vcr 3.0.3 → 4.0.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 +4 -4
- data/lib/vcr.rb +18 -1
- data/lib/vcr/cassette.rb +11 -3
- data/lib/vcr/cassette/persisters/file_system.rb +1 -1
- data/lib/vcr/configuration.rb +3 -5
- data/lib/vcr/deprecations.rb +0 -62
- data/lib/vcr/errors.rb +16 -0
- data/lib/vcr/library_hooks/typhoeus.rb +37 -8
- data/lib/vcr/middleware/faraday.rb +5 -1
- data/lib/vcr/structs.rb +1 -1
- data/lib/vcr/util/hooks.rb +1 -0
- data/lib/vcr/version.rb +1 -1
- metadata +9 -249
- data/features/CHANGELOG.md +0 -710
- data/features/CONTRIBUTING.md +0 -26
- data/features/LICENSE.md +0 -20
- data/features/README.md +0 -339
- data/features/Upgrade.md +0 -289
- data/features/about_these_examples.md +0 -18
- data/features/cassettes/allow_unused_http_interactions.feature +0 -100
- data/features/cassettes/automatic_re_recording.feature +0 -72
- data/features/cassettes/decompress.feature +0 -74
- data/features/cassettes/dynamic_erb.feature +0 -100
- data/features/cassettes/exclusive.feature +0 -126
- data/features/cassettes/format.feature +0 -411
- data/features/cassettes/freezing_time.feature +0 -68
- data/features/cassettes/naming.feature +0 -28
- data/features/cassettes/no_cassette.feature +0 -152
- data/features/cassettes/update_content_length_header.feature +0 -112
- data/features/configuration/allow_http_connections_when_no_cassette.feature +0 -55
- data/features/configuration/cassette_library_dir.feature +0 -31
- data/features/configuration/debug_logging.feature +0 -58
- data/features/configuration/default_cassette_options.feature +0 -100
- data/features/configuration/filter_sensitive_data.feature +0 -153
- data/features/configuration/hook_into.feature +0 -172
- data/features/configuration/ignore_request.feature +0 -192
- data/features/configuration/preserve_exact_body_bytes.feature +0 -108
- data/features/configuration/query_parser.feature +0 -84
- data/features/configuration/uri_parser.feature +0 -93
- data/features/getting_started.md +0 -82
- data/features/hooks/after_http_request.feature +0 -58
- data/features/hooks/around_http_request.feature +0 -57
- data/features/hooks/before_http_request.feature +0 -63
- data/features/hooks/before_playback.feature +0 -184
- data/features/hooks/before_record.feature +0 -172
- data/features/http_libraries/em_http_request.feature +0 -250
- data/features/http_libraries/net_http.feature +0 -179
- data/features/middleware/faraday.feature +0 -56
- data/features/middleware/rack.feature +0 -92
- data/features/record_modes/all.feature +0 -82
- data/features/record_modes/new_episodes.feature +0 -79
- data/features/record_modes/none.feature +0 -72
- data/features/record_modes/once.feature +0 -95
- data/features/request_matching/README.md +0 -30
- data/features/request_matching/body.feature +0 -91
- data/features/request_matching/body_as_json.feature +0 -90
- data/features/request_matching/custom_matcher.feature +0 -135
- data/features/request_matching/headers.feature +0 -85
- data/features/request_matching/host.feature +0 -95
- data/features/request_matching/identical_request_sequence.feature +0 -89
- data/features/request_matching/method.feature +0 -96
- data/features/request_matching/path.feature +0 -96
- data/features/request_matching/playback_repeats.feature +0 -98
- data/features/request_matching/query.feature +0 -97
- data/features/request_matching/uri.feature +0 -94
- data/features/request_matching/uri_without_param.feature +0 -101
- data/features/step_definitions/cli_steps.rb +0 -199
- data/features/support/env.rb +0 -46
- data/features/support/http_lib_filters.rb +0 -46
- data/features/test_frameworks/cucumber.feature +0 -211
- data/features/test_frameworks/rspec_macro.feature +0 -81
- data/features/test_frameworks/rspec_metadata.feature +0 -150
- data/features/test_frameworks/test_unit.feature +0 -49
- data/lib/vcr/extensions/net_http_response.rb +0 -36
- data/lib/vcr/library_hooks/fakeweb.rb +0 -197
- data/spec/acceptance/concurrency_spec.rb +0 -51
- data/spec/acceptance/threading_spec.rb +0 -34
- data/spec/fixtures/cassette_spec/1_x_cassette.yml +0 -110
- data/spec/fixtures/cassette_spec/empty.yml +0 -0
- data/spec/fixtures/cassette_spec/example.yml +0 -111
- data/spec/fixtures/cassette_spec/with_localhost_requests.yml +0 -111
- data/spec/fixtures/fake_example_responses.yml +0 -110
- data/spec/fixtures/match_requests_on.yml +0 -187
- data/spec/lib/vcr/cassette/erb_renderer_spec.rb +0 -53
- data/spec/lib/vcr/cassette/http_interaction_list_spec.rb +0 -295
- data/spec/lib/vcr/cassette/migrator_spec.rb +0 -196
- data/spec/lib/vcr/cassette/persisters/file_system_spec.rb +0 -75
- data/spec/lib/vcr/cassette/persisters_spec.rb +0 -39
- data/spec/lib/vcr/cassette/serializers_spec.rb +0 -182
- data/spec/lib/vcr/cassette_spec.rb +0 -618
- data/spec/lib/vcr/configuration_spec.rb +0 -326
- data/spec/lib/vcr/deprecations_spec.rb +0 -85
- data/spec/lib/vcr/errors_spec.rb +0 -178
- data/spec/lib/vcr/extensions/net_http_response_spec.rb +0 -86
- data/spec/lib/vcr/library_hooks/excon_spec.rb +0 -104
- data/spec/lib/vcr/library_hooks/fakeweb_spec.rb +0 -169
- data/spec/lib/vcr/library_hooks/faraday_spec.rb +0 -68
- data/spec/lib/vcr/library_hooks/typhoeus_0.4_spec.rb +0 -36
- data/spec/lib/vcr/library_hooks/typhoeus_spec.rb +0 -162
- data/spec/lib/vcr/library_hooks/webmock_spec.rb +0 -117
- data/spec/lib/vcr/library_hooks_spec.rb +0 -51
- data/spec/lib/vcr/middleware/faraday_spec.rb +0 -181
- data/spec/lib/vcr/middleware/rack_spec.rb +0 -115
- data/spec/lib/vcr/request_ignorer_spec.rb +0 -70
- data/spec/lib/vcr/request_matcher_registry_spec.rb +0 -345
- data/spec/lib/vcr/structs_spec.rb +0 -732
- data/spec/lib/vcr/test_frameworks/cucumber_spec.rb +0 -107
- data/spec/lib/vcr/test_frameworks/rspec_spec.rb +0 -94
- data/spec/lib/vcr/util/hooks_spec.rb +0 -158
- data/spec/lib/vcr/util/internet_connection_spec.rb +0 -37
- data/spec/lib/vcr/util/version_checker_spec.rb +0 -31
- data/spec/lib/vcr/version_spec.rb +0 -27
- data/spec/lib/vcr_spec.rb +0 -354
- data/spec/monkey_patches.rb +0 -186
- data/spec/spec_helper.rb +0 -63
- data/spec/support/configuration_stubbing.rb +0 -8
- data/spec/support/cucumber_helpers.rb +0 -39
- data/spec/support/fixnum_extension.rb +0 -10
- data/spec/support/http_library_adapters.rb +0 -289
- data/spec/support/limited_uri.rb +0 -21
- data/spec/support/ruby_interpreter.rb +0 -7
- data/spec/support/shared_example_groups/excon.rb +0 -63
- data/spec/support/shared_example_groups/hook_into_http_library.rb +0 -594
- data/spec/support/shared_example_groups/request_hooks.rb +0 -59
- data/spec/support/sinatra_app.rb +0 -86
- data/spec/support/vcr_localhost_server.rb +0 -76
- data/spec/support/vcr_stub_helpers.rb +0 -17
@@ -1,115 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'vcr/middleware/rack'
|
3
|
-
|
4
|
-
module VCR
|
5
|
-
module Middleware
|
6
|
-
describe CassetteArguments do
|
7
|
-
describe '#name' do
|
8
|
-
it 'initially returns nil' do
|
9
|
-
expect(subject.name).to be_nil
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'stores the given value, returning it when no arg is given' do
|
13
|
-
subject.name :value1
|
14
|
-
expect(subject.name).to eq(:value1)
|
15
|
-
|
16
|
-
subject.name :value2
|
17
|
-
expect(subject.name).to eq(:value2)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe '#options' do
|
22
|
-
it 'initially returns an empty hash' do
|
23
|
-
expect(subject.options).to eq({})
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'merges the given hash options, returning them when no arg is given' do
|
27
|
-
subject.options :record => :new_episodes
|
28
|
-
expect(subject.options).to eq({ :record => :new_episodes })
|
29
|
-
|
30
|
-
subject.options :erb => true
|
31
|
-
expect(subject.options).to eq({ :record => :new_episodes, :erb => true })
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe Rack do
|
37
|
-
describe '.new' do
|
38
|
-
it 'raises an error if no cassette arguments block is provided' do
|
39
|
-
expect {
|
40
|
-
described_class.new(lambda { |env| })
|
41
|
-
}.to raise_error(ArgumentError)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe '#call' do
|
46
|
-
let(:env_hash) { { :env => :hash } }
|
47
|
-
it 'calls the provided rack app and returns its response' do
|
48
|
-
rack_app = double
|
49
|
-
expect(rack_app).to receive(:call).with(env_hash).and_return(:response)
|
50
|
-
instance = described_class.new(rack_app) { |c| c.name 'cassette_name' }
|
51
|
-
expect(instance.call(env_hash)).to eq(:response)
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'uses a cassette when the rack app is called' do
|
55
|
-
expect(VCR.current_cassette).to be_nil
|
56
|
-
rack_app = lambda { |env| expect(VCR.current_cassette).not_to be_nil }
|
57
|
-
instance = described_class.new(rack_app) { |c| c.name 'cassette_name' }
|
58
|
-
instance.call({})
|
59
|
-
expect(VCR.current_cassette).to be_nil
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'sets the cassette name based on the provided block' do
|
63
|
-
rack_app = lambda do |env|
|
64
|
-
expect(VCR.current_cassette.name).to eq('rack_cassette')
|
65
|
-
end
|
66
|
-
instance = described_class.new(rack_app) { |c| c.name 'rack_cassette' }
|
67
|
-
instance.call({})
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'sets the cassette options based on the provided block' do
|
71
|
-
rack_app = lambda do |env|
|
72
|
-
expect(VCR.current_cassette.erb).to eq({ :foo => :bar })
|
73
|
-
end
|
74
|
-
|
75
|
-
instance = described_class.new(rack_app, &lambda do |c|
|
76
|
-
c.name 'c'
|
77
|
-
c.options :erb => { :foo => :bar }
|
78
|
-
end)
|
79
|
-
|
80
|
-
instance.call({})
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'yields the rack env to the provided block when the block accepts 2 arguments' do
|
84
|
-
instance = described_class.new(lambda { |env| }, &lambda do |c, env|
|
85
|
-
expect(env).to eq(env_hash)
|
86
|
-
c.name 'c'
|
87
|
-
end)
|
88
|
-
|
89
|
-
instance.call(env_hash)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
let(:threaded_app) do
|
94
|
-
lambda do |env|
|
95
|
-
sleep 0.15
|
96
|
-
expect(VCR.send(:cassettes).size).to eq(1)
|
97
|
-
[200, {}, ['OK']]
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'is thread safe' do
|
102
|
-
stack = described_class.new(threaded_app) do |cassette|
|
103
|
-
cassette.name 'c'
|
104
|
-
end
|
105
|
-
|
106
|
-
thread = Thread.new { stack.call({}) }
|
107
|
-
stack.call({})
|
108
|
-
thread.join
|
109
|
-
|
110
|
-
expect(VCR.current_cassette).to be_nil
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'vcr/structs'
|
2
|
-
require 'vcr/request_ignorer'
|
3
|
-
|
4
|
-
module VCR
|
5
|
-
describe RequestIgnorer do
|
6
|
-
def request(uri)
|
7
|
-
VCR::Request.new.tap { |r| r.uri = uri }
|
8
|
-
end
|
9
|
-
|
10
|
-
shared_examples_for "#ignore?" do |url, expected_value|
|
11
|
-
it "returns #{expected_value} if given a request with a url like #{url}" do
|
12
|
-
expect(subject.ignore?(request(url))).to eq(expected_value)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'when example.com and example.net are ignored' do
|
17
|
-
before(:each) { subject.ignore_hosts 'example.com', 'example.net' }
|
18
|
-
|
19
|
-
it_behaves_like "#ignore?", "http://www.example.com/foo", false
|
20
|
-
it_behaves_like "#ignore?", "http://example.com/foo", true
|
21
|
-
it_behaves_like "#ignore?", "http://example.net:890/foo", true
|
22
|
-
it_behaves_like "#ignore?", "http://some-other-domain.com/", false
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'when ignore_localhost is set to true' do
|
26
|
-
before(:each) { subject.ignore_localhost = true }
|
27
|
-
|
28
|
-
it_behaves_like "#ignore?", "http://some-host.com/foo", false
|
29
|
-
RequestIgnorer::LOCALHOST_ALIASES.each do |host|
|
30
|
-
it_behaves_like "#ignore?", "http://#{host}/foo", true
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'when ignore_localhost is not set' do
|
35
|
-
it_behaves_like "#ignore?", "http://some-host.com/foo", false
|
36
|
-
RequestIgnorer::LOCALHOST_ALIASES.each do |host|
|
37
|
-
it_behaves_like "#ignore?", "http://#{host}/foo", false
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context 'when ignore_localhost is set to false after being set to true' do
|
42
|
-
before(:each) do
|
43
|
-
subject.ignore_localhost = true
|
44
|
-
subject.ignore_localhost = false
|
45
|
-
end
|
46
|
-
|
47
|
-
it_behaves_like "#ignore?", "http://some-host.com/foo", false
|
48
|
-
RequestIgnorer::LOCALHOST_ALIASES.each do |host|
|
49
|
-
it_behaves_like "#ignore?", "http://#{host}/foo", false
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'when a custom ignore_request hook has been set' do
|
54
|
-
before(:each) do
|
55
|
-
subject.ignore_request do |request|
|
56
|
-
URI(request.uri).port == 5
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'ignores requests for which the block returns true' do
|
61
|
-
expect(subject.ignore?(request('http://foo.com:5/bar'))).to be true
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'does not ignore requests for which the block returns false' do
|
65
|
-
expect(subject.ignore?(request('http://foo.com:6/bar'))).to be false
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
@@ -1,345 +0,0 @@
|
|
1
|
-
require 'vcr/request_matcher_registry'
|
2
|
-
require 'vcr/structs'
|
3
|
-
require 'support/limited_uri'
|
4
|
-
require 'cgi'
|
5
|
-
require 'support/configuration_stubbing'
|
6
|
-
|
7
|
-
module VCR
|
8
|
-
describe RequestMatcherRegistry do
|
9
|
-
include_context "configuration stubbing"
|
10
|
-
|
11
|
-
before do
|
12
|
-
allow(config).to receive(:uri_parser) { LimitedURI }
|
13
|
-
allow(config).to receive(:query_parser) { CGI.method(:parse) }
|
14
|
-
end
|
15
|
-
|
16
|
-
def request_with(values)
|
17
|
-
VCR::Request.new.tap do |request|
|
18
|
-
values.each do |name, value|
|
19
|
-
request.send("#{name}=", value)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "#register" do
|
25
|
-
it 'registers a request matcher block that can be used later' do
|
26
|
-
matcher_called = false
|
27
|
-
subject.register(:my_matcher) { |*a| matcher_called = true }
|
28
|
-
subject[:my_matcher].matches?(double, double)
|
29
|
-
expect(matcher_called).to be true
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'when there is already a matcher for the given name' do
|
33
|
-
before(:each) do
|
34
|
-
subject.register(:foo) { |*a| false }
|
35
|
-
allow(subject).to receive :warn
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'overrides the existing matcher' do
|
39
|
-
subject.register(:foo) { |*a| true }
|
40
|
-
expect(subject[:foo].matches?(double, double)).to be true
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'warns that there is a name collision' do
|
44
|
-
expect(subject).to receive(:warn).with(
|
45
|
-
/WARNING: There is already a VCR request matcher registered for :foo\. Overriding it/
|
46
|
-
)
|
47
|
-
|
48
|
-
subject.register(:foo) { |*a| true }
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "#[]" do
|
54
|
-
it 'returns a previously registered matcher' do
|
55
|
-
matcher = lambda { }
|
56
|
-
subject.register(:my_matcher, &matcher)
|
57
|
-
expect(subject[:my_matcher]).to eq(RequestMatcherRegistry::Matcher.new(matcher))
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'raises an ArgumentError when no matcher has been registered for the given name' do
|
61
|
-
expect {
|
62
|
-
subject[:some_unregistered_matcher]
|
63
|
-
}.to raise_error(VCR::Errors::UnregisteredMatcherError)
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'returns an object that calls the named block when #matches? is called on it' do
|
67
|
-
subject.register(:foo) { |r1, r2| r1 == 5 || r2 == 10 }
|
68
|
-
expect(subject[:foo].matches?(5, 0)).to be true
|
69
|
-
expect(subject[:foo].matches?(0, 10)).to be true
|
70
|
-
expect(subject[:foo].matches?(7, 7)).to be false
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'returns an object that calls the given callable when #matches? is called on it' do
|
74
|
-
block_called = false
|
75
|
-
subject[lambda { |r1, r2| block_called = true }].matches?(5, 0)
|
76
|
-
expect(block_called).to be true
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
[:uri_without_param, :uri_without_params].each do |meth|
|
81
|
-
describe "##{meth}" do
|
82
|
-
it 'returns a matcher that can be registered for later use' do
|
83
|
-
matcher = subject.send(meth, :foo)
|
84
|
-
subject.register(:uri_without_foo, &matcher)
|
85
|
-
matches = subject[:uri_without_foo].matches?(
|
86
|
-
request_with(:uri => 'http://example.com/search?foo=123'),
|
87
|
-
request_with(:uri => 'http://example.com/search?foo=123')
|
88
|
-
)
|
89
|
-
expect(matches).to be true
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'matches two requests with URIs that are identical' do
|
93
|
-
matches = subject[subject.send(meth, :foo)].matches?(
|
94
|
-
request_with(:uri => 'http://example.com/search?foo=123'),
|
95
|
-
request_with(:uri => 'http://example.com/search?foo=123')
|
96
|
-
)
|
97
|
-
expect(matches).to be true
|
98
|
-
end
|
99
|
-
|
100
|
-
it 'does not match two requests with different path parts' do
|
101
|
-
matches = subject[subject.send(meth, :foo)].matches?(
|
102
|
-
request_with(:uri => 'http://example.com/search?foo=123'),
|
103
|
-
request_with(:uri => 'http://example.com/find?foo=123')
|
104
|
-
)
|
105
|
-
expect(matches).to be false
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'ignores the given query parameters when it is at the start' do
|
109
|
-
matches = subject[subject.send(meth, :foo)].matches?(
|
110
|
-
request_with(:uri => 'http://example.com/search?foo=123&bar=r'),
|
111
|
-
request_with(:uri => 'http://example.com/search?foo=124&bar=r')
|
112
|
-
)
|
113
|
-
expect(matches).to be true
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'ignores the given query parameters when it is at the end' do
|
117
|
-
matches = subject[subject.send(meth, :bar)].matches?(
|
118
|
-
request_with(:uri => 'http://example.com/search?foo=124&bar=r'),
|
119
|
-
request_with(:uri => 'http://example.com/search?foo=124&bar=q')
|
120
|
-
)
|
121
|
-
expect(matches).to be true
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'still takes into account other query params' do
|
125
|
-
matches = subject[subject.send(meth, :bar)].matches?(
|
126
|
-
request_with(:uri => 'http://example.com/search?foo=123&bar=r'),
|
127
|
-
request_with(:uri => 'http://example.com/search?foo=124&bar=q')
|
128
|
-
)
|
129
|
-
expect(matches).to be false
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'handles multiple query params of the same name' do
|
133
|
-
matches = subject[subject.send(meth, :tag)].matches?(
|
134
|
-
request_with(:uri => 'http://example.com/search?foo=124&tag[]=a&tag[]=b'),
|
135
|
-
request_with(:uri => 'http://example.com/search?foo=124&tag[]=d&tag[]=e')
|
136
|
-
)
|
137
|
-
expect(matches).to be true
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'can ignore multiple named parameters' do
|
141
|
-
matches = subject[subject.send(meth, :foo, :bar)].matches?(
|
142
|
-
request_with(:uri => 'http://example.com/search?foo=123&bar=r&baz=9'),
|
143
|
-
request_with(:uri => 'http://example.com/search?foo=124&baz=9&bar=q')
|
144
|
-
)
|
145
|
-
expect(matches).to be true
|
146
|
-
end
|
147
|
-
|
148
|
-
it 'matches two requests with URIs that have no params' do
|
149
|
-
matches = subject[subject.send(meth, :foo, :bar)].matches?(
|
150
|
-
request_with(:uri => 'http://example.com/search'),
|
151
|
-
request_with(:uri => 'http://example.com/search')
|
152
|
-
)
|
153
|
-
expect(matches).to be true
|
154
|
-
end
|
155
|
-
|
156
|
-
it 'does not match two requests with URIs that have no params but different paths' do
|
157
|
-
matches = subject[subject.send(meth, :foo, :bar)].matches?(
|
158
|
-
request_with(:uri => 'http://example.com/foo'),
|
159
|
-
request_with(:uri => 'http://example.com/bar')
|
160
|
-
)
|
161
|
-
expect(matches).to be false
|
162
|
-
end
|
163
|
-
|
164
|
-
it 'matches a second request when all parameters are filtered' do
|
165
|
-
matches = subject[subject.send(meth, :q, :oq)].matches?(
|
166
|
-
request_with(:uri => 'http://example.com/search'),
|
167
|
-
request_with(:uri => 'http://example.com/search?q=vcr&oq=vcr')
|
168
|
-
)
|
169
|
-
expect(matches).to be true
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
describe "built-ins" do
|
175
|
-
describe ":method" do
|
176
|
-
it 'matches when it is the same' do
|
177
|
-
matches = subject[:method].matches?(
|
178
|
-
request_with(:method => :get),
|
179
|
-
request_with(:method => :get)
|
180
|
-
)
|
181
|
-
expect(matches).to be true
|
182
|
-
end
|
183
|
-
|
184
|
-
it 'does not match when it is not the same' do
|
185
|
-
matches = subject[:method].matches?(
|
186
|
-
request_with(:method => :get),
|
187
|
-
request_with(:method => :post)
|
188
|
-
)
|
189
|
-
expect(matches).to be false
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
describe ":uri" do
|
194
|
-
it 'matches when it is exactly the same' do
|
195
|
-
matches = subject[:uri].matches?(
|
196
|
-
request_with(:uri => 'http://foo.com/bar?baz=7'),
|
197
|
-
request_with(:uri => 'http://foo.com/bar?baz=7')
|
198
|
-
)
|
199
|
-
expect(matches).to be true
|
200
|
-
end
|
201
|
-
|
202
|
-
it 'does not match when it is different' do
|
203
|
-
matches = subject[:uri].matches?(
|
204
|
-
request_with(:uri => 'http://foo1.com/bar?baz=7'),
|
205
|
-
request_with(:uri => 'http://foo2.com/bar?baz=7')
|
206
|
-
)
|
207
|
-
expect(matches).to be false
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
describe ":host" do
|
212
|
-
it 'matches when it is the same' do
|
213
|
-
matches = subject[:host].matches?(
|
214
|
-
request_with(:uri => 'http://foo.com/bar'),
|
215
|
-
request_with(:uri => 'http://foo.com/car')
|
216
|
-
)
|
217
|
-
expect(matches).to be true
|
218
|
-
end
|
219
|
-
|
220
|
-
it 'does not match when it is not the same' do
|
221
|
-
matches = subject[:host].matches?(
|
222
|
-
request_with(:uri => 'http://foo.com/bar'),
|
223
|
-
request_with(:uri => 'http://goo.com/bar')
|
224
|
-
)
|
225
|
-
expect(matches).to be false
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
describe ":path" do
|
230
|
-
it 'matches when it is the same' do
|
231
|
-
matches = subject[:path].matches?(
|
232
|
-
request_with(:uri => 'http://foo.com/bar?a=8'),
|
233
|
-
request_with(:uri => 'http://goo.com/bar?a=9')
|
234
|
-
)
|
235
|
-
expect(matches).to be true
|
236
|
-
end
|
237
|
-
|
238
|
-
it 'does not match when it is not the same' do
|
239
|
-
matches = subject[:path].matches?(
|
240
|
-
request_with(:uri => 'http://foo.com/bar?a=8'),
|
241
|
-
request_with(:uri => 'http://foo.com/car?a=8')
|
242
|
-
)
|
243
|
-
expect(matches).to be false
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
describe ":body" do
|
248
|
-
it 'matches when it is the same' do
|
249
|
-
matches = subject[:body].matches?(
|
250
|
-
request_with(:body => 'foo'),
|
251
|
-
request_with(:body => 'foo')
|
252
|
-
)
|
253
|
-
expect(matches).to be true
|
254
|
-
end
|
255
|
-
|
256
|
-
it 'does not match when it is not the same' do
|
257
|
-
matches = subject[:body].matches?(
|
258
|
-
request_with(:body => 'foo'),
|
259
|
-
request_with(:body => 'bar')
|
260
|
-
)
|
261
|
-
expect(matches).to be false
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
describe ":body_as_json" do
|
266
|
-
it 'matches when the body json is reordered' do
|
267
|
-
matches = subject[:body_as_json].matches?(
|
268
|
-
request_with(:body => '{ "a": "1", "b": "2" }'),
|
269
|
-
request_with(:body => '{ "b": "2", "a": "1" }')
|
270
|
-
)
|
271
|
-
expect(matches).to be true
|
272
|
-
end
|
273
|
-
|
274
|
-
it 'does not match when json is not the same' do
|
275
|
-
matches = subject[:body_as_json].matches?(
|
276
|
-
request_with(:body => '{ "a": "1", "b": "2" }'),
|
277
|
-
request_with(:body => '{ "a": "1", "b": "1" }')
|
278
|
-
)
|
279
|
-
expect(matches).to be false
|
280
|
-
end
|
281
|
-
|
282
|
-
it 'does not match when body is not json' do
|
283
|
-
matches = subject[:body_as_json].matches?(
|
284
|
-
request_with(:body => 'a=b'),
|
285
|
-
request_with(:body => 'a=b')
|
286
|
-
)
|
287
|
-
expect(matches).to be false
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
describe ":headers" do
|
292
|
-
it 'matches when it is the same' do
|
293
|
-
matches = subject[:headers].matches?(
|
294
|
-
request_with(:headers => { 'a' => 1, 'b' => 2 }),
|
295
|
-
request_with(:headers => { 'b' => 2, 'a' => 1 })
|
296
|
-
)
|
297
|
-
expect(matches).to be true
|
298
|
-
end
|
299
|
-
|
300
|
-
it 'does not match when it is not the same' do
|
301
|
-
matches = subject[:headers].matches?(
|
302
|
-
request_with(:headers => { 'a' => 3, 'b' => 2 }),
|
303
|
-
request_with(:headers => { 'b' => 2, 'a' => 1 })
|
304
|
-
)
|
305
|
-
expect(matches).to be false
|
306
|
-
end
|
307
|
-
end
|
308
|
-
|
309
|
-
describe ":query" do
|
310
|
-
it 'matches when it is identical' do
|
311
|
-
matches = subject[:query].matches?(
|
312
|
-
request_with(:uri => 'http://foo.com/bar?a=8'),
|
313
|
-
request_with(:uri => 'http://goo.com/car?a=8')
|
314
|
-
)
|
315
|
-
expect(matches).to be true
|
316
|
-
end
|
317
|
-
|
318
|
-
it 'matches when empty' do
|
319
|
-
matches = subject[:query].matches?(
|
320
|
-
request_with(:uri => 'http://foo.com/bar'),
|
321
|
-
request_with(:uri => 'http://goo.com/car')
|
322
|
-
)
|
323
|
-
expect(matches).to be true
|
324
|
-
end
|
325
|
-
|
326
|
-
it 'matches when parameters are reordered' do
|
327
|
-
matches = subject[:query].matches?(
|
328
|
-
request_with(:uri => 'http://foo.com/bar?a=8&b=9'),
|
329
|
-
request_with(:uri => 'http://goo.com/car?b=9&a=8')
|
330
|
-
)
|
331
|
-
expect(matches).to be true
|
332
|
-
end
|
333
|
-
|
334
|
-
it 'does not match when it is not the same' do
|
335
|
-
matches = subject[:query].matches?(
|
336
|
-
request_with(:uri => 'http://foo.com/bar?a=8'),
|
337
|
-
request_with(:uri => 'http://goo.com/car?b=8')
|
338
|
-
)
|
339
|
-
expect(matches).to be false
|
340
|
-
end
|
341
|
-
end
|
342
|
-
end
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|