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 UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
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)