Read more

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

Arne Hartherz
January 11, 2018Software engineer at makandra GmbH

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)
Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

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)
Posted by Arne Hartherz to makandra dev (2018-01-11 11:17)