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
@@ -26,6 +26,11 @@ describe "Typhoeus 0.4 hook", :with_monkey_patches => :typhoeus_0_4 do
|
|
26
26
|
::WebMock::HttpLibAdapters::TyphoeusAdapter.should_receive(:disable!)
|
27
27
|
$typhoeus_after_loaded_hook.conditionally_invoke
|
28
28
|
end
|
29
|
+
|
30
|
+
it "warns about Typhoeus 0.4 deprecation" do
|
31
|
+
::Kernel.should_receive(:warn).with("WARNING: VCR's Typhoeus 0.4 integration is deprecated and will be removed in VCR 3.0.")
|
32
|
+
$typhoeus_0_4_after_loaded_hook.conditionally_invoke
|
33
|
+
end
|
29
34
|
end
|
30
35
|
end if RUBY_INTERPRETER == :mri && ::Typhoeus::VERSION.to_f < 0.5
|
31
36
|
|
@@ -61,7 +61,7 @@ describe "Typhoeus hook", :with_monkey_patches => :typhoeus do
|
|
61
61
|
recorded = make_requests
|
62
62
|
played_back = make_requests
|
63
63
|
|
64
|
-
played_back.
|
64
|
+
expect(played_back).to eq(recorded)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -77,9 +77,9 @@ describe "Typhoeus hook", :with_monkey_patches => :typhoeus do
|
|
77
77
|
it 'recorded and played back properly' do
|
78
78
|
recorded = make_single_request
|
79
79
|
played_back = make_single_request
|
80
|
-
recorded.
|
80
|
+
expect(recorded).not_to be_nil
|
81
81
|
|
82
|
-
played_back.
|
82
|
+
expect(played_back).to eq(recorded)
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'support/shared_example_groups/excon'
|
2
3
|
|
3
4
|
describe "WebMock hook", :with_monkey_patches => :webmock do
|
4
5
|
after(:each) do
|
@@ -34,7 +35,7 @@ describe "WebMock hook", :with_monkey_patches => :webmock do
|
|
34
35
|
webmock_request.instance_variable_set(:@__typed_vcr_request, request)
|
35
36
|
|
36
37
|
run_after_request_callback
|
37
|
-
webmock_request.instance_variables.map(&:to_sym).
|
38
|
+
expect(webmock_request.instance_variables.map(&:to_sym)).not_to include(:@__typed_vcr_request)
|
38
39
|
end
|
39
40
|
|
40
41
|
context "when there'ss a bug and the request does not have the @__typed_vcr_request in the after_request callbacks" do
|
@@ -43,8 +44,8 @@ describe "WebMock hook", :with_monkey_patches => :webmock do
|
|
43
44
|
|
44
45
|
it 'records the HTTP interaction properly' do
|
45
46
|
VCR.should_receive(:record_http_interaction) do |i|
|
46
|
-
i.request.uri.
|
47
|
-
i.response.body.
|
47
|
+
expect(i.request.uri).to eq("http://foo.com/")
|
48
|
+
expect(i.response.body).to eq("OK")
|
48
49
|
end
|
49
50
|
|
50
51
|
run_after_request_callback
|
@@ -57,8 +58,8 @@ describe "WebMock hook", :with_monkey_patches => :webmock do
|
|
57
58
|
end
|
58
59
|
|
59
60
|
run_after_request_callback
|
60
|
-
request.uri.
|
61
|
-
request.type.
|
61
|
+
expect(request.uri).to eq("http://foo.com/")
|
62
|
+
expect(request.type).to eq(:unknown)
|
62
63
|
end
|
63
64
|
|
64
65
|
it 'prints a warning' do
|
@@ -111,4 +112,11 @@ describe "WebMock hook", :with_monkey_patches => :webmock do
|
|
111
112
|
end
|
112
113
|
end
|
113
114
|
end
|
115
|
+
|
116
|
+
it_behaves_like "Excon streaming" do
|
117
|
+
before(:each) do
|
118
|
+
pending "waiting on bblimke/webmock#246 for a fix"
|
119
|
+
end
|
120
|
+
end
|
114
121
|
end
|
122
|
+
|
@@ -4,8 +4,8 @@ module VCR
|
|
4
4
|
describe LibraryHooks do
|
5
5
|
describe '#disabled?' do
|
6
6
|
it 'returns false by default for any argument given' do
|
7
|
-
subject.disabled?(:foo).
|
8
|
-
subject.disabled?(:bar).
|
7
|
+
expect(subject.disabled?(:foo)).to be_false
|
8
|
+
expect(subject.disabled?(:bar)).to be_false
|
9
9
|
end
|
10
10
|
|
11
11
|
context 'when a library hook is exclusively enabled' do
|
@@ -16,7 +16,7 @@ module VCR
|
|
16
16
|
faraday_disabled = subject.disabled?(:faraday)
|
17
17
|
end
|
18
18
|
|
19
|
-
faraday_disabled.
|
19
|
+
expect(faraday_disabled).to eq(false)
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'returns true for every other argument given' do
|
@@ -27,8 +27,8 @@ module VCR
|
|
27
27
|
bar_disabled = subject.disabled?(:bar)
|
28
28
|
end
|
29
29
|
|
30
|
-
foo_disabled.
|
31
|
-
bar_disabled.
|
30
|
+
expect(foo_disabled).to be_true
|
31
|
+
expect(bar_disabled).to be_true
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -36,14 +36,14 @@ module VCR
|
|
36
36
|
describe '#exclusively_enabled' do
|
37
37
|
it 'restores all hook to being enabled when the block completes' do
|
38
38
|
subject.exclusively_enabled(:faraday) { }
|
39
|
-
subject.disabled?(:foo).
|
40
|
-
subject.disabled?(:faraday).
|
39
|
+
expect(subject.disabled?(:foo)).to be_false
|
40
|
+
expect(subject.disabled?(:faraday)).to be_false
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'restores all hooks to being enabled when the block completes, even if there is an error' do
|
44
44
|
subject.exclusively_enabled(:faraday) { raise "boom" } rescue
|
45
|
-
subject.disabled?(:foo).
|
46
|
-
subject.disabled?(:faraday).
|
45
|
+
expect(subject.disabled?(:foo)).to be_false
|
46
|
+
expect(subject.disabled?(:faraday)).to be_false
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -23,8 +23,8 @@ describe VCR::Middleware::Faraday do
|
|
23
23
|
payload = { :file => Faraday::UploadIO.new(__FILE__, 'text/plain') }
|
24
24
|
|
25
25
|
VCR.should_receive(:record_http_interaction) do |i|
|
26
|
-
i.request.headers['Content-Type'].first.
|
27
|
-
i.request.body.
|
26
|
+
expect(i.request.headers['Content-Type'].first).to include("multipart")
|
27
|
+
expect(i.request.body).to include(File.read(__FILE__))
|
28
28
|
end
|
29
29
|
|
30
30
|
VCR.use_cassette("upload") do
|
@@ -63,8 +63,8 @@ describe VCR::Middleware::Faraday do
|
|
63
63
|
end
|
64
64
|
|
65
65
|
# there should be no blanks
|
66
|
-
recorded.select { |r| r.to_s == '' }.
|
67
|
-
played_back.
|
66
|
+
expect(recorded.select { |r| r.to_s == '' }).to eq([])
|
67
|
+
expect(played_back).to eq(recorded)
|
68
68
|
end
|
69
69
|
|
70
70
|
shared_examples_for "exclusive library hook" do
|
@@ -73,17 +73,17 @@ describe VCR::Middleware::Faraday do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
it 'makes the faraday middleware exclusively enabled for the duration of the request' do
|
76
|
-
VCR.library_hooks.
|
76
|
+
expect(VCR.library_hooks).not_to be_disabled(:fakeweb)
|
77
77
|
|
78
78
|
hook_called = false
|
79
79
|
VCR.configuration.after_http_request do
|
80
80
|
hook_called = true
|
81
|
-
VCR.library_hooks.
|
81
|
+
expect(VCR.library_hooks).to be_disabled(:fakeweb)
|
82
82
|
end
|
83
83
|
|
84
84
|
make_request
|
85
|
-
VCR.library_hooks.
|
86
|
-
hook_called.
|
85
|
+
expect(VCR.library_hooks).not_to be_disabled(:fakeweb)
|
86
|
+
expect(hook_called).to be_true
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -133,11 +133,11 @@ describe VCR::Middleware::Faraday do
|
|
133
133
|
VCR.configuration.after_http_request { |request| VCR.eject_cassette }
|
134
134
|
|
135
135
|
VCR.should_receive(:record_http_interaction) do |interaction|
|
136
|
-
VCR.current_cassette.
|
136
|
+
expect(VCR.current_cassette).to be(inserted_cassette)
|
137
137
|
end
|
138
138
|
|
139
139
|
make_request
|
140
|
-
VCR.current_cassette.
|
140
|
+
expect(VCR.current_cassette).to be_nil
|
141
141
|
end
|
142
142
|
end
|
143
143
|
end if defined?(::Typhoeus)
|
@@ -6,29 +6,29 @@ module VCR
|
|
6
6
|
describe CassetteArguments do
|
7
7
|
describe '#name' do
|
8
8
|
it 'initially returns nil' do
|
9
|
-
subject.name.
|
9
|
+
expect(subject.name).to be_nil
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'stores the given value, returning it when no arg is given' do
|
13
13
|
subject.name :value1
|
14
|
-
subject.name.
|
14
|
+
expect(subject.name).to eq(:value1)
|
15
15
|
|
16
16
|
subject.name :value2
|
17
|
-
subject.name.
|
17
|
+
expect(subject.name).to eq(:value2)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
describe '#options' do
|
22
22
|
it 'initially returns an empty hash' do
|
23
|
-
subject.options.
|
23
|
+
expect(subject.options).to eq({})
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'merges the given hash options, returning them when no arg is given' do
|
27
27
|
subject.options :record => :new_episodes
|
28
|
-
subject.options.
|
28
|
+
expect(subject.options).to eq({ :record => :new_episodes })
|
29
29
|
|
30
30
|
subject.options :erb => true
|
31
|
-
subject.options.
|
31
|
+
expect(subject.options).to eq({ :record => :new_episodes, :erb => true })
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -48,25 +48,30 @@ module VCR
|
|
48
48
|
rack_app = mock
|
49
49
|
rack_app.should_receive(:call).with(env_hash).and_return(:response)
|
50
50
|
instance = described_class.new(rack_app) { |c| c.name 'cassette_name' }
|
51
|
-
instance.call(env_hash).
|
51
|
+
expect(instance.call(env_hash)).to eq(:response)
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'uses a cassette when the rack app is called' do
|
55
|
-
VCR.current_cassette.
|
56
|
-
rack_app = lambda { |env| VCR.current_cassette.
|
55
|
+
expect(VCR.current_cassette).to be_nil
|
56
|
+
rack_app = lambda { |env| expect(VCR.current_cassette).not_to be_nil }
|
57
57
|
instance = described_class.new(rack_app) { |c| c.name 'cassette_name' }
|
58
58
|
instance.call({})
|
59
|
-
VCR.current_cassette.
|
59
|
+
expect(VCR.current_cassette).to be_nil
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'sets the cassette name based on the provided block' do
|
63
|
-
rack_app = lambda
|
63
|
+
rack_app = lambda do |env|
|
64
|
+
expect(VCR.current_cassette.name).to eq('rack_cassette')
|
65
|
+
end
|
64
66
|
instance = described_class.new(rack_app) { |c| c.name 'rack_cassette' }
|
65
67
|
instance.call({})
|
66
68
|
end
|
67
69
|
|
68
70
|
it 'sets the cassette options based on the provided block' do
|
69
|
-
rack_app = lambda
|
71
|
+
rack_app = lambda do |env|
|
72
|
+
expect(VCR.current_cassette.erb).to eq({ :foo => :bar })
|
73
|
+
end
|
74
|
+
|
70
75
|
instance = described_class.new(rack_app, &lambda do |c|
|
71
76
|
c.name 'c'
|
72
77
|
c.options :erb => { :foo => :bar }
|
@@ -77,7 +82,7 @@ module VCR
|
|
77
82
|
|
78
83
|
it 'yields the rack env to the provided block when the block accepts 2 arguments' do
|
79
84
|
instance = described_class.new(lambda { |env| }, &lambda do |c, env|
|
80
|
-
env.
|
85
|
+
expect(env).to eq(env_hash)
|
81
86
|
c.name 'c'
|
82
87
|
end)
|
83
88
|
|
@@ -88,7 +93,7 @@ module VCR
|
|
88
93
|
let(:threaded_app) do
|
89
94
|
lambda do |env|
|
90
95
|
sleep 0.15
|
91
|
-
VCR.send(:cassettes).
|
96
|
+
expect(VCR.send(:cassettes)).to have(1).cassette
|
92
97
|
[200, {}, ['OK']]
|
93
98
|
end
|
94
99
|
end
|
@@ -102,7 +107,7 @@ module VCR
|
|
102
107
|
stack.call({})
|
103
108
|
thread.join
|
104
109
|
|
105
|
-
VCR.current_cassette.
|
110
|
+
expect(VCR.current_cassette).to be_nil
|
106
111
|
end
|
107
112
|
end
|
108
113
|
end
|
@@ -9,7 +9,7 @@ module VCR
|
|
9
9
|
|
10
10
|
shared_examples_for "#ignore?" do |url, expected_value|
|
11
11
|
it "returns #{expected_value} if given a request with a url like #{url}" do
|
12
|
-
subject.ignore?(request(url)).
|
12
|
+
expect(subject.ignore?(request(url))).to eq(expected_value)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -58,11 +58,11 @@ module VCR
|
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'ignores requests for which the block returns true' do
|
61
|
-
subject.ignore?(request('http://foo.com:5/bar')).
|
61
|
+
expect(subject.ignore?(request('http://foo.com:5/bar'))).to be_true
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'does not ignore requests for which the block returns false' do
|
65
|
-
subject.ignore?(request('http://foo.com:6/bar')).
|
65
|
+
expect(subject.ignore?(request('http://foo.com:6/bar'))).to be_false
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
@@ -21,7 +21,7 @@ module VCR
|
|
21
21
|
matcher_called = false
|
22
22
|
subject.register(:my_matcher) { |*a| matcher_called = true }
|
23
23
|
subject[:my_matcher].matches?(stub, stub)
|
24
|
-
matcher_called.
|
24
|
+
expect(matcher_called).to be_true
|
25
25
|
end
|
26
26
|
|
27
27
|
context 'when there is already a matcher for the given name' do
|
@@ -32,7 +32,7 @@ module VCR
|
|
32
32
|
|
33
33
|
it 'overrides the existing matcher' do
|
34
34
|
subject.register(:foo) { |*a| true }
|
35
|
-
subject[:foo].matches?(stub, stub).
|
35
|
+
expect(subject[:foo].matches?(stub, stub)).to be_true
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'warns that there is a name collision' do
|
@@ -49,7 +49,7 @@ module VCR
|
|
49
49
|
it 'returns a previously registered matcher' do
|
50
50
|
matcher = lambda { }
|
51
51
|
subject.register(:my_matcher, &matcher)
|
52
|
-
subject[:my_matcher].
|
52
|
+
expect(subject[:my_matcher]).to eq(RequestMatcherRegistry::Matcher.new(matcher))
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'raises an ArgumentError when no matcher has been registered for the given name' do
|
@@ -60,15 +60,15 @@ module VCR
|
|
60
60
|
|
61
61
|
it 'returns an object that calls the named block when #matches? is called on it' do
|
62
62
|
subject.register(:foo) { |r1, r2| r1 == 5 || r2 == 10 }
|
63
|
-
subject[:foo].matches?(5, 0).
|
64
|
-
subject[:foo].matches?(0, 10).
|
65
|
-
subject[:foo].matches?(7, 7).
|
63
|
+
expect(subject[:foo].matches?(5, 0)).to be_true
|
64
|
+
expect(subject[:foo].matches?(0, 10)).to be_true
|
65
|
+
expect(subject[:foo].matches?(7, 7)).to be_false
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'returns an object that calls the given callable when #matches? is called on it' do
|
69
69
|
block_called = false
|
70
70
|
subject[lambda { |r1, r2| block_called = true }].matches?(5, 0)
|
71
|
-
block_called.
|
71
|
+
expect(block_called).to be_true
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -77,80 +77,91 @@ module VCR
|
|
77
77
|
it 'returns a matcher that can be registered for later use' do
|
78
78
|
matcher = subject.send(meth, :foo)
|
79
79
|
subject.register(:uri_without_foo, &matcher)
|
80
|
-
subject[:uri_without_foo].matches?(
|
80
|
+
matches = subject[:uri_without_foo].matches?(
|
81
81
|
request_with(:uri => 'http://example.com/search?foo=123'),
|
82
82
|
request_with(:uri => 'http://example.com/search?foo=123')
|
83
|
-
)
|
83
|
+
)
|
84
|
+
expect(matches).to be_true
|
84
85
|
end
|
85
86
|
|
86
87
|
it 'matches two requests with URIs that are identical' do
|
87
|
-
subject[subject.send(meth, :foo)].matches?(
|
88
|
+
matches = subject[subject.send(meth, :foo)].matches?(
|
88
89
|
request_with(:uri => 'http://example.com/search?foo=123'),
|
89
90
|
request_with(:uri => 'http://example.com/search?foo=123')
|
90
|
-
)
|
91
|
+
)
|
92
|
+
expect(matches).to be_true
|
91
93
|
end
|
92
94
|
|
93
95
|
it 'does not match two requests with different path parts' do
|
94
|
-
subject[subject.send(meth, :foo)].matches?(
|
96
|
+
matches = subject[subject.send(meth, :foo)].matches?(
|
95
97
|
request_with(:uri => 'http://example.com/search?foo=123'),
|
96
98
|
request_with(:uri => 'http://example.com/find?foo=123')
|
97
|
-
)
|
99
|
+
)
|
100
|
+
expect(matches).to be_false
|
98
101
|
end
|
99
102
|
|
100
103
|
it 'ignores the given query parameters when it is at the start' do
|
101
|
-
subject[subject.send(meth, :foo)].matches?(
|
104
|
+
matches = subject[subject.send(meth, :foo)].matches?(
|
102
105
|
request_with(:uri => 'http://example.com/search?foo=123&bar=r'),
|
103
106
|
request_with(:uri => 'http://example.com/search?foo=124&bar=r')
|
104
|
-
)
|
107
|
+
)
|
108
|
+
expect(matches).to be_true
|
105
109
|
end
|
106
110
|
|
107
111
|
it 'ignores the given query parameters when it is at the end' do
|
108
|
-
subject[subject.send(meth, :bar)].matches?(
|
112
|
+
matches = subject[subject.send(meth, :bar)].matches?(
|
109
113
|
request_with(:uri => 'http://example.com/search?foo=124&bar=r'),
|
110
114
|
request_with(:uri => 'http://example.com/search?foo=124&bar=q')
|
111
|
-
)
|
115
|
+
)
|
116
|
+
expect(matches).to be_true
|
112
117
|
end
|
113
118
|
|
114
119
|
it 'still takes into account other query params' do
|
115
|
-
subject[subject.send(meth, :bar)].matches?(
|
120
|
+
matches = subject[subject.send(meth, :bar)].matches?(
|
116
121
|
request_with(:uri => 'http://example.com/search?foo=123&bar=r'),
|
117
122
|
request_with(:uri => 'http://example.com/search?foo=124&bar=q')
|
118
|
-
)
|
123
|
+
)
|
124
|
+
expect(matches).to be_false
|
119
125
|
end
|
120
126
|
|
121
127
|
it 'handles multiple query params of the same name' do
|
122
|
-
subject[subject.send(meth, :tag)].matches?(
|
128
|
+
matches = subject[subject.send(meth, :tag)].matches?(
|
123
129
|
request_with(:uri => 'http://example.com/search?foo=124&tag[]=a&tag[]=b'),
|
124
130
|
request_with(:uri => 'http://example.com/search?foo=124&tag[]=d&tag[]=e')
|
125
|
-
)
|
131
|
+
)
|
132
|
+
expect(matches).to be_true
|
126
133
|
end
|
127
134
|
|
128
135
|
it 'can ignore multiple named parameters' do
|
129
|
-
subject[subject.send(meth, :foo, :bar)].matches?(
|
136
|
+
matches = subject[subject.send(meth, :foo, :bar)].matches?(
|
130
137
|
request_with(:uri => 'http://example.com/search?foo=123&bar=r&baz=9'),
|
131
138
|
request_with(:uri => 'http://example.com/search?foo=124&baz=9&bar=q')
|
132
|
-
)
|
139
|
+
)
|
140
|
+
expect(matches).to be_true
|
133
141
|
end
|
134
142
|
|
135
143
|
it 'matches two requests with URIs that have no params' do
|
136
|
-
subject[subject.send(meth, :foo, :bar)].matches?(
|
144
|
+
matches = subject[subject.send(meth, :foo, :bar)].matches?(
|
137
145
|
request_with(:uri => 'http://example.com/search'),
|
138
146
|
request_with(:uri => 'http://example.com/search')
|
139
|
-
)
|
147
|
+
)
|
148
|
+
expect(matches).to be_true
|
140
149
|
end
|
141
150
|
|
142
151
|
it 'does not match two requests with URIs that have no params but different paths' do
|
143
|
-
subject[subject.send(meth, :foo, :bar)].matches?(
|
152
|
+
matches = subject[subject.send(meth, :foo, :bar)].matches?(
|
144
153
|
request_with(:uri => 'http://example.com/foo'),
|
145
154
|
request_with(:uri => 'http://example.com/bar')
|
146
|
-
)
|
155
|
+
)
|
156
|
+
expect(matches).to be_false
|
147
157
|
end
|
148
158
|
|
149
159
|
it 'matches a second request when all parameters are filtered' do
|
150
|
-
subject[subject.send(meth, :q, :oq)].matches?(
|
160
|
+
matches = subject[subject.send(meth, :q, :oq)].matches?(
|
151
161
|
request_with(:uri => 'http://example.com/search'),
|
152
162
|
request_with(:uri => 'http://example.com/search?q=vcr&oq=vcr')
|
153
|
-
)
|
163
|
+
)
|
164
|
+
expect(matches).to be_true
|
154
165
|
end
|
155
166
|
end
|
156
167
|
end
|
@@ -158,127 +169,143 @@ module VCR
|
|
158
169
|
describe "built-ins" do
|
159
170
|
describe ":method" do
|
160
171
|
it 'matches when it is the same' do
|
161
|
-
subject[:method].matches?(
|
172
|
+
matches = subject[:method].matches?(
|
162
173
|
request_with(:method => :get),
|
163
174
|
request_with(:method => :get)
|
164
|
-
)
|
175
|
+
)
|
176
|
+
expect(matches).to be_true
|
165
177
|
end
|
166
178
|
|
167
179
|
it 'does not match when it is not the same' do
|
168
|
-
subject[:method].matches?(
|
180
|
+
matches = subject[:method].matches?(
|
169
181
|
request_with(:method => :get),
|
170
182
|
request_with(:method => :post)
|
171
|
-
)
|
183
|
+
)
|
184
|
+
expect(matches).to be_false
|
172
185
|
end
|
173
186
|
end
|
174
187
|
|
175
188
|
describe ":uri" do
|
176
189
|
it 'matches when it is exactly the same' do
|
177
|
-
subject[:uri].matches?(
|
190
|
+
matches = subject[:uri].matches?(
|
178
191
|
request_with(:uri => 'http://foo.com/bar?baz=7'),
|
179
192
|
request_with(:uri => 'http://foo.com/bar?baz=7')
|
180
|
-
)
|
193
|
+
)
|
194
|
+
expect(matches).to be_true
|
181
195
|
end
|
182
196
|
|
183
197
|
it 'does not match when it is different' do
|
184
|
-
subject[:uri].matches?(
|
198
|
+
matches = subject[:uri].matches?(
|
185
199
|
request_with(:uri => 'http://foo1.com/bar?baz=7'),
|
186
200
|
request_with(:uri => 'http://foo2.com/bar?baz=7')
|
187
|
-
)
|
201
|
+
)
|
202
|
+
expect(matches).to be_false
|
188
203
|
end
|
189
204
|
end
|
190
205
|
|
191
206
|
describe ":host" do
|
192
207
|
it 'matches when it is the same' do
|
193
|
-
subject[:host].matches?(
|
208
|
+
matches = subject[:host].matches?(
|
194
209
|
request_with(:uri => 'http://foo.com/bar'),
|
195
210
|
request_with(:uri => 'http://foo.com/car')
|
196
|
-
)
|
211
|
+
)
|
212
|
+
expect(matches).to be_true
|
197
213
|
end
|
198
214
|
|
199
215
|
it 'does not match when it is not the same' do
|
200
|
-
subject[:host].matches?(
|
216
|
+
matches = subject[:host].matches?(
|
201
217
|
request_with(:uri => 'http://foo.com/bar'),
|
202
218
|
request_with(:uri => 'http://goo.com/bar')
|
203
|
-
)
|
219
|
+
)
|
220
|
+
expect(matches).to be_false
|
204
221
|
end
|
205
222
|
end
|
206
223
|
|
207
224
|
describe ":path" do
|
208
225
|
it 'matches when it is the same' do
|
209
|
-
subject[:path].matches?(
|
226
|
+
matches = subject[:path].matches?(
|
210
227
|
request_with(:uri => 'http://foo.com/bar?a=8'),
|
211
228
|
request_with(:uri => 'http://goo.com/bar?a=9')
|
212
|
-
)
|
229
|
+
)
|
230
|
+
expect(matches).to be_true
|
213
231
|
end
|
214
232
|
|
215
233
|
it 'does not match when it is not the same' do
|
216
|
-
subject[:path].matches?(
|
234
|
+
matches = subject[:path].matches?(
|
217
235
|
request_with(:uri => 'http://foo.com/bar?a=8'),
|
218
236
|
request_with(:uri => 'http://foo.com/car?a=8')
|
219
|
-
)
|
237
|
+
)
|
238
|
+
expect(matches).to be_false
|
220
239
|
end
|
221
240
|
end
|
222
241
|
|
223
242
|
describe ":body" do
|
224
243
|
it 'matches when it is the same' do
|
225
|
-
subject[:body].matches?(
|
244
|
+
matches = subject[:body].matches?(
|
226
245
|
request_with(:body => 'foo'),
|
227
246
|
request_with(:body => 'foo')
|
228
|
-
)
|
247
|
+
)
|
248
|
+
expect(matches).to be_true
|
229
249
|
end
|
230
250
|
|
231
251
|
it 'does not match when it is not the same' do
|
232
|
-
subject[:body].matches?(
|
252
|
+
matches = subject[:body].matches?(
|
233
253
|
request_with(:body => 'foo'),
|
234
254
|
request_with(:body => 'bar')
|
235
|
-
)
|
255
|
+
)
|
256
|
+
expect(matches).to be_false
|
236
257
|
end
|
237
258
|
end
|
238
259
|
|
239
260
|
describe ":headers" do
|
240
261
|
it 'matches when it is the same' do
|
241
|
-
subject[:headers].matches?(
|
262
|
+
matches = subject[:headers].matches?(
|
242
263
|
request_with(:headers => { 'a' => 1, 'b' => 2 }),
|
243
264
|
request_with(:headers => { 'b' => 2, 'a' => 1 })
|
244
|
-
)
|
265
|
+
)
|
266
|
+
expect(matches).to be_true
|
245
267
|
end
|
246
268
|
|
247
269
|
it 'does not match when it is not the same' do
|
248
|
-
subject[:headers].matches?(
|
270
|
+
matches = subject[:headers].matches?(
|
249
271
|
request_with(:headers => { 'a' => 3, 'b' => 2 }),
|
250
272
|
request_with(:headers => { 'b' => 2, 'a' => 1 })
|
251
|
-
)
|
273
|
+
)
|
274
|
+
expect(matches).to be_false
|
252
275
|
end
|
253
276
|
end
|
254
277
|
|
255
278
|
describe ":query" do
|
256
279
|
it 'matches when it is identical' do
|
257
|
-
subject[:query].matches?(
|
280
|
+
matches = subject[:query].matches?(
|
258
281
|
request_with(:uri => 'http://foo.com/bar?a=8'),
|
259
282
|
request_with(:uri => 'http://goo.com/car?a=8')
|
260
|
-
)
|
283
|
+
)
|
284
|
+
expect(matches).to be_true
|
261
285
|
end
|
262
286
|
|
263
287
|
it 'matches when empty' do
|
264
|
-
subject[:query].matches?(
|
288
|
+
matches = subject[:query].matches?(
|
265
289
|
request_with(:uri => 'http://foo.com/bar'),
|
266
290
|
request_with(:uri => 'http://goo.com/car')
|
267
|
-
)
|
291
|
+
)
|
292
|
+
expect(matches).to be_true
|
268
293
|
end
|
269
294
|
|
270
295
|
it 'matches when parameters are reordered' do
|
271
|
-
subject[:query].matches?(
|
296
|
+
matches = subject[:query].matches?(
|
272
297
|
request_with(:uri => 'http://foo.com/bar?a=8&b=9'),
|
273
298
|
request_with(:uri => 'http://goo.com/car?b=9&a=8')
|
274
|
-
)
|
299
|
+
)
|
300
|
+
expect(matches).to be_true
|
275
301
|
end
|
276
302
|
|
277
303
|
it 'does not match when it is not the same' do
|
278
|
-
subject[:query].matches?(
|
304
|
+
matches = subject[:query].matches?(
|
279
305
|
request_with(:uri => 'http://foo.com/bar?a=8'),
|
280
306
|
request_with(:uri => 'http://goo.com/car?b=8')
|
281
|
-
)
|
307
|
+
)
|
308
|
+
expect(matches).to be_false
|
282
309
|
end
|
283
310
|
end
|
284
311
|
end
|