vcr 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +62 -0
- data/README.md +224 -0
- data/Rakefile +12 -5
- data/VERSION +1 -1
- data/benchmarks/http_stubbing_libraries.rb +59 -0
- data/features/fixtures/vcr_cassettes/1.8.6/cucumber_tags/replay_cassette1.yml +25 -25
- data/features/fixtures/vcr_cassettes/1.8.6/cucumber_tags/replay_cassette2.yml +32 -30
- data/features/fixtures/vcr_cassettes/1.8.6/cucumber_tags/replay_cassette3.yml +40 -40
- data/features/fixtures/vcr_cassettes/1.8.6/nested_replay_cassette.yml +16 -15
- data/features/fixtures/vcr_cassettes/1.8.6/not_the_real_response.yml +25 -25
- data/features/fixtures/vcr_cassettes/1.8.7/cucumber_tags/replay_cassette1.yml +23 -23
- data/features/fixtures/vcr_cassettes/1.8.7/cucumber_tags/replay_cassette2.yml +24 -22
- data/features/fixtures/vcr_cassettes/1.8.7/cucumber_tags/replay_cassette3.yml +36 -36
- data/features/fixtures/vcr_cassettes/1.8.7/nested_replay_cassette.yml +12 -11
- data/features/fixtures/vcr_cassettes/1.8.7/not_the_real_response.yml +23 -23
- data/features/fixtures/vcr_cassettes/1.9.1/cucumber_tags/replay_cassette1.yml +24 -24
- data/features/fixtures/vcr_cassettes/1.9.1/cucumber_tags/replay_cassette2.yml +26 -24
- data/features/fixtures/vcr_cassettes/1.9.1/cucumber_tags/replay_cassette3.yml +38 -38
- data/features/fixtures/vcr_cassettes/1.9.1/nested_replay_cassette.yml +13 -12
- data/features/fixtures/vcr_cassettes/1.9.1/not_the_real_response.yml +24 -24
- data/features/record_response.feature +2 -2
- data/features/replay_recorded_response.feature +1 -1
- data/features/step_definitions/vcr_steps.rb +8 -8
- data/features/support/env.rb +6 -0
- data/lib/vcr.rb +16 -3
- data/lib/vcr/cassette.rb +49 -46
- data/lib/vcr/config.rb +8 -0
- data/lib/vcr/extensions/fake_web.rb +12 -26
- data/lib/vcr/extensions/net_http.rb +9 -26
- data/lib/vcr/http_stubbing_adapters/base.rb +34 -0
- data/lib/vcr/http_stubbing_adapters/fakeweb.rb +75 -0
- data/lib/vcr/http_stubbing_adapters/webmock.rb +80 -0
- data/lib/vcr/structs.rb +44 -0
- data/lib/vcr/task_runner.rb +47 -0
- data/lib/vcr/tasks/vcr.rake +9 -0
- data/spec/cassette_spec.rb +70 -71
- data/spec/config_spec.rb +27 -0
- data/spec/extensions/net_http_spec.rb +21 -17
- data/spec/fixtures/1.8.6/0_3_1_cassette.yml +29 -0
- data/spec/fixtures/1.8.6/cassette_spec/example.yml +110 -108
- data/spec/fixtures/1.8.6/example_net_http.yml +14 -0
- data/spec/fixtures/1.8.6/example_net_http_request.yml +12 -0
- data/spec/fixtures/1.8.6/example_net_http_response.yml +25 -0
- data/spec/fixtures/1.8.6/fake_example.com_responses.yml +90 -0
- data/spec/fixtures/1.8.7/0_3_1_cassette.yml +29 -0
- data/spec/fixtures/1.8.7/cassette_spec/example.yml +110 -108
- data/spec/fixtures/1.8.7/example_net_http.yml +14 -0
- data/spec/fixtures/1.8.7/example_net_http_request.yml +12 -0
- data/spec/fixtures/1.8.7/example_net_http_response.yml +25 -0
- data/spec/fixtures/1.8.7/fake_example.com_responses.yml +90 -0
- data/spec/fixtures/1.9.1/0_3_1_cassette.yml +29 -0
- data/spec/fixtures/1.9.1/cassette_spec/example.yml +62 -59
- data/spec/fixtures/1.9.1/example_net_http.yml +14 -0
- data/spec/fixtures/1.9.1/example_net_http_request.yml +12 -0
- data/spec/fixtures/1.9.1/example_net_http_response.yml +25 -0
- data/spec/fixtures/1.9.1/fake_example.com_responses.yml +90 -0
- data/spec/http_stubbing_adapters/fakeweb_spec.rb +24 -0
- data/spec/http_stubbing_adapters/webmock_spec.rb +23 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/structs_spec.rb +95 -0
- data/spec/support/http_stubbing_adapter.rb +113 -0
- data/spec/task_runner_spec.rb +59 -0
- data/spec/vcr_spec.rb +37 -0
- data/vcr.gemspec +45 -15
- metadata +67 -26
- data/History.rdoc +0 -31
- data/README.rdoc +0 -222
- data/lib/vcr/recorded_response.rb +0 -4
- data/spec/extensions/fake_web_spec.rb +0 -63
- data/spec/recorded_response_spec.rb +0 -25
data/lib/vcr/structs.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module VCR
|
4
|
+
class Request < Struct.new(:method, :uri, :body, :headers)
|
5
|
+
def self.from_net_http_request(net_http, request)
|
6
|
+
new(
|
7
|
+
request.method.downcase.to_sym,
|
8
|
+
VCR.http_stubbing_adapter.request_uri(net_http, request),
|
9
|
+
request.body,
|
10
|
+
request.to_hash
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class ResponseStatus < Struct.new(:code, :message)
|
16
|
+
def self.from_net_http_response(response)
|
17
|
+
new(response.code.to_i, response.message)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Response < Struct.new(:status, :headers, :body, :http_version)
|
22
|
+
def self.from_net_http_response(response)
|
23
|
+
new(
|
24
|
+
ResponseStatus.from_net_http_response(response),
|
25
|
+
response.to_hash,
|
26
|
+
response.body,
|
27
|
+
response.http_version
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class HTTPInteraction < Struct.new(:request, :response)
|
33
|
+
extend ::Forwardable
|
34
|
+
|
35
|
+
def_delegators :request, :uri, :method
|
36
|
+
|
37
|
+
def self.from_net_http_objects(net_http, request, response)
|
38
|
+
new(
|
39
|
+
Request.from_net_http_request(net_http, request),
|
40
|
+
Response.from_net_http_response(response)
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'vcr'
|
2
|
+
|
3
|
+
module VCR
|
4
|
+
module TaskRunner
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def migrate_cassettes(dir)
|
8
|
+
with_recorded_response_defined do
|
9
|
+
FileUtils.cp_r(dir, "#{dir}-backup")
|
10
|
+
|
11
|
+
Dir.glob(dir + '/**/*.yml').each do |cassette_file|
|
12
|
+
recorded_responses = YAML.load(File.read(cassette_file))
|
13
|
+
next unless recorded_responses.is_a?(Enumerable) && recorded_responses.all? { |rr| rr.is_a?(VCR::RecordedResponse) }
|
14
|
+
|
15
|
+
interactions = recorded_responses.map do |recorded_response|
|
16
|
+
http_interaction(recorded_response)
|
17
|
+
end
|
18
|
+
|
19
|
+
File.open(cassette_file, 'w') { |f| f.write(interactions.to_yaml) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def http_interaction(recorded_response)
|
27
|
+
VCR::HTTPInteraction.new(
|
28
|
+
request(recorded_response),
|
29
|
+
VCR::Response.from_net_http_response(recorded_response.response)
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
def request(recorded_response)
|
34
|
+
VCR::Request.new(recorded_response.method, recorded_response.uri)
|
35
|
+
end
|
36
|
+
|
37
|
+
def with_recorded_response_defined
|
38
|
+
VCR.const_set(:RecordedResponse, Class.new(Struct.new(:method, :uri, :response, :request_body, :request_headers)))
|
39
|
+
|
40
|
+
begin
|
41
|
+
yield
|
42
|
+
ensure
|
43
|
+
VCR.send(:remove_const, :RecordedResponse)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'vcr/task_runner'
|
2
|
+
|
3
|
+
namespace :vcr do
|
4
|
+
desc 'Migrates your VCR cassettes in DIR from the 0.3.1 format to the 0.4+ format'
|
5
|
+
task :migrate_cassettes do
|
6
|
+
raise "You must pass the cassette library directory as DIR" if ENV['DIR'].to_s == ''
|
7
|
+
VCR::TaskRunner.migrate_cassettes(ENV['DIR'])
|
8
|
+
end
|
9
|
+
end
|
data/spec/cassette_spec.rb
CHANGED
@@ -26,21 +26,30 @@ describe VCR::Cassette do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
describe '#
|
30
|
-
it 'adds the
|
31
|
-
recorded_response = VCR::RecordedResponse.new(:get, 'http://example.com', :response)
|
29
|
+
describe '#record_http_interaction' do
|
30
|
+
it 'adds the interaction to #recorded_interactions' do
|
32
31
|
cassette = VCR::Cassette.new(:test_cassette)
|
33
|
-
cassette.
|
34
|
-
cassette.
|
35
|
-
cassette.
|
32
|
+
cassette.recorded_interactions.should == []
|
33
|
+
cassette.record_http_interaction(:the_interaction)
|
34
|
+
cassette.recorded_interactions.should == [:the_interaction]
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
39
38
|
describe 'on creation' do
|
39
|
+
it 'raises an error with a helpful message when loading an old unsupported cassette' do
|
40
|
+
VCR::Config.cassette_library_dir = File.expand_path(File.dirname(__FILE__) + "/fixtures/#{RUBY_VERSION}")
|
41
|
+
lambda { VCR::Cassette.new('0_3_1_cassette') }.should raise_error(/The VCR cassette 0_3_1_cassette uses an old format that is now deprecated/)
|
42
|
+
end
|
43
|
+
|
40
44
|
it "raises an error if given an invalid record mode" do
|
41
45
|
lambda { VCR::Cassette.new(:test, :record => :not_a_record_mode) }.should raise_error(ArgumentError)
|
42
46
|
end
|
43
47
|
|
48
|
+
it 'creates a stubs checkpoint on the http_stubbing_adapter' do
|
49
|
+
VCR.http_stubbing_adapter.should_receive(:create_stubs_checkpoint).with('example').once
|
50
|
+
VCR::Cassette.new('example')
|
51
|
+
end
|
52
|
+
|
44
53
|
VCR::Cassette::VALID_RECORD_MODES.each do |mode|
|
45
54
|
it "defaults the record mode to #{mode} when VCR::Config.default_cassette_options[:record] is #{mode}" do
|
46
55
|
VCR::Config.default_cassette_options = { :record => mode }
|
@@ -49,56 +58,49 @@ describe VCR::Cassette do
|
|
49
58
|
end
|
50
59
|
end
|
51
60
|
|
52
|
-
{ :new_episodes => true, :all => true, :none => false }.each do |record_mode,
|
53
|
-
it "sets
|
54
|
-
|
61
|
+
{ :new_episodes => true, :all => true, :none => false }.each do |record_mode, http_connections_allowed|
|
62
|
+
it "sets http_connections_allowed to #{http_connections_allowed} on the http stubbing adapter when the record mode is #{record_mode}" do
|
63
|
+
VCR.http_stubbing_adapter.should_receive(:http_connections_allowed=).with(http_connections_allowed)
|
55
64
|
VCR::Cassette.new(:name, :record => record_mode)
|
56
|
-
FakeWeb.allow_net_connect?.should == allow_fakeweb_connect
|
57
65
|
end
|
58
66
|
end
|
59
67
|
|
60
|
-
{ :new_episodes => true, :all => false, :none => true }.each do |record_mode,
|
61
|
-
it "#{
|
68
|
+
{ :new_episodes => true, :all => false, :none => true }.each do |record_mode, load_interactions|
|
69
|
+
it "#{load_interactions ? 'loads' : 'does not load'} the recorded interactions from the library yml file when the record mode is #{record_mode}" do
|
62
70
|
VCR::Config.cassette_library_dir = File.expand_path(File.dirname(__FILE__) + "/fixtures/#{RUBY_VERSION}/cassette_spec")
|
63
71
|
cassette = VCR::Cassette.new('example', :record => record_mode)
|
64
72
|
|
65
|
-
if
|
66
|
-
cassette.should have(3).
|
73
|
+
if load_interactions
|
74
|
+
cassette.should have(3).recorded_interactions
|
67
75
|
|
68
|
-
|
76
|
+
i1, i2, i3 = *cassette.recorded_interactions
|
69
77
|
|
70
|
-
|
71
|
-
|
72
|
-
|
78
|
+
i1.request.method.should == :get
|
79
|
+
i1.request.uri.should == 'http://example.com:80/'
|
80
|
+
i1.response.body.should =~ /You have reached this web page by typing.+example\.com/
|
73
81
|
|
74
|
-
|
75
|
-
|
76
|
-
|
82
|
+
i2.request.method.should == :get
|
83
|
+
i2.request.uri.should == 'http://example.com:80/foo'
|
84
|
+
i2.response.body.should =~ /foo was not found on this server/
|
77
85
|
|
78
|
-
|
79
|
-
|
80
|
-
|
86
|
+
i3.request.method.should == :get
|
87
|
+
i3.request.uri.should == 'http://example.com:80/'
|
88
|
+
i3.response.body.should =~ /Another example\.com response/
|
81
89
|
else
|
82
|
-
cassette.should have(0).
|
90
|
+
cassette.should have(0).recorded_interactions
|
83
91
|
end
|
84
92
|
end
|
85
93
|
|
86
|
-
it "#{
|
94
|
+
it "#{load_interactions ? 'stubs' : 'does not stub'} the recorded requests with the http stubbing adapter when the record mode is #{record_mode}" do
|
87
95
|
VCR::Config.cassette_library_dir = File.expand_path(File.dirname(__FILE__) + "/fixtures/#{RUBY_VERSION}/cassette_spec")
|
88
|
-
cassette = VCR::Cassette.new('example', :record => record_mode)
|
89
|
-
|
90
|
-
rr1 = FakeWeb.response_for(:get, "http://example.com")
|
91
|
-
rr2 = FakeWeb.response_for(:get, "http://example.com/foo")
|
92
|
-
rr3 = FakeWeb.response_for(:get, "http://example.com")
|
93
96
|
|
94
|
-
if
|
95
|
-
|
96
|
-
rr1.body.should =~ /You have reached this web page by typing.+example\.com/
|
97
|
-
rr2.body.should =~ /foo was not found on this server/
|
98
|
-
rr3.body.should =~ /Another example\.com response/
|
97
|
+
if load_interactions
|
98
|
+
VCR.http_stubbing_adapter.should_receive(:stub_requests).with([an_instance_of(VCR::HTTPInteraction)]*3)
|
99
99
|
else
|
100
|
-
|
100
|
+
VCR.http_stubbing_adapter.should_receive(:stub_requests).never
|
101
101
|
end
|
102
|
+
|
103
|
+
cassette = VCR::Cassette.new('example', :record => record_mode)
|
102
104
|
end
|
103
105
|
end
|
104
106
|
end
|
@@ -144,66 +146,63 @@ describe VCR::Cassette do
|
|
144
146
|
describe '#eject' do
|
145
147
|
temp_dir File.expand_path(File.dirname(__FILE__) + '/fixtures/cassette_spec_eject'), :assign_to_cassette_library_dir => true
|
146
148
|
|
147
|
-
[true, false].each do |
|
148
|
-
it "resets
|
149
|
-
|
149
|
+
[true, false].each do |orig_http_connections_allowed|
|
150
|
+
it "resets #{orig_http_connections_allowed} on the http stubbing adapter if it was originally #{orig_http_connections_allowed}" do
|
151
|
+
VCR.http_stubbing_adapter.should_receive(:http_connections_allowed?).and_return(orig_http_connections_allowed)
|
150
152
|
cassette = VCR::Cassette.new(:name)
|
153
|
+
VCR.http_stubbing_adapter.should_receive(:http_connections_allowed=).with(orig_http_connections_allowed)
|
151
154
|
cassette.eject
|
152
|
-
FakeWeb.allow_net_connect?.should == orig_allow_net_connect
|
153
155
|
end
|
154
156
|
end
|
155
157
|
|
156
|
-
it "writes the recorded
|
157
|
-
|
158
|
-
VCR::
|
159
|
-
VCR::
|
160
|
-
VCR::
|
158
|
+
it "writes the recorded interactions to disk as yaml" do
|
159
|
+
recorded_interactions = [
|
160
|
+
VCR::HTTPInteraction.new(:req_sig_1, :response_1),
|
161
|
+
VCR::HTTPInteraction.new(:req_sig_2, :response_2),
|
162
|
+
VCR::HTTPInteraction.new(:req_sig_3, :response_3)
|
161
163
|
]
|
162
164
|
|
163
165
|
cassette = VCR::Cassette.new(:eject_test)
|
164
|
-
cassette.stub!(:
|
166
|
+
cassette.stub!(:recorded_interactions).and_return(recorded_interactions)
|
165
167
|
|
166
168
|
lambda { cassette.eject }.should change { File.exist?(cassette.file) }.from(false).to(true)
|
167
|
-
|
168
|
-
|
169
|
+
saved_recorded_interactions = File.open(cassette.file, "r") { |f| YAML.load(f.read) }
|
170
|
+
saved_recorded_interactions.should == recorded_interactions
|
169
171
|
end
|
170
172
|
|
171
|
-
it "writes the recorded
|
172
|
-
|
173
|
+
it "writes the recorded interactions to a subdirectory if the cassette name includes a directory" do
|
174
|
+
recorded_interactions = [VCR::HTTPInteraction.new(:the_request, :the_response)]
|
173
175
|
cassette = VCR::Cassette.new('subdirectory/test_cassette')
|
174
|
-
cassette.stub!(:
|
176
|
+
cassette.stub!(:recorded_interactions).and_return(recorded_interactions)
|
175
177
|
|
176
178
|
lambda { cassette.eject }.should change { File.exist?(cassette.file) }.from(false).to(true)
|
177
|
-
|
178
|
-
|
179
|
+
saved_recorded_interactions = File.open(cassette.file, "r") { |f| YAML.load(f.read) }
|
180
|
+
saved_recorded_interactions.should == recorded_interactions
|
179
181
|
end
|
180
182
|
|
181
|
-
it "writes both old and new recorded
|
183
|
+
it "writes both old and new recorded interactions to disk" do
|
182
184
|
file = File.expand_path(File.dirname(__FILE__) + "/fixtures/#{RUBY_VERSION}/cassette_spec/example.yml")
|
183
|
-
FileUtils.cp file, File.join(@temp_dir, '
|
184
|
-
cassette = VCR::Cassette.new('
|
185
|
-
cassette.should have(3).
|
186
|
-
|
187
|
-
cassette.
|
185
|
+
FileUtils.cp file, File.join(@temp_dir, 'previously_recorded_interactions.yml')
|
186
|
+
cassette = VCR::Cassette.new('previously_recorded_interactions')
|
187
|
+
cassette.should have(3).recorded_interactions
|
188
|
+
new_recorded_interaction = VCR::HTTPInteraction.new(:the_request, :the_response)
|
189
|
+
cassette.record_http_interaction(new_recorded_interaction)
|
188
190
|
cassette.eject
|
189
|
-
|
190
|
-
|
191
|
-
|
191
|
+
saved_recorded_interactions = File.open(cassette.file, "r") { |f| YAML.load(f.read) }
|
192
|
+
saved_recorded_interactions.should have(4).recorded_interactions
|
193
|
+
saved_recorded_interactions.last.should == new_recorded_interaction
|
192
194
|
end
|
193
195
|
end
|
194
196
|
|
195
|
-
describe '#eject for a cassette with previously recorded
|
196
|
-
it "
|
197
|
+
describe '#eject for a cassette with previously recorded interactions' do
|
198
|
+
it "restore the stubs checkpoint on the http stubbing adapter" do
|
197
199
|
VCR::Config.cassette_library_dir = File.expand_path(File.dirname(__FILE__) + "/fixtures/#{RUBY_VERSION}/cassette_spec")
|
198
200
|
cassette = VCR::Cassette.new('example', :record => :none)
|
199
|
-
|
200
|
-
FakeWeb.registered_uri?(:get, 'http://example.com/foo').should be_true
|
201
|
+
VCR.http_stubbing_adapter.should_receive(:restore_stubs_checkpoint).with('example')
|
201
202
|
cassette.eject
|
202
|
-
FakeWeb.registered_uri?(:get, 'http://example.com').should be_false
|
203
|
-
FakeWeb.registered_uri?(:get, 'http://example.com/foo').should be_false
|
204
203
|
end
|
205
204
|
|
206
|
-
it "does not re-write to disk the previously recorded
|
205
|
+
it "does not re-write to disk the previously recorded interactions if there are no new ones" do
|
207
206
|
VCR::Config.cassette_library_dir = File.expand_path(File.dirname(__FILE__) + "/fixtures/#{RUBY_VERSION}/cassette_spec")
|
208
207
|
yaml_file = File.join(VCR::Config.cassette_library_dir, 'example.yml')
|
209
208
|
cassette = VCR::Cassette.new('example', :record => :none)
|
@@ -211,4 +210,4 @@ describe VCR::Cassette do
|
|
211
210
|
lambda { cassette.eject }.should_not change { File.mtime(yaml_file) }
|
212
211
|
end
|
213
212
|
end
|
214
|
-
end
|
213
|
+
end
|
data/spec/config_spec.rb
CHANGED
@@ -19,4 +19,31 @@ describe VCR::Config do
|
|
19
19
|
VCR::Config.default_cassette_options.should == {}
|
20
20
|
end
|
21
21
|
end
|
22
|
+
|
23
|
+
describe '#http_stubbing_library' do
|
24
|
+
it 'returns the configured value' do
|
25
|
+
[:fakeweb, :webmock].each do |setting|
|
26
|
+
VCR::Config.http_stubbing_library = setting
|
27
|
+
VCR::Config.http_stubbing_library.should == setting
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when set to nil' do
|
32
|
+
before(:each) { VCR::Config.http_stubbing_library = nil }
|
33
|
+
|
34
|
+
{
|
35
|
+
[:FakeWeb, :WebMock] => nil,
|
36
|
+
[] => nil,
|
37
|
+
[:FakeWeb] => :fakeweb,
|
38
|
+
[:WebMock] => :webmock
|
39
|
+
}.each do |defined_constants, expected_return_value|
|
40
|
+
it "returns #{expected_return_value.inspect} when these constants are defined: #{defined_constants.inspect}" do
|
41
|
+
[:FakeWeb, :WebMock].each do |const|
|
42
|
+
Object.should_receive(:const_defined?).with(const).and_return(defined_constants.include?(const))
|
43
|
+
end
|
44
|
+
VCR::Config.http_stubbing_library.should == expected_return_value
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
22
49
|
end
|
@@ -16,35 +16,39 @@ describe "Net::HTTP Extensions" do
|
|
16
16
|
@current_cassette.should_receive(:allow_real_http_requests_to?).at_least(:once).with(@uri).and_return(false)
|
17
17
|
end
|
18
18
|
|
19
|
-
describe 'a request that is not registered with
|
19
|
+
describe 'a request that is not registered with the http stubbing adapter' do
|
20
|
+
before(:each) do
|
21
|
+
VCR.http_stubbing_adapter.should_receive(:request_stubbed?).with(anything, 'http://example.com:80/').and_return(false)
|
22
|
+
end
|
23
|
+
|
20
24
|
def perform_get_with_returning_block
|
21
25
|
Net::HTTP.new('example.com', 80).request(Net::HTTP::Get.new('/', {})) do |response|
|
22
26
|
return response
|
23
27
|
end
|
24
28
|
end
|
25
29
|
|
26
|
-
it 'calls #
|
27
|
-
|
28
|
-
VCR::
|
29
|
-
@current_cassette.should_receive(:
|
30
|
+
it 'calls #record_http_interaction on the current cassette' do
|
31
|
+
interaction = VCR::HTTPInteraction.new
|
32
|
+
VCR::HTTPInteraction.should_receive(:from_net_http_objects).and_return(interaction)
|
33
|
+
@current_cassette.should_receive(:record_http_interaction).with(interaction)
|
30
34
|
Net::HTTP.get(@uri)
|
31
35
|
end
|
32
36
|
|
33
|
-
it 'calls #
|
34
|
-
@current_cassette.should_receive(:
|
37
|
+
it 'calls #record_http_interaction only once, even when Net::HTTP internally recursively calls #request' do
|
38
|
+
@current_cassette.should_receive(:record_http_interaction).once
|
35
39
|
Net::HTTP.new('example.com', 80).post('/', nil)
|
36
40
|
end
|
37
41
|
|
38
|
-
it 'calls #
|
39
|
-
@current_cassette.should_receive(:
|
42
|
+
it 'calls #record_http_interaction when Net::HTTP#request is called with a block with a return statement' do
|
43
|
+
@current_cassette.should_receive(:record_http_interaction).once
|
40
44
|
perform_get_with_returning_block
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
44
|
-
describe 'a request that is registered with
|
45
|
-
it 'does not call #
|
46
|
-
|
47
|
-
@current_cassette.should_not_receive(:
|
48
|
+
describe 'a request that is registered with the http stubbing adapter' do
|
49
|
+
it 'does not call #record_http_interaction on the current cassette' do
|
50
|
+
VCR.http_stubbing_adapter.should_receive(:request_stubbed?).with(:get, 'http://example.com:80/').and_return(true)
|
51
|
+
@current_cassette.should_not_receive(:record_http_interaction)
|
48
52
|
Net::HTTP.get(@uri)
|
49
53
|
end
|
50
54
|
end
|
@@ -55,13 +59,13 @@ describe "Net::HTTP Extensions" do
|
|
55
59
|
@current_cassette.should_receive(:allow_real_http_requests_to?).with(@uri).and_return(true)
|
56
60
|
end
|
57
61
|
|
58
|
-
it 'does not call #
|
59
|
-
@current_cassette.should_receive(:
|
62
|
+
it 'does not call #record_http_interaction on the current cassette' do
|
63
|
+
@current_cassette.should_receive(:record_http_interaction).never
|
60
64
|
Net::HTTP.get(@uri)
|
61
65
|
end
|
62
66
|
|
63
|
-
it 'uses
|
64
|
-
|
67
|
+
it 'uses VCR.http_stubbing_adapter.with_http_connections_allowed_set_to(true) to make the request' do
|
68
|
+
VCR.http_stubbing_adapter.should_receive(:with_http_connections_allowed_set_to).with(true).and_yield
|
65
69
|
Net::HTTP.get(@uri)
|
66
70
|
end
|
67
71
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::RecordedResponse
|
3
|
+
method: :post
|
4
|
+
uri: http://example.com:80/
|
5
|
+
response: !ruby/object:Net::HTTPOK
|
6
|
+
body: The response from example.com
|
7
|
+
body_exist: true
|
8
|
+
code: "200"
|
9
|
+
header:
|
10
|
+
etag:
|
11
|
+
- "\"24ec5-1b6-4059a80bfd280\""
|
12
|
+
last-modified:
|
13
|
+
- Tue, 15 Nov 2005 13:24:10 GMT
|
14
|
+
content-type:
|
15
|
+
- text/html; charset=UTF-8
|
16
|
+
connection:
|
17
|
+
- close
|
18
|
+
server:
|
19
|
+
- Apache/2.2.3 (CentOS)
|
20
|
+
date:
|
21
|
+
- Wed, 31 Mar 2010 02:43:26 GMT
|
22
|
+
content-length:
|
23
|
+
- "438"
|
24
|
+
accept-ranges:
|
25
|
+
- bytes
|
26
|
+
http_version: "1.1"
|
27
|
+
message: OK
|
28
|
+
read: true
|
29
|
+
socket:
|