VCR
v-6.0.0
v-6.0.0
  • Introduction
  • Upgrade
  • Changelog
  • About These Examples
  • License
  • Contributing
  • Cassettes
    • Cassette Format
    • Naming
    • Error for HTTP Request Made When No Cassette Is in Use
    • Dynamic ERB Cassettes
    • Automatic Re-Recording
    • Exclusive Cassette
    • Update Content Length Header
    • Decode Compressed Response
    • Allow Unused HTTP Interactions
    • Freezing Time
  • Record modes
    • Once
    • New Episodes
    • None
    • All
    • Record on Error
  • Configuration
    • Cassette Library Dir
    • Hook Into
    • Default Cassette Options
    • Ignore Request
    • Filter Sensitive Data
    • Allow HTTP Connections When No Cassette
    • Debug Logging
    • Preserve Exact Body Bytes
    • URI Parser
    • Query Parser
  • Hooks
    • Before Record Hook
    • Before Playback Hook
    • Before HTTP Request Hook
    • After HTTP Request Hook
    • Around HTTP Request Hook
  • Request matching
    • Introduction
    • Matching on Method
    • Matching on URI
    • Matching on Host
    • Matching on Path
    • Matching on Query String
    • Matching on Body
    • Matching on Headers
    • Identical Requests Are Replayed in Sequence
    • Register and Use a Custom Matcher
    • URI Without Param(s)
    • Playback Repeats
    • Matching on Body as JSON
  • Test frameworks
    • Usage With Test::Unit
    • Usage With RSpec Metadata
    • Usage With Cucumber
  • Middleware
    • Rack
    • Faraday Middleware
  • HTTP Libraries
    • Net::HTTP
    • EM HTTP Request
Powered by GitBook
On this page
  • Background ()
  • cassettes get default values from configured default_cassette_options
  • :match_requests_on defaults to [:method, :uri] when it has not been set
  • :record defaults to :once when it has not been set
  • :record_on_error defaults to true when it has not been set
  • cassettes can set their own options
  • cassettes can override default options

Was this helpful?

  1. Configuration

Default Cassette Options

The default_cassette_options configuration option takes a hash that provides defaults for each cassette you use. Any cassette can override the defaults as well as set additional options.

The :match_requests_on option defaults to [:method, :uri] when it has not been set.

The :record option defaults to :once when it has not been set.

Background ()

Given a file named "vcr_setup.rb" with:

require 'vcr'

VCR.configure do |c|
  c.default_cassette_options = { :record => :new_episodes, :erb => true }

  # not important for this example, but must be set to something
  c.hook_into :webmock
  c.cassette_library_dir = 'cassettes'
end

cassettes get default values from configured default_cassette_options

Given a file named "default_cassette_options.rb" with:

require 'vcr_setup.rb'

VCR.use_cassette('example') do
  puts "Record Mode: #{VCR.current_cassette.record_mode}"
  puts "ERB: #{VCR.current_cassette.erb}"
end

When I run ruby default_cassette_options.rb

Then the output should contain:

Record Mode: new_episodes
ERB: true

:match_requests_on defaults to [:method, :uri] when it has not been set

Given a file named "default_cassette_options.rb" with:

require 'vcr_setup.rb'

VCR.use_cassette('example') do
  puts "Match Requests On: #{VCR.current_cassette.match_requests_on.inspect}"
end

When I run ruby default_cassette_options.rb

Then the output should contain "Match Requests On: [:method, :uri]".

:record defaults to :once when it has not been set

Given a file named "default_record_mode.rb" with:

require 'vcr'

VCR.configure do |c|
  # not important for this example, but must be set to something
  c.hook_into :webmock
  c.cassette_library_dir = 'cassettes'
end

VCR.use_cassette('example') do
  puts "Record mode: #{VCR.current_cassette.record_mode.inspect}"
end

When I run ruby default_record_mode.rb

Then the output should contain "Record mode: :once".

:record_on_error defaults to true when it has not been set

Given a file named "default_record_on_error.rb" with:

require 'vcr'

VCR.configure do |c|
  # not important for this example, but must be set to something
  c.hook_into :webmock
  c.cassette_library_dir = 'cassettes'
end

VCR.use_cassette('example') do
  puts "Record on error: #{VCR.current_cassette.record_on_error}"
end

When I run ruby default_record_on_error.rb

Then the output should contain "Record on error: true".

cassettes can set their own options

Given a file named "default_cassette_options.rb" with:

require 'vcr_setup.rb'

VCR.use_cassette('example', :re_record_interval => 10000) do
  puts "Re-record Interval: #{VCR.current_cassette.re_record_interval}"
end

When I run ruby default_cassette_options.rb

Then the output should contain "Re-record Interval: 10000".

cassettes can override default options

Given a file named "default_cassette_options.rb" with:

require 'vcr_setup.rb'

VCR.use_cassette('example', :record => :none, :erb => false) do
  puts "Record Mode: #{VCR.current_cassette.record_mode}"
  puts "ERB: #{VCR.current_cassette.erb}"
end

When I run ruby default_cassette_options.rb

Then the output should contain:

Record Mode: none
ERB: false
PreviousHook IntoNextIgnore Request

Last updated 4 years ago

Was this helpful?