I work with external APIs in my application and need a reliable way of testing how my code handles those API responses. The VCR gem provides a great way to that in a contextual fashion.

Add this file

support/vcr.rb

and a directory named

vcr

to your rspec directory and implement the following gist:

When you run your spec for the first time, VCR creates a new file under the vcr directory with the cassette name you specified. On the next call, this data will be used for mocking your API response.