Search⌘ K
AI Features

VCR and RSpec

Understand how to use VCR with RSpec to efficiently test external service integrations in Rails apps. This lesson covers VCR configuration options, managing cassettes, and handling HTTP request stubbing to ensure accurate and stable tests.

VCR and RSpec

We can use RSpec metadata to specify that any RSpec it or describe block uses a VCR cassette. The configuration goes into another RSpec support file:

Ruby
VCR.configure do |c|
c.cassette_library_dir = "spec/cassettes"
c.hook_into :webmock
c.configure_rspec_metadata!
c.ignore_localhost = true
end

VCR options

Here, four options are specified:

First option

First, the directory where VCR is going to place its cassette files (which can be anything we want, ...