Search code examples
ruby-on-railsrspecvcr

How do I test this third party API integration in rspec?


My project is a rails app that extends some third party API. A lot of the requests rely on third party API calls. How should I test these cases in rspec? Should I use VCR and actually just hit the third party (then mock future requests)? Or should I just download the payload into a fixture manually and stub requests with webmock and find a way to bypass the oauth process? Are the better solutions?

Note that it uses OAuth, but I don't use omniauth.

Sometimes the API limits me to fetching N records at a time, so I have to paginate them. There could be instances where I'm making 25 requests just to get the data I need, but this is mostly for the sync rake tasks.


Solution

  • There is no need to download a payload manually, as this is exactly what VCR does for you. VCR creates a yaml fixture, that it uses for all future requests.