This is an excellent post that explains a little bit behind the difficulty in testing external services https://robots.thoughtbot.com/how-to-stub-external-services-in-tests How to Stub External Services in Tests
One simple option is to use Webmock
Here is an example of using Webmock in a similar way to what VCR does - which is recording and reading from a file
stub_request(:any, "www.example.com").
to_return(:body => File.new('/tmp/response_body.txt'), :status => 200)
So what you can do is throw a byebug
in dev where you're making an api call and then write what you get from that api call to a file, using something like this:
File.open('/tmp/response_body.txt', 'w') { |f| f.puts 'abc' }
Only in this case you'd probably use a .json file
You can then mess up your api key and get an example of what a 500 status looks like and then input crap data and get what an example of a not-found or 404 status looks like Then you'll be prepared for the 'unhappy' path
This is an example of a VCR cassette
As you can see, it stores a lot of additional data But the way most people use them is just to provide the 'body' or a response and a status code Here is where the body is in a VCR
If that's all you need for testing, then I'd avoid VCR, personally.
I'd advocate for the 'file' approach to stubbing the API for some things - because you can very easily swap out files But with webmock you can also just pass a hash in your testing code Reading from files will add some time to how long your tests take to run - so limit the # of times you read a file by having it happen only once for a set of tests, if possible
@rrgayhart This is a nice explanation of the differences between webmock and VCR, Thanks for sharing it :)