vcr 2.4.0 → 2.5.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 +15 -0
- data/.gitignore +3 -0
- data/.travis.yml +2 -0
- data/CHANGELOG.md +31 -0
- data/Gemfile +1 -2
- data/Gemfile.lock +63 -46
- data/README.md +5 -2
- data/features/cassettes/allow_unused_http_interactions.feature +1 -1
- data/features/cassettes/automatic_re_recording.feature +1 -1
- data/features/cassettes/decompress.feature +3 -3
- data/features/cassettes/dynamic_erb.feature +2 -2
- data/features/cassettes/exclusive.feature +1 -1
- data/features/cassettes/naming.feature +1 -1
- data/features/cassettes/no_cassette.feature +6 -3
- data/features/cassettes/persistence.feature +1 -1
- data/features/cassettes/update_content_length_header.feature +1 -1
- data/features/configuration/allow_http_connections_when_no_cassette.feature +1 -1
- data/features/configuration/cassette_library_dir.feature +1 -1
- data/features/configuration/debug_logging.feature +5 -5
- data/features/configuration/filter_sensitive_data.feature +2 -2
- data/features/configuration/hook_into.feature +4 -7
- data/features/getting_started.md +2 -2
- data/features/hooks/before_playback.feature +5 -5
- data/features/hooks/before_record.feature +5 -5
- data/features/middleware/rack.feature +2 -2
- data/features/record_modes/all.feature +1 -1
- data/features/record_modes/new_episodes.feature +1 -1
- data/features/record_modes/none.feature +1 -1
- data/features/record_modes/once.feature +1 -1
- data/features/request_matching/custom_matcher.feature +1 -1
- data/features/request_matching/headers.feature +0 -2
- data/features/request_matching/playback_repeats.feature +1 -1
- data/features/request_matching/uri_without_param.feature +1 -1
- data/features/support/env.rb +1 -0
- data/features/test_frameworks/cucumber.feature +8 -8
- data/features/test_frameworks/rspec_macro.feature +2 -2
- data/features/test_frameworks/rspec_metadata.feature +1 -1
- data/gemfiles/typhoeus_old.gemfile +1 -1
- data/gemfiles/typhoeus_old.gemfile.lock +31 -57
- data/lib/vcr/cassette/migrator.rb +8 -1
- data/lib/vcr/configuration.rb +9 -2
- data/lib/vcr/library_hooks/excon.rb +2 -184
- data/lib/vcr/library_hooks/typhoeus.rb +1 -1
- data/lib/vcr/library_hooks/typhoeus_0.4.rb +4 -0
- data/lib/vcr/library_hooks/webmock.rb +1 -1
- data/lib/vcr/middleware/excon.rb +226 -0
- data/lib/vcr/version.rb +1 -1
- data/spec/acceptance/threading_spec.rb +28 -0
- data/spec/monkey_patches.rb +3 -7
- data/spec/quality_spec.rb +1 -1
- data/spec/spec_helper.rb +7 -4
- data/spec/support/http_library_adapters.rb +4 -3
- data/spec/support/shared_example_groups/excon.rb +22 -0
- data/spec/support/shared_example_groups/hook_into_http_library.rb +46 -46
- data/spec/support/shared_example_groups/request_hooks.rb +8 -8
- data/spec/vcr/cassette/erb_renderer_spec.rb +5 -5
- data/spec/vcr/cassette/http_interaction_list_spec.rb +52 -40
- data/spec/vcr/cassette/migrator_spec.rb +11 -11
- data/spec/vcr/cassette/persisters/file_system_spec.rb +11 -11
- data/spec/vcr/cassette/persisters_spec.rb +2 -2
- data/spec/vcr/cassette/serializers_spec.rb +13 -12
- data/spec/vcr/cassette_spec.rb +58 -58
- data/spec/vcr/configuration_spec.rb +43 -31
- data/spec/vcr/deprecations_spec.rb +3 -3
- data/spec/vcr/errors_spec.rb +25 -25
- data/spec/vcr/extensions/net_http_response_spec.rb +7 -7
- data/spec/vcr/library_hooks/excon_spec.rb +7 -85
- data/spec/vcr/library_hooks/fakeweb_spec.rb +15 -13
- data/spec/vcr/library_hooks/faraday_spec.rb +4 -4
- data/spec/vcr/library_hooks/typhoeus_0.4_spec.rb +5 -0
- data/spec/vcr/library_hooks/typhoeus_spec.rb +3 -3
- data/spec/vcr/library_hooks/webmock_spec.rb +13 -5
- data/spec/vcr/library_hooks_spec.rb +9 -9
- data/spec/vcr/middleware/faraday_spec.rb +10 -10
- data/spec/vcr/middleware/rack_spec.rb +20 -15
- data/spec/vcr/request_ignorer_spec.rb +3 -3
- data/spec/vcr/request_matcher_registry_spec.rb +88 -61
- data/spec/vcr/structs_spec.rb +85 -85
- data/spec/vcr/test_frameworks/cucumber_spec.rb +7 -7
- data/spec/vcr/test_frameworks/rspec_spec.rb +10 -10
- data/spec/vcr/util/hooks_spec.rb +20 -20
- data/spec/vcr/util/internet_connection_spec.rb +2 -2
- data/spec/vcr_spec.rb +50 -48
- data/vcr.gemspec +4 -4
- metadata +308 -372
data/spec/vcr/cassette_spec.rb
CHANGED
@@ -11,9 +11,9 @@ describe VCR::Cassette do
|
|
11
11
|
describe '#file' do
|
12
12
|
it 'delegates the file resolution to the FileSystem persister' do
|
13
13
|
fs = VCR::Cassette::Persisters::FileSystem
|
14
|
-
fs.
|
14
|
+
expect(fs).to respond_to(:absolute_path_to_file).with(1).argument
|
15
15
|
fs.should_receive(:absolute_path_to_file).with("cassette name.yml") { "f.yml" }
|
16
|
-
VCR::Cassette.new("cassette name").file.
|
16
|
+
expect(VCR::Cassette.new("cassette name").file).to eq("f.yml")
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'raises a NotImplementedError when a different persister is used' do
|
@@ -25,15 +25,15 @@ describe VCR::Cassette do
|
|
25
25
|
|
26
26
|
describe '#tags' do
|
27
27
|
it 'returns a blank array if no tag has been set' do
|
28
|
-
VCR::Cassette.new("name").tags.
|
28
|
+
expect(VCR::Cassette.new("name").tags).to eq([])
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'converts a single :tag to an array' do
|
32
|
-
VCR::Cassette.new("name", :tag => :foo).tags.
|
32
|
+
expect(VCR::Cassette.new("name", :tag => :foo).tags).to eq([:foo])
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'accepts an array as the :tags option' do
|
36
|
-
VCR::Cassette.new("name", :tags => [:foo]).tags.
|
36
|
+
expect(VCR::Cassette.new("name", :tags => [:foo]).tags).to eq([:foo])
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -42,9 +42,9 @@ describe VCR::Cassette do
|
|
42
42
|
|
43
43
|
it 'adds the interaction to #new_recorded_interactions' do
|
44
44
|
cassette = VCR::Cassette.new(:test_cassette)
|
45
|
-
cassette.new_recorded_interactions.
|
45
|
+
expect(cassette.new_recorded_interactions).to eq([])
|
46
46
|
cassette.record_http_interaction(the_interaction)
|
47
|
-
cassette.new_recorded_interactions.
|
47
|
+
expect(cassette.new_recorded_interactions).to eq([the_interaction])
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -65,11 +65,11 @@ describe VCR::Cassette do
|
|
65
65
|
it 'includes the hash form of all recorded interactions' do
|
66
66
|
interaction_1.stub(:to_hash => { "i" => 1, 'body' => '' })
|
67
67
|
interaction_2.stub(:to_hash => { "i" => 2, 'body' => '' })
|
68
|
-
subject.serializable_hash.
|
68
|
+
expect(subject.serializable_hash).to include('http_interactions' => [{ "i" => 1, 'body' => '' }, { "i" => 2, 'body' => '' }])
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'includes additional metadata about the cassette' do
|
72
|
-
metadata.
|
72
|
+
expect(metadata).to eq("recorded_with" => "VCR #{VCR.version}")
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -77,13 +77,13 @@ describe VCR::Cassette do
|
|
77
77
|
[:all, :new_episodes].each do |mode|
|
78
78
|
it "returns true when the record mode is :#{mode}" do
|
79
79
|
cassette = VCR::Cassette.new("foo", :record => mode)
|
80
|
-
cassette.
|
80
|
+
expect(cassette).to be_recording
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
84
|
it "returns false when the record mode is :none" do
|
85
85
|
cassette = VCR::Cassette.new("foo", :record => :none)
|
86
|
-
cassette.
|
86
|
+
expect(cassette).not_to be_recording
|
87
87
|
end
|
88
88
|
|
89
89
|
context 'when the record mode is :once' do
|
@@ -93,22 +93,22 @@ describe VCR::Cassette do
|
|
93
93
|
|
94
94
|
it 'returns false when there is an existing cassette file with content' do
|
95
95
|
cassette = VCR::Cassette.new("example", :record => :once)
|
96
|
-
File.
|
97
|
-
File.size?(cassette.file).
|
98
|
-
cassette.
|
96
|
+
expect(File).to exist(cassette.file)
|
97
|
+
expect(File.size?(cassette.file)).to be_true
|
98
|
+
expect(cassette).not_to be_recording
|
99
99
|
end
|
100
100
|
|
101
101
|
it 'returns true when there is an empty existing cassette file' do
|
102
102
|
cassette = VCR::Cassette.new("empty", :record => :once)
|
103
|
-
File.
|
104
|
-
File.size?(cassette.file).
|
105
|
-
cassette.
|
103
|
+
expect(File).to exist(cassette.file)
|
104
|
+
expect(File.size?(cassette.file)).to be_false
|
105
|
+
expect(cassette).to be_recording
|
106
106
|
end
|
107
107
|
|
108
108
|
it 'returns true when there is no existing cassette file' do
|
109
109
|
cassette = VCR::Cassette.new("non_existant_file", :record => :once)
|
110
|
-
File.
|
111
|
-
cassette.
|
110
|
+
expect(File).not_to exist(cassette.file)
|
111
|
+
expect(cassette).to be_recording
|
112
112
|
end
|
113
113
|
end
|
114
114
|
end
|
@@ -118,12 +118,12 @@ describe VCR::Cassette do
|
|
118
118
|
|
119
119
|
it "returns the provided options" do
|
120
120
|
c = VCR::Cassette.new('example', :match_requests_on => [:uri])
|
121
|
-
c.match_requests_on.
|
121
|
+
expect(c.match_requests_on).to eq([:uri])
|
122
122
|
end
|
123
123
|
|
124
124
|
it "returns a the default #match_requests_on when it has not been specified for the cassette" do
|
125
125
|
c = VCR::Cassette.new('example')
|
126
|
-
c.match_requests_on.
|
126
|
+
expect(c.match_requests_on).to eq([:uri, :method])
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
@@ -184,7 +184,7 @@ describe VCR::Cassette do
|
|
184
184
|
|
185
185
|
it 'does not raise an error in the case of an empty file' do
|
186
186
|
VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
|
187
|
-
VCR::Cassette.new('empty', :record => :none).send(:previously_recorded_interactions).
|
187
|
+
expect(VCR::Cassette.new('empty', :record => :none).send(:previously_recorded_interactions)).to eq([])
|
188
188
|
end
|
189
189
|
|
190
190
|
let(:custom_persister) { stub("custom persister") }
|
@@ -204,7 +204,7 @@ describe VCR::Cassette do
|
|
204
204
|
|
205
205
|
it "defaults the record mode to #{record_mode} when VCR.configuration.default_cassette_options[:record] is #{record_mode}" do
|
206
206
|
cassette = VCR::Cassette.new(:test)
|
207
|
-
cassette.record_mode.
|
207
|
+
expect(cassette.record_mode).to eq(record_mode)
|
208
208
|
end
|
209
209
|
end
|
210
210
|
|
@@ -249,7 +249,7 @@ describe VCR::Cassette do
|
|
249
249
|
before(:each) { File.stub(:exist?).with(file_name).and_return(false) }
|
250
250
|
|
251
251
|
it "has :#{record_mode} for the record mode" do
|
252
|
-
subject.record_mode.
|
252
|
+
expect(subject.record_mode).to eq(record_mode)
|
253
253
|
end
|
254
254
|
end
|
255
255
|
|
@@ -273,7 +273,7 @@ describe VCR::Cassette do
|
|
273
273
|
] end
|
274
274
|
|
275
275
|
it "has :#{record_mode} for the record mode" do
|
276
|
-
subject.record_mode.
|
276
|
+
expect(subject.record_mode).to eq(record_mode)
|
277
277
|
end
|
278
278
|
end
|
279
279
|
|
@@ -286,12 +286,12 @@ describe VCR::Cassette do
|
|
286
286
|
|
287
287
|
it "has :all for the record mode when there is an internet connection available" do
|
288
288
|
VCR::InternetConnection.stub(:available? => true)
|
289
|
-
subject.record_mode.
|
289
|
+
expect(subject.record_mode).to eq(:all)
|
290
290
|
end
|
291
291
|
|
292
292
|
it "has :#{record_mode} for the record mode when there is no internet connection available" do
|
293
293
|
VCR::InternetConnection.stub(:available? => false)
|
294
|
-
subject.record_mode.
|
294
|
+
expect(subject.record_mode).to eq(record_mode)
|
295
295
|
end
|
296
296
|
end
|
297
297
|
end
|
@@ -305,35 +305,35 @@ describe VCR::Cassette do
|
|
305
305
|
|
306
306
|
VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
|
307
307
|
cassette = VCR::Cassette.new('with_localhost_requests', :record => record_mode)
|
308
|
-
cassette.send(:previously_recorded_interactions).map { |i| URI.parse(i.request.uri).host }.
|
308
|
+
expect(cassette.send(:previously_recorded_interactions).map { |i| URI.parse(i.request.uri).host }).to eq(%w[example.com])
|
309
309
|
end
|
310
310
|
|
311
311
|
it "loads the recorded interactions from the library yml file" do
|
312
312
|
VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
|
313
313
|
cassette = VCR::Cassette.new('example', :record => record_mode)
|
314
314
|
|
315
|
-
cassette.
|
315
|
+
expect(cassette).to have(3).previously_recorded_interactions
|
316
316
|
|
317
317
|
i1, i2, i3 = *cassette.send(:previously_recorded_interactions)
|
318
318
|
|
319
|
-
i1.request.method.
|
320
|
-
i1.request.uri.
|
321
|
-
i1.response.body.
|
319
|
+
expect(i1.request.method).to eq(:get)
|
320
|
+
expect(i1.request.uri).to eq('http://example.com/')
|
321
|
+
expect(i1.response.body).to match(/You have reached this web page by typing.+example\.com/)
|
322
322
|
|
323
|
-
i2.request.method.
|
324
|
-
i2.request.uri.
|
325
|
-
i2.response.body.
|
323
|
+
expect(i2.request.method).to eq(:get)
|
324
|
+
expect(i2.request.uri).to eq('http://example.com/foo')
|
325
|
+
expect(i2.response.body).to match(/foo was not found on this server/)
|
326
326
|
|
327
|
-
i3.request.method.
|
328
|
-
i3.request.uri.
|
329
|
-
i3.response.body.
|
327
|
+
expect(i3.request.method).to eq(:get)
|
328
|
+
expect(i3.request.uri).to eq('http://example.com/')
|
329
|
+
expect(i3.response.body).to match(/Another example\.com response/)
|
330
330
|
end
|
331
331
|
|
332
332
|
[true, false].each do |value|
|
333
333
|
it "instantiates the http_interactions with allow_playback_repeats = #{value} if given :allow_playback_repeats => #{value}" do
|
334
334
|
VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
|
335
335
|
cassette = VCR::Cassette.new('example', :record => record_mode, :allow_playback_repeats => value)
|
336
|
-
cassette.http_interactions.allow_playback_repeats.
|
336
|
+
expect(cassette.http_interactions.allow_playback_repeats).to eq(value)
|
337
337
|
end
|
338
338
|
end
|
339
339
|
|
@@ -341,14 +341,14 @@ describe VCR::Cassette do
|
|
341
341
|
VCR.stub(:http_interactions => stub)
|
342
342
|
VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
|
343
343
|
cassette = VCR::Cassette.new('example', :record => record_mode, :exclusive => true)
|
344
|
-
cassette.http_interactions.parent_list.
|
344
|
+
expect(cassette.http_interactions.parent_list).to be(VCR::Cassette::HTTPInteractionList::NullList)
|
345
345
|
end
|
346
346
|
|
347
347
|
it "instantiates the http_interactions with parent_list set to VCR.http_interactions if given :exclusive => false" do
|
348
348
|
VCR.stub(:http_interactions => stub)
|
349
349
|
VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
|
350
350
|
cassette = VCR::Cassette.new('example', :record => record_mode, :exclusive => false)
|
351
|
-
cassette.http_interactions.parent_list.
|
351
|
+
expect(cassette.http_interactions.parent_list).to be(VCR.http_interactions)
|
352
352
|
end
|
353
353
|
|
354
354
|
if stub_requests
|
@@ -360,7 +360,7 @@ describe VCR::Cassette do
|
|
360
360
|
).exactly(3).times
|
361
361
|
|
362
362
|
cassette = VCR::Cassette.new('example', :record => record_mode)
|
363
|
-
cassette.
|
363
|
+
expect(cassette).to have(3).previously_recorded_interactions
|
364
364
|
end
|
365
365
|
|
366
366
|
it 'does not playback any interactions that are ignored in a before_playback hook' do
|
@@ -370,21 +370,21 @@ describe VCR::Cassette do
|
|
370
370
|
|
371
371
|
VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
|
372
372
|
cassette = VCR::Cassette.new('example', :record => record_mode)
|
373
|
-
cassette.
|
373
|
+
expect(cassette).to have(2).previously_recorded_interactions
|
374
374
|
end
|
375
375
|
|
376
376
|
it 'instantiates the http_interactions with the loaded interactions and the request matchers' do
|
377
377
|
VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
|
378
378
|
cassette = VCR::Cassette.new('example', :record => record_mode, :match_requests_on => [:body, :headers])
|
379
|
-
cassette.http_interactions.interactions.
|
380
|
-
cassette.http_interactions.request_matchers.
|
379
|
+
expect(cassette.http_interactions.interactions).to have(3).interactions
|
380
|
+
expect(cassette.http_interactions.request_matchers).to eq([:body, :headers])
|
381
381
|
end
|
382
382
|
else
|
383
383
|
it 'instantiates the http_interactions with the no interactions and the request matchers' do
|
384
384
|
VCR.configuration.cassette_library_dir = "#{VCR::SPEC_ROOT}/fixtures/cassette_spec"
|
385
385
|
cassette = VCR::Cassette.new('example', :record => record_mode, :match_requests_on => [:body, :headers])
|
386
|
-
cassette.http_interactions.interactions.
|
387
|
-
cassette.http_interactions.request_matchers.
|
386
|
+
expect(cassette.http_interactions.interactions).to have(0).interactions
|
387
|
+
expect(cassette.http_interactions.request_matchers).to eq([:body, :headers])
|
388
388
|
end
|
389
389
|
end
|
390
390
|
end
|
@@ -398,7 +398,7 @@ describe VCR::Cassette do
|
|
398
398
|
cassette = VCR.insert_cassette("foo", :allow_unused_http_interactions => false)
|
399
399
|
|
400
400
|
interaction_list = cassette.http_interactions
|
401
|
-
interaction_list.
|
401
|
+
expect(interaction_list).to respond_to(:assert_no_unused_interactions!).with(0).arguments
|
402
402
|
interaction_list.should_receive(:assert_no_unused_interactions!)
|
403
403
|
|
404
404
|
cassette.eject
|
@@ -408,7 +408,7 @@ describe VCR::Cassette do
|
|
408
408
|
cassette = VCR.insert_cassette("foo", :allow_unused_http_interactions => true)
|
409
409
|
|
410
410
|
interaction_list = cassette.http_interactions
|
411
|
-
interaction_list.
|
411
|
+
expect(interaction_list).to respond_to(:assert_no_unused_interactions!)
|
412
412
|
interaction_list.should_not_receive(:assert_no_unused_interactions!)
|
413
413
|
|
414
414
|
cassette.eject
|
@@ -428,12 +428,12 @@ describe VCR::Cassette do
|
|
428
428
|
it "writes the serializable_hash to disk as yaml" do
|
429
429
|
cassette = VCR::Cassette.new(:eject_test)
|
430
430
|
cassette.record_http_interaction http_interaction # so it has one
|
431
|
-
cassette.
|
431
|
+
expect(cassette).to respond_to(:serializable_hash)
|
432
432
|
cassette.stub(:serializable_hash => { "http_interactions" => [1, 3, 5] })
|
433
433
|
|
434
434
|
expect { cassette.eject }.to change { File.exist?(cassette.file) }.from(false).to(true)
|
435
435
|
saved_stuff = YAML.load_file(cassette.file)
|
436
|
-
saved_stuff.
|
436
|
+
expect(saved_stuff).to eq("http_interactions" => [1, 3, 5])
|
437
437
|
end
|
438
438
|
|
439
439
|
it 'invokes the appropriately tagged before_record hooks' do
|
@@ -471,7 +471,7 @@ describe VCR::Cassette do
|
|
471
471
|
cassette.eject
|
472
472
|
|
473
473
|
saved_recorded_interactions = ::YAML.load_file(cassette.file)
|
474
|
-
saved_recorded_interactions["http_interactions"].
|
474
|
+
expect(saved_recorded_interactions["http_interactions"]).to eq([interaction_2.to_hash])
|
475
475
|
end
|
476
476
|
|
477
477
|
it 'does not write the cassette to disk if all interactions have been ignored' do
|
@@ -485,7 +485,7 @@ describe VCR::Cassette do
|
|
485
485
|
cassette.stub!(:new_recorded_interactions).and_return([interaction_1])
|
486
486
|
cassette.eject
|
487
487
|
|
488
|
-
File.
|
488
|
+
expect(File).not_to exist(cassette.file)
|
489
489
|
end
|
490
490
|
|
491
491
|
it "writes the recorded interactions to a subdirectory if the cassette name includes a directory" do
|
@@ -495,7 +495,7 @@ describe VCR::Cassette do
|
|
495
495
|
|
496
496
|
expect { cassette.eject }.to change { File.exist?(cassette.file) }.from(false).to(true)
|
497
497
|
saved_recorded_interactions = YAML.load_file(cassette.file)
|
498
|
-
saved_recorded_interactions["http_interactions"].
|
498
|
+
expect(saved_recorded_interactions["http_interactions"]).to eq(recorded_interactions.map(&:to_hash))
|
499
499
|
end
|
500
500
|
|
501
501
|
[:all, :none, :new_episodes].each do |record_mode|
|
@@ -540,16 +540,16 @@ describe VCR::Cassette do
|
|
540
540
|
|
541
541
|
if record_mode == :all
|
542
542
|
it 'replaces previously recorded interactions with new ones when the requests match' do
|
543
|
-
saved_recorded_interactions.first.
|
544
|
-
saved_recorded_interactions.
|
543
|
+
expect(saved_recorded_interactions.first).to eq(interaction_foo_2)
|
544
|
+
expect(saved_recorded_interactions).not_to include(interaction_foo_1)
|
545
545
|
end
|
546
546
|
|
547
547
|
it 'appends new recorded interactions that do not match existing ones' do
|
548
|
-
saved_recorded_interactions.last.
|
548
|
+
expect(saved_recorded_interactions.last).to eq(interaction_bar)
|
549
549
|
end
|
550
550
|
else
|
551
551
|
it 'appends new recorded interactions after existing ones' do
|
552
|
-
saved_recorded_interactions.
|
552
|
+
expect(saved_recorded_interactions).to eq([interaction_foo_1, interaction_foo_2, interaction_bar])
|
553
553
|
end
|
554
554
|
end
|
555
555
|
end
|
@@ -17,13 +17,13 @@ describe VCR::Configuration do
|
|
17
17
|
relative_dir = 'tmp/cassette_library_dir/new_dir'
|
18
18
|
subject.cassette_library_dir = relative_dir
|
19
19
|
absolute_dir = File.join(VCR::SPEC_ROOT.sub(/\/spec\z/, ''), relative_dir)
|
20
|
-
subject.cassette_library_dir.
|
20
|
+
expect(subject.cassette_library_dir).to eq(absolute_dir)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
describe '#default_cassette_options' do
|
25
25
|
it 'has a hash with some defaults' do
|
26
|
-
subject.default_cassette_options.
|
26
|
+
expect(subject.default_cassette_options).to eq({
|
27
27
|
:match_requests_on => VCR::RequestMatcherRegistry::DEFAULT_MATCHERS,
|
28
28
|
:allow_unused_http_interactions => true,
|
29
29
|
:record => :once,
|
@@ -34,22 +34,22 @@ describe VCR::Configuration do
|
|
34
34
|
|
35
35
|
it "returns #{VCR::RequestMatcherRegistry::DEFAULT_MATCHERS.inspect} for :match_requests_on when other defaults have been set" do
|
36
36
|
subject.default_cassette_options = { :record => :none }
|
37
|
-
subject.default_cassette_options.
|
37
|
+
expect(subject.default_cassette_options).to include(:match_requests_on => VCR::RequestMatcherRegistry::DEFAULT_MATCHERS)
|
38
38
|
end
|
39
39
|
|
40
40
|
it "returns :once for :record when other defaults have been set" do
|
41
41
|
subject.default_cassette_options = { :erb => :true }
|
42
|
-
subject.default_cassette_options.
|
42
|
+
expect(subject.default_cassette_options).to include(:record => :once)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "allows defaults to be overriden" do
|
46
46
|
subject.default_cassette_options = { :record => :all }
|
47
|
-
subject.default_cassette_options.
|
47
|
+
expect(subject.default_cassette_options).to include(:record => :all)
|
48
48
|
end
|
49
49
|
|
50
50
|
it "allows other keys to be set" do
|
51
51
|
subject.default_cassette_options = { :re_record_interval => 10 }
|
52
|
-
subject.default_cassette_options.
|
52
|
+
expect(subject.default_cassette_options).to include(:re_record_interval => 10)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
@@ -62,7 +62,7 @@ describe VCR::Configuration do
|
|
62
62
|
matcher_run = false
|
63
63
|
subject.register_request_matcher(:custom) { |r1, r2| matcher_run = true }
|
64
64
|
VCR.request_matchers[:custom].matches?(:r1, :r2)
|
65
|
-
matcher_run.
|
65
|
+
expect(matcher_run).to be_true
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -83,7 +83,7 @@ describe VCR::Configuration do
|
|
83
83
|
called = false
|
84
84
|
subject.after_library_hooks_loaded { called = true }
|
85
85
|
subject.hook_into :fakeweb
|
86
|
-
called.
|
86
|
+
expect(called).to be_true
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -108,7 +108,7 @@ describe VCR::Configuration do
|
|
108
108
|
block_called = false
|
109
109
|
subject.ignore_request { |r| block_called = true }
|
110
110
|
VCR.request_ignorer.ignore?(stub(:parsed_uri => uri))
|
111
|
-
block_called.
|
111
|
+
expect(block_called).to be_true
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
@@ -116,7 +116,7 @@ describe VCR::Configuration do
|
|
116
116
|
[true, false].each do |val|
|
117
117
|
it "sets the allow_http_connections_when_no_cassette to #{val} when set to #{val}" do
|
118
118
|
subject.allow_http_connections_when_no_cassette = val
|
119
|
-
subject.allow_http_connections_when_no_cassette
|
119
|
+
expect(subject.allow_http_connections_when_no_cassette?).to eq(val)
|
120
120
|
end
|
121
121
|
end
|
122
122
|
end
|
@@ -133,8 +133,8 @@ describe VCR::Configuration do
|
|
133
133
|
::Net::HTTP.get_response(URI("http://localhost:#{VCR::SinatraApp.port}/foo"))
|
134
134
|
end
|
135
135
|
|
136
|
-
before_record_req.
|
137
|
-
before_request_req.
|
136
|
+
expect(before_record_req).not_to respond_to(:type)
|
137
|
+
expect(before_request_req).to respond_to(:type)
|
138
138
|
end unless (RUBY_VERSION =~ /^1\.8/ || RUBY_INTERPRETER == :jruby)
|
139
139
|
|
140
140
|
specify 'the filter_sensitive_data option works even when it modifies the URL in a way that makes it an invalid URI' do
|
@@ -156,9 +156,9 @@ describe VCR::Configuration do
|
|
156
156
|
called = false
|
157
157
|
VCR.configuration.send(hook_type, :my_tag) { called = true }
|
158
158
|
VCR.configuration.invoke_hook(hook_type, stub, stub(:tags => []))
|
159
|
-
called.
|
159
|
+
expect(called).to be_false
|
160
160
|
VCR.configuration.invoke_hook(hook_type, stub, stub(:tags => [:my_tag]))
|
161
|
-
called.
|
161
|
+
expect(called).to be_true
|
162
162
|
end
|
163
163
|
end
|
164
164
|
end
|
@@ -194,14 +194,14 @@ describe VCR::Configuration do
|
|
194
194
|
yielded_interaction = nil
|
195
195
|
subject.send(method, 'foo', &lambda { |i| yielded_interaction = i; 'bar' })
|
196
196
|
subject.invoke_hook(:before_record, interaction, stub.as_null_object)
|
197
|
-
yielded_interaction.
|
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
203
|
subject.invoke_hook(:before_playback, interaction, stub.as_null_object)
|
204
|
-
yielded_interaction.
|
204
|
+
expect(yielded_interaction).to equal(interaction)
|
205
205
|
end
|
206
206
|
end
|
207
207
|
end
|
@@ -218,11 +218,11 @@ describe VCR::Configuration do
|
|
218
218
|
yielded = false
|
219
219
|
subject.after_http_request(:stubbed_by_vcr?) { |req| yielded = true }
|
220
220
|
subject.invoke_hook(:after_http_request, request(:stubbed_by_vcr), response)
|
221
|
-
yielded.
|
221
|
+
expect(yielded).to be_true
|
222
222
|
|
223
223
|
yielded = false
|
224
224
|
subject.invoke_hook(:after_http_request, request(:ignored), response)
|
225
|
-
yielded.
|
225
|
+
expect(yielded).to be_false
|
226
226
|
end
|
227
227
|
end
|
228
228
|
|
@@ -239,7 +239,7 @@ describe VCR::Configuration do
|
|
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
|
242
|
-
subject.cassette_serializers[:custom].
|
242
|
+
expect(subject.cassette_serializers[:custom]).to be(custom_serializer)
|
243
243
|
end
|
244
244
|
end
|
245
245
|
|
@@ -248,7 +248,7 @@ describe VCR::Configuration do
|
|
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
|
251
|
-
subject.cassette_persisters[:custom].
|
251
|
+
expect(subject.cassette_persisters[:custom]).to be(custom_persister)
|
252
252
|
end
|
253
253
|
end
|
254
254
|
|
@@ -256,11 +256,11 @@ describe VCR::Configuration do
|
|
256
256
|
let(:custom_parser) { stub }
|
257
257
|
it 'allows a custom uri parser to be set' do
|
258
258
|
subject.uri_parser = custom_parser
|
259
|
-
subject.uri_parser.
|
259
|
+
expect(subject.uri_parser).to eq(custom_parser)
|
260
260
|
end
|
261
261
|
|
262
262
|
it "uses Ruby's standard library `URI` as a default" do
|
263
|
-
subject.uri_parser.
|
263
|
+
expect(subject.uri_parser).to eq(URI)
|
264
264
|
end
|
265
265
|
end
|
266
266
|
|
@@ -271,43 +271,55 @@ describe VCR::Configuration do
|
|
271
271
|
|
272
272
|
context "default hook" do
|
273
273
|
it "returns false when there is no current cassette" do
|
274
|
-
subject.preserve_exact_body_bytes_for?(message_for "string").
|
274
|
+
expect(subject.preserve_exact_body_bytes_for?(message_for "string")).to be_false
|
275
275
|
end
|
276
276
|
|
277
277
|
it "returns false when the current cassette has been created without the :preserve_exact_body_bytes option" do
|
278
278
|
VCR.insert_cassette('foo')
|
279
|
-
subject.preserve_exact_body_bytes_for?(message_for "string").
|
279
|
+
expect(subject.preserve_exact_body_bytes_for?(message_for "string")).to be_false
|
280
280
|
end
|
281
281
|
|
282
282
|
it 'returns true when the current cassette has been created with the :preserve_exact_body_bytes option' do
|
283
283
|
VCR.insert_cassette('foo', :preserve_exact_body_bytes => true)
|
284
|
-
subject.preserve_exact_body_bytes_for?(message_for "string").
|
284
|
+
expect(subject.preserve_exact_body_bytes_for?(message_for "string")).to be_true
|
285
285
|
end
|
286
286
|
end
|
287
287
|
|
288
288
|
it "returns true when the configured block returns true" do
|
289
289
|
subject.preserve_exact_body_bytes { |msg| msg.body == "a" }
|
290
|
-
subject.preserve_exact_body_bytes_for?(message_for "a").
|
291
|
-
subject.preserve_exact_body_bytes_for?(message_for "b").
|
290
|
+
expect(subject.preserve_exact_body_bytes_for?(message_for "a")).to be_true
|
291
|
+
expect(subject.preserve_exact_body_bytes_for?(message_for "b")).to be_false
|
292
292
|
end
|
293
293
|
|
294
294
|
it "returns true when any of the registered blocks returns true" do
|
295
295
|
called_hooks = []
|
296
296
|
subject.preserve_exact_body_bytes { called_hooks << :hook_1; false }
|
297
297
|
subject.preserve_exact_body_bytes { called_hooks << :hook_2; true }
|
298
|
-
subject.preserve_exact_body_bytes_for?(message_for "a").
|
299
|
-
called_hooks.
|
298
|
+
expect(subject.preserve_exact_body_bytes_for?(message_for "a")).to be_true
|
299
|
+
expect(called_hooks).to eq([:hook_1, :hook_2])
|
300
300
|
end
|
301
301
|
|
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
|
-
cassette.
|
304
|
+
expect(cassette).to be_a(VCR::Cassette)
|
305
305
|
message = stub(:message)
|
306
306
|
|
307
307
|
yielded_objects = nil
|
308
308
|
subject.preserve_exact_body_bytes { |a, b| yielded_objects = [a, b] }
|
309
309
|
subject.preserve_exact_body_bytes_for?(message)
|
310
|
-
yielded_objects.
|
310
|
+
expect(yielded_objects).to eq([message, cassette])
|
311
|
+
end
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
describe "#configure_rspec_metadata!" do
|
316
|
+
it "only configures the underlying metadata once, no matter how many times it is called" do
|
317
|
+
VCR::RSpec::Metadata.should_receive(:configure!).once
|
318
|
+
VCR.configure do |c|
|
319
|
+
c.configure_rspec_metadata!
|
320
|
+
end
|
321
|
+
VCR.configure do |c|
|
322
|
+
c.configure_rspec_metadata!
|
311
323
|
end
|
312
324
|
end
|
313
325
|
end
|