Smoke Tests and VCR Options

Smoke tests

So far, we’ve used VCR to record an interaction once and preserve it for all time. VCR provides other options. These options are passed as key-value arguments to VCR.use_cassette(re_record_interval: 7.days) or, if we’re using RSpec metadata, as the value part of the metadata, as in vcr: {re_record_interval: 7.days}.

The re_record_interval method

That re_record_interval we just used as an example allows us to use the same VCR test as both an integration and a smoke test. The re_record_interval is an amount of time. If the associated cassette requests are older than the interval, then VCR will attempt to reconnect to the HTTP server and re-record the cassette. If the server is unavailable, VCR will use the existing cassette.

This allows us to protect our application against API changes in the server. If the server API changes, our VCR cassette will eventually pick up the change, and our test will fail. This can be a useful feature. It can also be a little on the opaque side when a test randomly fails, but it’s better to have an opaque failure in testing than to have one in production.

VCR recording options

VCR lets us set different record modes with the :record option. The default, which we’ve been using so far, is :once, which records new interactions if they don’t exist but raises an error for new interactions if the cassette already exists.

This table lists all the VCR recording options:

Get hands-on with 1400+ tech skills courses.