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 ()
  • Allow HTTP connections when no cassette
  • Cassettes record and replay as normal

Was this helpful?

  1. Configuration

Allow HTTP Connections When No Cassette

PreviousFilter Sensitive DataNextDebug Logging

Last updated 5 years ago

Was this helpful?

Usually, HTTP requests made when no cassette is inserted will . You can set the allow_http_connections_when_no_cassette configuration option to true to allow requests, if you do not want to use VCR for everything.

Background ()

Given a file named "vcr_setup.rb" with:

if ARGV.include?('--with-server')
  $server = start_sinatra_app do
    get('/') { "Hello" }
  end
end

require 'vcr'

VCR.configure do |c|
  c.allow_http_connections_when_no_cassette = true
  c.hook_into :webmock
  c.cassette_library_dir = 'cassettes'
  c.default_cassette_options = {
    :match_requests_on => [:method, :host, :path]
  }
end

And the directory "vcr/cassettes" does not exist.

Allow HTTP connections when no cassette

Given a file named "no_cassette.rb" with:

require 'vcr_setup.rb'

puts "Response: " + Net::HTTP.get_response('localhost', '/', $server ? $server.port : 0).body

When I run ruby no_cassette.rb --with-server

Then the output should contain "Response: Hello".

Cassettes record and replay as normal

Given a file named "record_replay_cassette.rb" with:

require 'vcr_setup.rb'

VCR.use_cassette('localhost') do
  puts "Response: " + Net::HTTP.get_response('localhost', '/', $server ? $server.port : 0).body
end

When I run ruby record_replay_cassette.rb --with-server

Then the output should contain "Response: Hello"

And the file "cassettes/localhost.yml" should contain "Hello"

When I run ruby record_replay_cassette.rb

Then the output should contain "Response: Hello".

result in an error