< mockra >

VCR - 16 Oct 2012

VCR is a great tool for testing HTTP requests. VCR records responses that you can test against in the future. This speeds up tests and allows you to run them without an internet connection.

I like to create a separate file for setting up VCR configurations, so I can load it on demand without having to include spec_helper. Here’s what an example vcr_setup file would look like:

require 'vcr'

VCR.configure do |c|
  c.cassette_library_dir = 'spec/vcr_cassettes'
  c.hook_into :fakeweb

RSpec.configure do |c|
  c.extend VCR::RSpec::Macros

Whenever you’re interacting with an external service, it’s a good idea to wrap the library, API, or tool that you’re using. If something changes within the tool you’re using, you should only need to adapt your wrapper, not your entire application.

VCR on Github