vcr 2.5.0 → 2.6.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.
- checksums.yaml +8 -8
- data/.travis.yml +0 -3
- data/CHANGELOG.md +32 -3
- data/Gemfile +33 -0
- data/Gemfile.lock +99 -119
- data/README.md +19 -7
- data/Rakefile +5 -9
- data/benchmarks/null_logging.rb +62 -0
- data/features/.nav +0 -1
- data/features/about_these_examples.md +1 -2
- data/features/cassettes/allow_unused_http_interactions.feature +15 -1
- data/features/cassettes/decompress.feature +6 -2
- data/features/cassettes/format.feature +20 -12
- data/features/cassettes/freezing_time.feature +68 -0
- data/features/configuration/cassette_library_dir.feature +5 -0
- data/features/configuration/preserve_exact_body_bytes.feature +5 -0
- data/features/configuration/uri_parser.feature +2 -4
- data/features/http_libraries/net_http.feature +1 -1
- data/features/request_matching/headers.feature +0 -1
- data/features/step_definitions/cli_steps.rb +1 -4
- data/features/test_frameworks/cucumber.feature +59 -0
- data/features/test_frameworks/rspec_metadata.feature +59 -1
- data/gemfiles/typhoeus_old.gemfile +19 -0
- data/gemfiles/typhoeus_old.gemfile.lock +84 -86
- data/lib/vcr.rb +12 -3
- data/lib/vcr/cassette.rb +32 -11
- data/lib/vcr/cassette/http_interaction_list.rb +3 -2
- data/lib/vcr/cassette/migrator.rb +1 -0
- data/lib/vcr/cassette/serializers/json.rb +1 -1
- data/lib/vcr/configuration.rb +17 -9
- data/lib/vcr/library_hooks/typhoeus.rb +3 -2
- data/lib/vcr/library_hooks/webmock.rb +1 -1
- data/lib/vcr/middleware/excon.rb +13 -1
- data/lib/vcr/middleware/faraday.rb +1 -0
- data/lib/vcr/request_handler.rb +1 -1
- data/lib/vcr/structs.rb +19 -4
- data/lib/vcr/test_frameworks/cucumber.rb +2 -2
- data/lib/vcr/test_frameworks/rspec.rb +10 -2
- data/lib/vcr/util/logger.rb +41 -7
- data/lib/vcr/version.rb +1 -1
- data/script/ci.sh +8 -1
- data/spec/acceptance/threading_spec.rb +6 -0
- data/spec/capture_warnings.rb +9 -1
- data/spec/spec_helper.rb +6 -2
- data/spec/support/configuration_stubbing.rb +8 -0
- data/spec/support/http_library_adapters.rb +1 -1
- data/spec/support/limited_uri.rb +1 -0
- data/spec/support/shared_example_groups/excon.rb +23 -1
- data/spec/support/shared_example_groups/hook_into_http_library.rb +12 -12
- data/spec/support/shared_example_groups/request_hooks.rb +1 -1
- data/spec/support/sinatra_app.rb +9 -0
- data/spec/support/vcr_localhost_server.rb +4 -25
- data/spec/support/vcr_stub_helpers.rb +1 -1
- data/spec/vcr/cassette/http_interaction_list_spec.rb +41 -14
- data/spec/vcr/cassette/migrator_spec.rb +1 -1
- data/spec/vcr/cassette/persisters_spec.rb +2 -2
- data/spec/vcr/cassette/serializers_spec.rb +13 -4
- data/spec/vcr/cassette_spec.rb +107 -58
- data/spec/vcr/configuration_spec.rb +23 -23
- data/spec/vcr/deprecations_spec.rb +9 -9
- data/spec/vcr/errors_spec.rb +6 -6
- data/spec/vcr/library_hooks/excon_spec.rb +15 -10
- data/spec/vcr/library_hooks/fakeweb_spec.rb +8 -8
- data/spec/vcr/library_hooks/faraday_spec.rb +1 -1
- data/spec/vcr/library_hooks/typhoeus_0.4_spec.rb +2 -2
- data/spec/vcr/library_hooks/typhoeus_spec.rb +68 -9
- data/spec/vcr/library_hooks/webmock_spec.rb +6 -10
- data/spec/vcr/middleware/faraday_spec.rb +33 -5
- data/spec/vcr/middleware/rack_spec.rb +2 -2
- data/spec/vcr/request_matcher_registry_spec.rb +11 -6
- data/spec/vcr/structs_spec.rb +114 -47
- data/spec/vcr/test_frameworks/cucumber_spec.rb +4 -4
- data/spec/vcr/util/hooks_spec.rb +2 -2
- data/spec/vcr/util/internet_connection_spec.rb +3 -3
- data/spec/vcr/util/version_checker_spec.rb +4 -4
- data/spec/vcr_spec.rb +22 -16
- data/vcr.gemspec +2 -31
- metadata +9 -328
- data/features/test_frameworks/shoulda.feature +0 -64
@@ -68,8 +68,8 @@ describe VCR::Configuration do
|
|
68
68
|
|
69
69
|
describe '#hook_into' do
|
70
70
|
it 'requires the named library hook' do
|
71
|
-
subject.
|
72
|
-
subject.
|
71
|
+
expect(subject).to receive(:require).with("vcr/library_hooks/fakeweb")
|
72
|
+
expect(subject).to receive(:require).with("vcr/library_hooks/excon")
|
73
73
|
subject.hook_into :fakeweb, :excon
|
74
74
|
end
|
75
75
|
|
@@ -89,14 +89,14 @@ describe VCR::Configuration do
|
|
89
89
|
|
90
90
|
describe '#ignore_hosts' do
|
91
91
|
it 'delegates to the current request_ignorer instance' do
|
92
|
-
VCR.request_ignorer.
|
92
|
+
expect(VCR.request_ignorer).to receive(:ignore_hosts).with('example.com', 'example.net')
|
93
93
|
subject.ignore_hosts 'example.com', 'example.net'
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
97
|
describe '#ignore_localhost=' do
|
98
98
|
it 'delegates to the current request_ignorer instance' do
|
99
|
-
VCR.request_ignorer.
|
99
|
+
expect(VCR.request_ignorer).to receive(:ignore_localhost=).with(true)
|
100
100
|
subject.ignore_localhost = true
|
101
101
|
end
|
102
102
|
end
|
@@ -107,7 +107,7 @@ describe VCR::Configuration do
|
|
107
107
|
it 'registers the given block with the request ignorer' do
|
108
108
|
block_called = false
|
109
109
|
subject.ignore_request { |r| block_called = true }
|
110
|
-
VCR.request_ignorer.ignore?(
|
110
|
+
VCR.request_ignorer.ignore?(double(:parsed_uri => uri))
|
111
111
|
expect(block_called).to be_true
|
112
112
|
end
|
113
113
|
end
|
@@ -155,9 +155,9 @@ describe VCR::Configuration do
|
|
155
155
|
it 'sets up a tag filter' do
|
156
156
|
called = false
|
157
157
|
VCR.configuration.send(hook_type, :my_tag) { called = true }
|
158
|
-
VCR.configuration.invoke_hook(hook_type,
|
158
|
+
VCR.configuration.invoke_hook(hook_type, double, double(:tags => []))
|
159
159
|
expect(called).to be_false
|
160
|
-
VCR.configuration.invoke_hook(hook_type,
|
160
|
+
VCR.configuration.invoke_hook(hook_type, double, double(:tags => [:my_tag]))
|
161
161
|
expect(called).to be_true
|
162
162
|
end
|
163
163
|
end
|
@@ -165,42 +165,42 @@ describe VCR::Configuration do
|
|
165
165
|
|
166
166
|
%w[ filter_sensitive_data define_cassette_placeholder ].each do |method|
|
167
167
|
describe "##{method}" do
|
168
|
-
let(:interaction) {
|
169
|
-
before(:each) { interaction.
|
168
|
+
let(:interaction) { double('interaction').as_null_object }
|
169
|
+
before(:each) { allow(interaction).to receive(:filter!) }
|
170
170
|
|
171
171
|
it 'adds a before_record hook that replaces the string returned by the block with the given string' do
|
172
172
|
subject.send(method, 'foo', &lambda { 'bar' })
|
173
|
-
interaction.
|
174
|
-
subject.invoke_hook(:before_record, interaction,
|
173
|
+
expect(interaction).to receive(:filter!).with('bar', 'foo')
|
174
|
+
subject.invoke_hook(:before_record, interaction, double.as_null_object)
|
175
175
|
end
|
176
176
|
|
177
177
|
it 'adds a before_playback hook that replaces the given string with the string returned by the block' do
|
178
178
|
subject.send(method, 'foo', &lambda { 'bar' })
|
179
|
-
interaction.
|
180
|
-
subject.invoke_hook(:before_playback, interaction,
|
179
|
+
expect(interaction).to receive(:filter!).with('foo', 'bar')
|
180
|
+
subject.invoke_hook(:before_playback, interaction, double.as_null_object)
|
181
181
|
end
|
182
182
|
|
183
183
|
it 'tags the before_record hook when given a tag' do
|
184
|
-
subject.
|
184
|
+
expect(subject).to receive(:before_record).with(:my_tag)
|
185
185
|
subject.send(method, 'foo', :my_tag) { 'bar' }
|
186
186
|
end
|
187
187
|
|
188
188
|
it 'tags the before_playback hook when given a tag' do
|
189
|
-
subject.
|
189
|
+
expect(subject).to receive(:before_playback).with(:my_tag)
|
190
190
|
subject.send(method, 'foo', :my_tag) { 'bar' }
|
191
191
|
end
|
192
192
|
|
193
193
|
it 'yields the interaction to the block for the before_record hook' do
|
194
194
|
yielded_interaction = nil
|
195
195
|
subject.send(method, 'foo', &lambda { |i| yielded_interaction = i; 'bar' })
|
196
|
-
subject.invoke_hook(:before_record, interaction,
|
196
|
+
subject.invoke_hook(:before_record, interaction, double.as_null_object)
|
197
197
|
expect(yielded_interaction).to equal(interaction)
|
198
198
|
end
|
199
199
|
|
200
200
|
it 'yields the interaction to the block for the before_playback hook' do
|
201
201
|
yielded_interaction = nil
|
202
202
|
subject.send(method, 'foo', &lambda { |i| yielded_interaction = i; 'bar' })
|
203
|
-
subject.invoke_hook(:before_playback, interaction,
|
203
|
+
subject.invoke_hook(:before_playback, interaction, double.as_null_object)
|
204
204
|
expect(yielded_interaction).to equal(interaction)
|
205
205
|
end
|
206
206
|
end
|
@@ -235,7 +235,7 @@ describe VCR::Configuration do
|
|
235
235
|
end if RUBY_VERSION < '1.9'
|
236
236
|
|
237
237
|
describe "#cassette_serializers" do
|
238
|
-
let(:custom_serializer) {
|
238
|
+
let(:custom_serializer) { double }
|
239
239
|
it 'allows a custom serializer to be registered' do
|
240
240
|
expect { subject.cassette_serializers[:custom] }.to raise_error(ArgumentError)
|
241
241
|
subject.cassette_serializers[:custom] = custom_serializer
|
@@ -244,7 +244,7 @@ describe VCR::Configuration do
|
|
244
244
|
end
|
245
245
|
|
246
246
|
describe "#cassette_persisters" do
|
247
|
-
let(:custom_persister) {
|
247
|
+
let(:custom_persister) { double }
|
248
248
|
it 'allows a custom persister to be registered' do
|
249
249
|
expect { subject.cassette_persisters[:custom] }.to raise_error(ArgumentError)
|
250
250
|
subject.cassette_persisters[:custom] = custom_persister
|
@@ -253,7 +253,7 @@ describe VCR::Configuration do
|
|
253
253
|
end
|
254
254
|
|
255
255
|
describe "#uri_parser=" do
|
256
|
-
let(:custom_parser) {
|
256
|
+
let(:custom_parser) { double }
|
257
257
|
it 'allows a custom uri parser to be set' do
|
258
258
|
subject.uri_parser = custom_parser
|
259
259
|
expect(subject.uri_parser).to eq(custom_parser)
|
@@ -266,7 +266,7 @@ describe VCR::Configuration do
|
|
266
266
|
|
267
267
|
describe "#preserve_exact_body_bytes_for?" do
|
268
268
|
def message_for(body)
|
269
|
-
|
269
|
+
double(:body => body)
|
270
270
|
end
|
271
271
|
|
272
272
|
context "default hook" do
|
@@ -302,7 +302,7 @@ describe VCR::Configuration do
|
|
302
302
|
it "invokes the configured hook with the http message and the current cassette" do
|
303
303
|
VCR.use_cassette('example') do |cassette|
|
304
304
|
expect(cassette).to be_a(VCR::Cassette)
|
305
|
-
message =
|
305
|
+
message = double(:message)
|
306
306
|
|
307
307
|
yielded_objects = nil
|
308
308
|
subject.preserve_exact_body_bytes { |a, b| yielded_objects = [a, b] }
|
@@ -314,7 +314,7 @@ describe VCR::Configuration do
|
|
314
314
|
|
315
315
|
describe "#configure_rspec_metadata!" do
|
316
316
|
it "only configures the underlying metadata once, no matter how many times it is called" do
|
317
|
-
VCR::RSpec::Metadata.
|
317
|
+
expect(VCR::RSpec::Metadata).to receive(:configure!).once
|
318
318
|
VCR.configure do |c|
|
319
319
|
c.configure_rspec_metadata!
|
320
320
|
end
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe VCR, 'deprecations', :disable_warnings do
|
4
4
|
describe ".config" do
|
5
5
|
it 'delegates to VCR.configure' do
|
6
|
-
VCR.
|
6
|
+
expect(VCR).to receive(:configure)
|
7
7
|
VCR.config { }
|
8
8
|
end
|
9
9
|
|
@@ -14,7 +14,7 @@ describe VCR, 'deprecations', :disable_warnings do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'prints a deprecation warning' do
|
17
|
-
VCR.
|
17
|
+
expect(VCR).to receive(:warn).with(/VCR.config.*deprecated/i)
|
18
18
|
|
19
19
|
VCR.config { }
|
20
20
|
end
|
@@ -26,7 +26,7 @@ describe VCR, 'deprecations', :disable_warnings do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'prints a deprecation warning' do
|
29
|
-
VCR.
|
29
|
+
expect(VCR).to receive(:warn).with(/VCR::Config.*deprecated/i)
|
30
30
|
|
31
31
|
VCR::Config
|
32
32
|
end
|
@@ -44,7 +44,7 @@ describe VCR, 'deprecations', :disable_warnings do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'prints a deprecation warning' do
|
47
|
-
VCR::Cassette.
|
47
|
+
expect(VCR::Cassette).to receive(:warn).with(/VCR::Cassette::MissingERBVariableError.*deprecated/i)
|
48
48
|
|
49
49
|
VCR::Cassette::MissingERBVariableError
|
50
50
|
end
|
@@ -58,26 +58,26 @@ describe VCR, 'deprecations', :disable_warnings do
|
|
58
58
|
|
59
59
|
describe "VCR.configure { |c| c.stub_with ... }" do
|
60
60
|
it 'delegates to #hook_into' do
|
61
|
-
VCR.configuration.
|
61
|
+
expect(VCR.configuration).to receive(:hook_into).with(:fakeweb, :excon)
|
62
62
|
VCR.configure { |c| c.stub_with :fakeweb, :excon }
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'prints a deprecation warning' do
|
66
|
-
VCR.configuration.
|
66
|
+
expect(VCR.configuration).to receive(:warn).with(/stub_with.*deprecated/i)
|
67
67
|
VCR.configure { |c| c.stub_with :fakeweb, :excon }
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
71
|
describe "VCR::Middleware::Faraday" do
|
72
72
|
it 'prints a deprecation warning when passed a block' do
|
73
|
-
Kernel.
|
74
|
-
VCR::Middleware::Faraday.new(
|
73
|
+
expect(Kernel).to receive(:warn).with(/Passing a block .* is deprecated/)
|
74
|
+
VCR::Middleware::Faraday.new(double) { }
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
78
|
describe "VCR::RSpec::Macros" do
|
79
79
|
it 'prints a deprecation warning' do
|
80
|
-
Kernel.
|
80
|
+
expect(Kernel).to receive(:warn).with(/VCR::RSpec::Macros is deprecated/)
|
81
81
|
Class.new.extend(VCR::RSpec::Macros)
|
82
82
|
end
|
83
83
|
end
|
data/spec/vcr/errors_spec.rb
CHANGED
@@ -82,7 +82,7 @@ module VCR
|
|
82
82
|
it 'mentions :allow_playback_repeats if the current cassette has a used matching interaction' do
|
83
83
|
VCR.use_cassette('example') do |cassette|
|
84
84
|
expect(cassette.http_interactions).to respond_to(:has_used_interaction_matching?)
|
85
|
-
cassette.http_interactions.
|
85
|
+
allow(cassette.http_interactions).to receive(:has_used_interaction_matching?).and_return(true)
|
86
86
|
expect(message).to include('allow_playback_repeats')
|
87
87
|
end
|
88
88
|
end
|
@@ -90,7 +90,7 @@ module VCR
|
|
90
90
|
it 'does not mention :allow_playback_repeats if the current cassette does not have a used matching interaction' do
|
91
91
|
VCR.use_cassette('example') do |cassette|
|
92
92
|
expect(cassette.http_interactions).to respond_to(:has_used_interaction_matching?)
|
93
|
-
cassette.http_interactions.
|
93
|
+
allow(cassette.http_interactions).to receive(:has_used_interaction_matching?).and_return(false)
|
94
94
|
expect(message).not_to include('allow_playback_repeats')
|
95
95
|
end
|
96
96
|
end
|
@@ -98,7 +98,7 @@ module VCR
|
|
98
98
|
it 'does not mention using a different :match_requests_on option when there are no remaining unused interactions' do
|
99
99
|
VCR.use_cassette('example') do |cassette|
|
100
100
|
expect(cassette.http_interactions).to respond_to(:remaining_unused_interaction_count)
|
101
|
-
cassette.http_interactions.
|
101
|
+
allow(cassette.http_interactions).to receive(:remaining_unused_interaction_count).and_return(0)
|
102
102
|
expect(message).not_to include('match_requests_on cassette option')
|
103
103
|
end
|
104
104
|
end
|
@@ -106,7 +106,7 @@ module VCR
|
|
106
106
|
it 'mentions using a different :match_requests_on option when there are some remaining unused interactions' do
|
107
107
|
VCR.use_cassette('example') do |cassette|
|
108
108
|
expect(cassette.http_interactions).to respond_to(:remaining_unused_interaction_count)
|
109
|
-
cassette.http_interactions.
|
109
|
+
allow(cassette.http_interactions).to receive(:remaining_unused_interaction_count).and_return(1)
|
110
110
|
expect(message).to include('match_requests_on cassette option')
|
111
111
|
end
|
112
112
|
end
|
@@ -114,7 +114,7 @@ module VCR
|
|
114
114
|
it 'uses the singular (HTTP interaction) when there is only 1 left' do
|
115
115
|
VCR.use_cassette('example') do |cassette|
|
116
116
|
expect(cassette.http_interactions).to respond_to(:remaining_unused_interaction_count)
|
117
|
-
cassette.http_interactions.
|
117
|
+
allow(cassette.http_interactions).to receive(:remaining_unused_interaction_count).and_return(1)
|
118
118
|
expect(message).to include('1 HTTP interaction ')
|
119
119
|
end
|
120
120
|
end
|
@@ -122,7 +122,7 @@ module VCR
|
|
122
122
|
it 'uses the plural (HTTP interactions) when there is more than 1 left' do
|
123
123
|
VCR.use_cassette('example') do |cassette|
|
124
124
|
expect(cassette.http_interactions).to respond_to(:remaining_unused_interaction_count)
|
125
|
-
cassette.http_interactions.
|
125
|
+
allow(cassette.http_interactions).to receive(:remaining_unused_interaction_count).and_return(2)
|
126
126
|
expect(message).to include('2 HTTP interactions ')
|
127
127
|
end
|
128
128
|
end
|
@@ -2,11 +2,15 @@ require 'spec_helper'
|
|
2
2
|
require 'support/shared_example_groups/excon'
|
3
3
|
|
4
4
|
describe "Excon hook", :with_monkey_patches => :excon do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
after(:each) do
|
6
|
+
::Excon.stubs.clear
|
7
|
+
::Excon.defaults[:mock] = false
|
8
|
+
end
|
9
|
+
|
10
|
+
def directly_stub_request(method, url, response_body)
|
11
|
+
::Excon.defaults[:mock] = true
|
12
|
+
::Excon.stub({ :method => method, :url => url }, { :body => response_body })
|
13
|
+
end
|
10
14
|
|
11
15
|
it_behaves_like 'a hook into an HTTP library', :excon, 'excon', :status_message_not_exposed
|
12
16
|
|
@@ -14,7 +18,7 @@ describe "Excon hook", :with_monkey_patches => :excon do
|
|
14
18
|
let(:excon) { ::Excon.new("http://localhost:#{VCR::SinatraApp.port}/search") }
|
15
19
|
|
16
20
|
it 'properly records and plays back the response' do
|
17
|
-
VCR.
|
21
|
+
allow(VCR).to receive(:real_http_connections_allowed?).and_return(true)
|
18
22
|
recorded, played_back = [1, 2].map do
|
19
23
|
VCR.use_cassette('excon_query', :record => :once) do
|
20
24
|
excon.request(:method => :get, :query => { :q => 'Tolkien' }).body
|
@@ -30,16 +34,17 @@ describe "Excon hook", :with_monkey_patches => :excon do
|
|
30
34
|
|
31
35
|
context 'when Excon raises an error due to an unexpected response status' do
|
32
36
|
before(:each) do
|
33
|
-
VCR.
|
37
|
+
allow(VCR).to receive(:real_http_connections_allowed?).and_return(true)
|
34
38
|
end
|
35
39
|
|
36
40
|
it 'still records properly' do
|
37
|
-
VCR.
|
41
|
+
expect(VCR).to receive(:record_http_interaction) do |interaction|
|
38
42
|
expect(interaction.response.status.code).to eq(404)
|
43
|
+
expect(interaction.response.body).to eq('404 not 200')
|
39
44
|
end
|
40
45
|
|
41
46
|
expect {
|
42
|
-
Excon.get("http://localhost:#{VCR::SinatraApp.port}/
|
47
|
+
Excon.get("http://localhost:#{VCR::SinatraApp.port}/404_not_200", :expects => 200)
|
43
48
|
}.to raise_error(Excon::Errors::Error)
|
44
49
|
end
|
45
50
|
|
@@ -76,7 +81,7 @@ describe "Excon hook", :with_monkey_patches => :excon do
|
|
76
81
|
describe "VCR.configuration.after_library_hooks_loaded hook" do
|
77
82
|
it 'disables the webmock excon adapter so it does not conflict with our typhoeus hook' do
|
78
83
|
expect(::WebMock::HttpLibAdapters::ExconAdapter).to respond_to(:disable!)
|
79
|
-
::WebMock::HttpLibAdapters::ExconAdapter.
|
84
|
+
expect(::WebMock::HttpLibAdapters::ExconAdapter).to receive(:disable!)
|
80
85
|
$excon_after_loaded_hook.conditionally_invoke
|
81
86
|
end
|
82
87
|
end
|
@@ -22,11 +22,11 @@ describe "FakeWeb hook", :with_monkey_patches => :fakeweb do
|
|
22
22
|
|
23
23
|
describe "some specific Net::HTTP edge cases" do
|
24
24
|
before(:each) do
|
25
|
-
VCR.
|
25
|
+
allow(VCR).to receive(:real_http_connections_allowed?).and_return(true)
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'records the request body when using #post_form' do
|
29
|
-
VCR.
|
29
|
+
expect(VCR).to receive(:record_http_interaction) do |interaction|
|
30
30
|
expect(interaction.request.body).to eq("q=ruby")
|
31
31
|
end
|
32
32
|
|
@@ -35,7 +35,7 @@ describe "FakeWeb hook", :with_monkey_patches => :fakeweb do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it "does not record headers for which Net::HTTP sets defaults near the end of the real request" do
|
38
|
-
VCR.
|
38
|
+
expect(VCR).to receive(:record_http_interaction) do |interaction|
|
39
39
|
expect(interaction.request.headers).not_to have_key('content-type')
|
40
40
|
expect(interaction.request.headers).not_to have_key('host')
|
41
41
|
end
|
@@ -43,7 +43,7 @@ describe "FakeWeb hook", :with_monkey_patches => :fakeweb do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
it "records headers for which Net::HTTP usually sets defaults when the user manually sets their values" do
|
46
|
-
VCR.
|
46
|
+
expect(VCR).to receive(:record_http_interaction) do |interaction|
|
47
47
|
expect(interaction.request.headers['content-type']).to eq(['foo/bar'])
|
48
48
|
expect(interaction.request.headers['host']).to eq(['my-example.com'])
|
49
49
|
end
|
@@ -57,7 +57,7 @@ describe "FakeWeb hook", :with_monkey_patches => :fakeweb do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'records the interaction when Net::HTTP#request is called with a block with a return statement' do
|
60
|
-
VCR.
|
60
|
+
expect(VCR).to receive(:record_http_interaction).once
|
61
61
|
expect(perform_get_with_returning_block.body).to eq("GET to root")
|
62
62
|
end
|
63
63
|
|
@@ -66,7 +66,7 @@ describe "FakeWeb hook", :with_monkey_patches => :fakeweb do
|
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'records the interaction only once, even when Net::HTTP internally recursively calls #request' do
|
69
|
-
VCR.
|
69
|
+
expect(VCR).to receive(:record_http_interaction).once
|
70
70
|
make_post_request
|
71
71
|
end
|
72
72
|
|
@@ -129,7 +129,7 @@ describe "FakeWeb hook", :with_monkey_patches => :fakeweb do
|
|
129
129
|
end
|
130
130
|
|
131
131
|
it "warns about FakeWeb deprecation" do
|
132
|
-
::Kernel.
|
132
|
+
expect(::Kernel).to receive(:warn).with("WARNING: VCR's FakeWeb integration is deprecated and will be removed in VCR 3.0.")
|
133
133
|
run_hook
|
134
134
|
end
|
135
135
|
end
|
@@ -148,7 +148,7 @@ describe "FakeWeb hook", :with_monkey_patches => :fakeweb do
|
|
148
148
|
|
149
149
|
undef make_request
|
150
150
|
def make_request(disabled = false)
|
151
|
-
::Net::HTTP.
|
151
|
+
allow_any_instance_of(::Net::HTTP).to receive(:request_without_vcr).and_raise(SocketError)
|
152
152
|
expect {
|
153
153
|
::Net::HTTP.get_response(URI(request_url))
|
154
154
|
}.to raise_error(SocketError)
|
@@ -23,12 +23,12 @@ describe "Typhoeus 0.4 hook", :with_monkey_patches => :typhoeus_0_4 do
|
|
23
23
|
|
24
24
|
describe "VCR.configuration.after_library_hooks_loaded hook" do
|
25
25
|
it 'disables the webmock typhoeus adapter so it does not conflict with our typhoeus hook' do
|
26
|
-
::WebMock::HttpLibAdapters::TyphoeusAdapter.
|
26
|
+
expect(::WebMock::HttpLibAdapters::TyphoeusAdapter).to receive(:disable!)
|
27
27
|
$typhoeus_after_loaded_hook.conditionally_invoke
|
28
28
|
end
|
29
29
|
|
30
30
|
it "warns about Typhoeus 0.4 deprecation" do
|
31
|
-
::Kernel.
|
31
|
+
expect(::Kernel).to receive(:warn).with("WARNING: VCR's Typhoeus 0.4 integration is deprecated and will be removed in VCR 3.0.")
|
32
32
|
$typhoeus_0_4_after_loaded_hook.conditionally_invoke
|
33
33
|
end
|
34
34
|
end
|
@@ -23,7 +23,7 @@ describe "Typhoeus hook", :with_monkey_patches => :typhoeus do
|
|
23
23
|
|
24
24
|
describe "VCR.configuration.after_library_hooks_loaded hook" do
|
25
25
|
it 'disables the webmock typhoeus adapter so it does not conflict with our typhoeus hook' do
|
26
|
-
::WebMock::HttpLibAdapters::TyphoeusAdapter.
|
26
|
+
expect(::WebMock::HttpLibAdapters::TyphoeusAdapter).to receive(:disable!)
|
27
27
|
$typhoeus_after_loaded_hook.conditionally_invoke
|
28
28
|
end
|
29
29
|
end
|
@@ -65,22 +65,81 @@ describe "Typhoeus hook", :with_monkey_patches => :typhoeus do
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
+
context "when used with a typhoeus-based faraday connection" do
|
69
|
+
let(:base_url) { "http://localhost:#{VCR::SinatraApp.port}" }
|
70
|
+
|
71
|
+
let(:conn) do
|
72
|
+
Faraday.new(:url => base_url) do |faraday|
|
73
|
+
faraday.adapter :typhoeus
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_response
|
78
|
+
# Ensure faraday hook doesn't handle the request.
|
79
|
+
VCR.library_hooks.exclusively_enabled(:typhoeus) do
|
80
|
+
VCR.use_cassette("faraday") do
|
81
|
+
conn.get("/")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'records and replays headers correctly' do
|
87
|
+
pending "waiting on typhoeus/typhoeus#324" do
|
88
|
+
recorded = get_response
|
89
|
+
played_back = get_response
|
90
|
+
|
91
|
+
expect(played_back.headers).to eq(recorded.headers)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
68
96
|
context '#effective_url' do
|
69
|
-
|
70
|
-
VCR.use_cassette('single') do
|
71
|
-
response = Typhoeus::Request.new("http://localhost:#{VCR::SinatraApp.port}/").run
|
97
|
+
ResponseValues = Struct.new(:status, :body, :effective_url)
|
72
98
|
|
73
|
-
|
99
|
+
def url_for(path)
|
100
|
+
"http://localhost:#{VCR::SinatraApp.port}#{path}"
|
101
|
+
end
|
102
|
+
|
103
|
+
def make_single_request(path, options = {})
|
104
|
+
VCR.use_cassette('single') do |cassette|
|
105
|
+
response = Typhoeus::Request.new(url_for(path), options).run
|
106
|
+
|
107
|
+
yield cassette if block_given?
|
108
|
+
|
109
|
+
ResponseValues.new(
|
110
|
+
response.code,
|
111
|
+
response.body,
|
112
|
+
response.effective_url
|
113
|
+
)
|
74
114
|
end
|
75
115
|
end
|
76
116
|
|
77
|
-
it '
|
78
|
-
recorded = make_single_request
|
79
|
-
played_back = make_single_request
|
80
|
-
expect(recorded).not_to be_nil
|
117
|
+
it 'records and plays back properly' do
|
118
|
+
recorded = make_single_request('/')
|
119
|
+
played_back = make_single_request('/')
|
81
120
|
|
121
|
+
expect(recorded.effective_url).to eq(url_for('/'))
|
82
122
|
expect(played_back).to eq(recorded)
|
83
123
|
end
|
124
|
+
|
125
|
+
it 'falls back to the request url when it was not recorded (e.g. on VCR <= 2.5.0)' do
|
126
|
+
make_single_request('/') do |cassette|
|
127
|
+
cassette.new_recorded_interactions.each { |i| i.response.adapter_metadata.clear }
|
128
|
+
end
|
129
|
+
|
130
|
+
played_back = make_single_request('/')
|
131
|
+
expect(played_back.effective_url).to eq(url_for('/'))
|
132
|
+
end
|
133
|
+
|
134
|
+
context "when following redirects" do
|
135
|
+
it 'records and plays back properly' do
|
136
|
+
recorded = make_single_request('/redirect-to-root', :followlocation => true)
|
137
|
+
played_back = make_single_request('/redirect-to-root', :followlocation => true)
|
138
|
+
|
139
|
+
expect(recorded.effective_url).to eq(url_for('/'))
|
140
|
+
expect(played_back).to eq(recorded)
|
141
|
+
end
|
142
|
+
end
|
84
143
|
end
|
85
144
|
end
|
86
145
|
|