Read more

VCR fails if the same request is triggered multiple times

Emanuel
September 23, 2016Software engineer at makandra GmbH

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:

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

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 Show archive.org snapshot . 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

Posted by Emanuel to makandra dev (2016-09-23 09:23)