forked from vcr/vcr
/
allow_http_connections_when_no_cassette.feature
52 lines (42 loc) · 1.7 KB
/
allow_http_connections_when_no_cassette.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Feature: Allow HTTP connections when no cassette
Usually, HTTP requests made when no cassette is inserted will [result in an
error](../cassettes/error-for-http-request-made-when-no-cassette-is-in-use).
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:
"""ruby
if ARGV.include?('--with-server')
start_sinatra_app(:port => 7777) do
get('/') { "Hello" }
end
end
require 'vcr'
VCR.configure do |c|
c.allow_http_connections_when_no_cassette = true
c.hook_into :fakeweb
c.cassette_library_dir = 'cassettes'
end
"""
And the directory "vcr/cassettes" does not exist
Scenario: Allow HTTP connections when no cassette
Given a file named "no_cassette.rb" with:
"""ruby
require 'vcr_setup.rb'
puts "Response: " + Net::HTTP.get_response('localhost', '/', 7777).body
"""
When I run `ruby no_cassette.rb --with-server`
Then the output should contain "Response: Hello"
Scenario: Cassettes record and replay as normal
Given a file named "record_replay_cassette.rb" with:
"""ruby
require 'vcr_setup.rb'
VCR.use_cassette('localhost') do
puts "Response: " + Net::HTTP.get_response('localhost', '/', 7777).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"