VCR fails if the same request is triggered multiple times

Updated . Posted . Visible to the public.

Same requests are recorded only once in vcr Show archive.org snapshot . Replaying a test fails, if you trigger the same request multiple times. The error message is somehow confusing, as your cassette contains the request:

An HTTP request has been made that VCR does not know how to handle

If you want to allow to match a request multiple times, you need to configure this explicit with allow_playback_repeats: true. Some example configurations:

# specific cassette only
VCR.use_cassette('example', :allow_playback_repeats => true) do
  puts response_body_for(:get, 'http://example.com/foo')
  puts response_body_for(:get, 'http://example.com/foo')
  puts response_body_for(:get, 'http://example.com/foo')
end
# cucumber only
VCR.cucumber_tags do |t|
  t.tag '@vcr',
    use_scenario_name: true,
    allow_playback_repeats: true
end
# globally
VCR.configure do |config|
  config.default_casette_options = { allow_playback_repeats: true } 
end

Use this option with caution, as there are many scenarios where the response changes for the same request!

Further reading

If this doesn't help, you might find these topics useful:

Matchers

VCR has different matchers Show archive.org snapshot (:method (default enabled), :uri (default enabled), :body, :headers, :host, :path, :query). If e.g. your params have a different order, this might fail in the comparison of equality:

Tests with AJAX

Using javascript in integration tests might cause issues that AJAX requests are not recorded or bleed in other scenarios:

Debugging

Last edit
Michael Leimstädtner
License
Source code in this card is licensed under the MIT License.
Posted by Emanuel to makandra dev (2016-09-23 07:23)