Posted over 1 year ago. Visible to the public.

Cucumber: How to avoid VCR errors for unused requests in pending tests

When you have a pending Cucumber step (or feature) that also uses an existing VCR cassette, your pending test may fail at the very end with an error like this:

There are unused HTTP interactions left in the cassette: - [get ...] => [200 ...] - [get ...] => [200 ...] (VCR::Errors::UnusedHTTPInteractionError)

The error happens because your VCR is configured to complain about cassettes that contain extra requests which your test did not use. This is often a good configuration.
If you do not want to change your whole test suite's settings because of a pending test, you can disable this behavior for pending features only.

To make any pending call reconfigure the current cassette, you can simply redefine it. There is no official API to change the option at runtime, so we need to modify the instance variable.

module PendingWithoutVcrErrors def pending(*) VCR.current_cassette.instance_variable_set(:@allow_unused_http_interactions, true) if VCR.current_cassette super end end World(PendingWithoutVcrErrors)

makandra has been working exclusively with Ruby on Rails since 2007. Our laser focus on a single technology has made us a leader in this space.

Owner of this card:

Arne Hartherz
Last edit:
over 1 year ago
by Arne Hartherz
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Arne Hartherz to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more