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

Posted . Visible to the public.

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)
Arne Hartherz
Last edit
Arne Hartherz
License
Source code in this card is licensed under the MIT License.
Posted by Arne Hartherz to makandra dev (2018-01-11 10:17)