vcr 1.11.3 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.travis.yml +6 -2
- data/CHANGELOG.md +49 -1
- data/Gemfile +1 -5
- data/Guardfile +0 -5
- data/README.md +3 -2
- data/Rakefile +11 -16
- data/cucumber.yml +0 -4
- data/features/.nav +14 -2
- data/features/cassettes/automatic_re_recording.feature +4 -6
- data/features/cassettes/dynamic_erb.feature +6 -8
- data/features/cassettes/exclusive.feature +111 -0
- data/features/cassettes/format.feature +16 -14
- data/features/cassettes/naming.feature +4 -6
- data/features/cassettes/no_cassette.feature +25 -28
- data/features/cassettes/update_content_length_header.feature +9 -9
- data/features/configuration/allow_http_connections_when_no_cassette.feature +6 -8
- data/features/configuration/cassette_library_dir.feature +4 -6
- data/features/configuration/default_cassette_options.feature +12 -10
- data/features/configuration/filter_sensitive_data.feature +12 -17
- data/features/configuration/{stub_with.feature → hook_into.feature} +63 -62
- data/features/configuration/hooks.feature +23 -33
- data/features/configuration/ignore_hosts.feature +16 -17
- data/features/configuration/ignore_localhost.feature +33 -42
- data/features/http_libraries/em_http_request.feature +7 -8
- data/features/http_libraries/net_http.feature +26 -28
- data/features/middleware/faraday.feature +17 -56
- data/features/middleware/rack.feature +8 -11
- data/features/record_modes/all.feature +5 -7
- data/features/record_modes/new_episodes.feature +5 -7
- data/features/record_modes/none.feature +6 -6
- data/features/record_modes/once.feature +6 -8
- data/features/request_matching/README.md +28 -0
- data/features/request_matching/body.feature +81 -0
- data/features/request_matching/custom_matcher.feature +125 -0
- data/features/request_matching/headers.feature +85 -0
- data/features/request_matching/host.feature +85 -0
- data/features/request_matching/identical_request_sequence.feature +79 -0
- data/features/request_matching/method.feature +86 -0
- data/features/request_matching/path.feature +86 -0
- data/features/request_matching/playback_repeats.feature +87 -0
- data/features/request_matching/uri.feature +84 -0
- data/features/request_matching/uri_without_param.feature +85 -0
- data/features/step_definitions/cli_steps.rb +4 -28
- data/features/support/env.rb +11 -9
- data/features/support/http_lib_filters.rb +2 -11
- data/features/support/vcr_cucumber_helpers.rb +4 -5
- data/features/test_frameworks/cucumber.feature +17 -18
- data/features/test_frameworks/rspec.feature +8 -12
- data/features/test_frameworks/shoulda.feature +5 -8
- data/features/test_frameworks/test_unit.feature +5 -8
- data/lib/vcr.rb +38 -58
- data/lib/vcr/cassette.rb +41 -60
- data/lib/vcr/cassette/http_interaction_list.rb +56 -0
- data/lib/vcr/cassette/reader.rb +29 -31
- data/lib/vcr/configuration.rb +76 -0
- data/lib/vcr/deprecations.rb +39 -0
- data/lib/vcr/errors.rb +22 -0
- data/lib/vcr/library_hooks.rb +19 -0
- data/lib/vcr/library_hooks/excon.rb +136 -0
- data/lib/vcr/library_hooks/fakeweb.rb +110 -0
- data/lib/vcr/library_hooks/faraday.rb +3 -0
- data/lib/vcr/library_hooks/typhoeus.rb +98 -0
- data/lib/vcr/library_hooks/webmock.rb +100 -0
- data/lib/vcr/middleware/faraday.rb +43 -36
- data/lib/vcr/middleware/rack.rb +28 -4
- data/lib/vcr/request_handler.rb +43 -0
- data/lib/vcr/request_ignorer.rb +31 -0
- data/lib/vcr/request_matcher_registry.rb +86 -0
- data/lib/vcr/structs/http_interaction.rb +24 -18
- data/lib/vcr/structs/normalizers/body.rb +1 -1
- data/lib/vcr/structs/normalizers/header.rb +1 -1
- data/lib/vcr/structs/normalizers/status_message.rb +1 -1
- data/lib/vcr/structs/normalizers/uri.rb +1 -1
- data/lib/vcr/structs/request.rb +0 -13
- data/lib/vcr/structs/response.rb +2 -9
- data/lib/vcr/structs/response_status.rb +0 -4
- data/lib/vcr/test_frameworks/cucumber.rb +1 -1
- data/lib/vcr/test_frameworks/rspec.rb +1 -1
- data/lib/vcr/util/hooks.rb +28 -19
- data/lib/vcr/util/internet_connection.rb +29 -2
- data/lib/vcr/util/version_checker.rb +60 -0
- data/lib/vcr/version.rb +1 -1
- data/script/FullBuildRakeFile +0 -7
- data/script/full_build +1 -1
- data/spec/capture_warnings.rb +36 -31
- data/spec/fixtures/{1.9.1/cassette_spec → cassette_spec}/empty.yml +0 -0
- data/spec/fixtures/{not_1.9.1/cassette_spec → cassette_spec}/example.yml +0 -0
- data/spec/fixtures/{not_1.9.1/cassette_spec → cassette_spec}/with_localhost_requests.yml +0 -0
- data/spec/fixtures/{not_1.9.1/fake_example.com_responses.yml → fake_example.com_responses.yml} +0 -0
- data/spec/fixtures/{not_1.9.1/match_requests_on.yml → match_requests_on.yml} +0 -0
- data/spec/monkey_patches.rb +40 -11
- data/spec/spec_helper.rb +7 -43
- data/spec/support/http_library_adapters.rb +3 -13
- data/spec/support/shared_example_groups/{http_library.rb → hook_into_http_library.rb} +39 -111
- data/spec/support/shared_example_groups/version_checking.rb +9 -9
- data/spec/vcr/cassette/http_interaction_list_spec.rb +178 -0
- data/spec/vcr/cassette/reader_spec.rb +2 -2
- data/spec/vcr/cassette_spec.rb +121 -156
- data/spec/vcr/configuration_spec.rb +143 -0
- data/spec/vcr/deprecations_spec.rb +91 -0
- data/spec/vcr/{http_stubbing_adapters → library_hooks}/excon_spec.rb +6 -9
- data/spec/vcr/library_hooks/fakeweb_spec.rb +83 -0
- data/spec/vcr/{http_stubbing_adapters → library_hooks}/typhoeus_spec.rb +7 -11
- data/spec/vcr/library_hooks/webmock_spec.rb +17 -0
- data/spec/vcr/library_hooks_spec.rb +51 -0
- data/spec/vcr/middleware/faraday_spec.rb +17 -44
- data/spec/vcr/middleware/rack_spec.rb +94 -58
- data/spec/vcr/request_ignorer_spec.rb +54 -0
- data/spec/vcr/request_matcher_registry_spec.rb +223 -0
- data/spec/vcr/structs/request_spec.rb +0 -33
- data/spec/vcr/structs/response_spec.rb +0 -24
- data/spec/vcr/structs/response_status_spec.rb +0 -9
- data/spec/vcr/util/hooks_spec.rb +3 -5
- data/spec/vcr/version_spec.rb +1 -1
- data/spec/vcr_spec.rb +79 -91
- data/vcr.gemspec +1 -1
- metadata +83 -103
- data/features/cassettes/request_matching.feature +0 -383
- data/lib/vcr/config.rb +0 -84
- data/lib/vcr/deprecations/cassette.rb +0 -29
- data/lib/vcr/deprecations/config.rb +0 -18
- data/lib/vcr/deprecations/http_stubbing_adapters/common.rb +0 -9
- data/lib/vcr/deprecations/http_stubbing_adapters/fakeweb.rb +0 -11
- data/lib/vcr/extensions/net_http.rb +0 -32
- data/lib/vcr/http_stubbing_adapters/common.rb +0 -202
- data/lib/vcr/http_stubbing_adapters/excon.rb +0 -178
- data/lib/vcr/http_stubbing_adapters/fakeweb.rb +0 -107
- data/lib/vcr/http_stubbing_adapters/faraday.rb +0 -26
- data/lib/vcr/http_stubbing_adapters/multi_object_proxy.rb +0 -43
- data/lib/vcr/http_stubbing_adapters/typhoeus.rb +0 -115
- data/lib/vcr/http_stubbing_adapters/webmock.rb +0 -120
- data/lib/vcr/middleware/cassette_arguments.rb +0 -19
- data/lib/vcr/middleware/common.rb +0 -20
- data/lib/vcr/request_matcher.rb +0 -94
- data/lib/vcr/rspec.rb +0 -2
- data/lib/vcr/util/basic_object.rb +0 -43
- data/lib/vcr/util/ping.rb +0 -30
- data/lib/vcr/util/regexes.rb +0 -37
- data/spec/fixtures/1.9.1/0_3_1_cassette.yml +0 -29
- data/spec/fixtures/1.9.1/cassette_spec/example.yml +0 -110
- data/spec/fixtures/1.9.1/cassette_spec/with_localhost_requests.yml +0 -109
- data/spec/fixtures/1.9.1/example_net_http.yml +0 -14
- data/spec/fixtures/1.9.1/example_net_http_request.yml +0 -12
- data/spec/fixtures/1.9.1/example_net_http_response.yml +0 -25
- data/spec/fixtures/1.9.1/fake_example.com_responses.yml +0 -108
- data/spec/fixtures/1.9.1/match_requests_on.yml +0 -185
- data/spec/fixtures/not_1.9.1/0_3_1_cassette.yml +0 -29
- data/spec/fixtures/not_1.9.1/cassette_spec/empty.yml +0 -0
- data/spec/fixtures/not_1.9.1/example_net_http.yml +0 -14
- data/spec/fixtures/not_1.9.1/example_net_http_request.yml +0 -12
- data/spec/fixtures/not_1.9.1/example_net_http_response.yml +0 -25
- data/spec/support/shared_example_groups/http_stubbing_adapter.rb +0 -133
- data/spec/support/shared_example_groups/ignore_localhost_deprecation.rb +0 -28
- data/spec/vcr/config_spec.rb +0 -181
- data/spec/vcr/deprecations/cassette_spec.rb +0 -57
- data/spec/vcr/deprecations/config_spec.rb +0 -30
- data/spec/vcr/deprecations/http_stubbing_adapters/common_spec.rb +0 -7
- data/spec/vcr/deprecations/http_stubbing_adapters/fakeweb_spec.rb +0 -16
- data/spec/vcr/extensions/net_http_spec.rb +0 -80
- data/spec/vcr/http_stubbing_adapters/fakeweb_spec.rb +0 -19
- data/spec/vcr/http_stubbing_adapters/faraday_spec.rb +0 -76
- data/spec/vcr/http_stubbing_adapters/multi_object_proxy_spec.rb +0 -101
- data/spec/vcr/http_stubbing_adapters/webmock_spec.rb +0 -17
- data/spec/vcr/middleware/cassette_arguments_spec.rb +0 -32
- data/spec/vcr/request_matcher_spec.rb +0 -230
@@ -1,101 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module VCR
|
4
|
-
module HttpStubbingAdapters
|
5
|
-
describe MultiObjectProxy do
|
6
|
-
let(:mock1) { mock }
|
7
|
-
let(:mock2) { mock }
|
8
|
-
subject { described_class.new(mock1, mock2) }
|
9
|
-
|
10
|
-
it 'raises an error when it is created with no objects' do
|
11
|
-
expect { described_class.new }.to raise_error(ArgumentError)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'raises an error when one of the objects is nil' do
|
15
|
-
expect { described_class.new(Object.new, nil) }.to raise_error(ArgumentError)
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'is a basic object with very few of its own methods' do
|
19
|
-
inst_methods = described_class.instance_methods.map { |m| m.to_sym }
|
20
|
-
inst_methods.should_not include(:send, :object_id)
|
21
|
-
end
|
22
|
-
|
23
|
-
describe '#proxied_objects' do
|
24
|
-
it 'returns the proxied objects' do
|
25
|
-
subject.proxied_objects.should eq([mock1, mock2])
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe '#respond_to?' do
|
30
|
-
it 'responds to any method that any of the objects responds to' do
|
31
|
-
mock1.stub(:respond_to?).with(:foo).and_return(true)
|
32
|
-
mock1.stub(:respond_to?).with(:bar).and_return(false)
|
33
|
-
mock2.stub(:respond_to?).with(:bar).and_return(true)
|
34
|
-
mock2.stub(:respond_to?).with(:foo).and_return(false)
|
35
|
-
|
36
|
-
subject.respond_to?(:foo).should be_true
|
37
|
-
subject.respond_to?(:bar).should be_true
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'does not respond to a method that none of the objects respond to' do
|
41
|
-
subject.respond_to?(:bazz).should be_false
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe 'calling a method' do
|
46
|
-
it 'raises a no method error when none of the objects responds to the method' do
|
47
|
-
expect { subject.some_undefined_method }.to raise_error(NoMethodError)
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'properly proxies messages to a single object when only one object responds to the message' do
|
51
|
-
mock1.should_not respond_to(:request_stubbed?)
|
52
|
-
mock2.should_receive(:request_stubbed?).and_return(true)
|
53
|
-
|
54
|
-
subject.request_stubbed?.should eq(true)
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'proxies messages to each object' do
|
58
|
-
mock1.should_receive(:stub_requests).with(:arg1, :arg2)
|
59
|
-
mock2.should_receive(:stub_requests).with(:arg1, :arg2)
|
60
|
-
|
61
|
-
subject.stub_requests(:arg1, :arg2)
|
62
|
-
end
|
63
|
-
|
64
|
-
[:http_connections_allowed?, :request_uri].each do |method|
|
65
|
-
context "for ##{method}" do
|
66
|
-
it 'raises an error if the the objects return different values' do
|
67
|
-
mock1.should_receive(method).and_return(:return_value_1)
|
68
|
-
mock2.should_receive(method).and_return(:return_value_2)
|
69
|
-
|
70
|
-
expect { subject.__send__(method) }.to raise_error(/proxied objects returned different values/)
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'returns the value returned by both objects when they return the same value' do
|
74
|
-
mock1.should_receive(method).and_return(:return_value_1)
|
75
|
-
mock2.should_receive(method).and_return(:return_value_1)
|
76
|
-
|
77
|
-
subject.__send__(method).should eq(:return_value_1)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context 'for a non-predicate method' do
|
83
|
-
it 'does not raise an error when the objects have different return values' do
|
84
|
-
mock1.should_receive(:stub_requests).and_return(:val1)
|
85
|
-
mock2.should_receive(:stub_requests).and_return(:val2)
|
86
|
-
|
87
|
-
subject.stub_requests
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'returns nil regardless of the return values of the objects' do
|
91
|
-
mock1.should_receive(:stub_requests).and_return(:val1)
|
92
|
-
mock2.should_receive(:stub_requests).and_return(:val1)
|
93
|
-
|
94
|
-
subject.stub_requests.should be_nil
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe VCR::HttpStubbingAdapters::WebMock, :with_monkey_patches => :webmock do
|
4
|
-
it_behaves_like 'an http stubbing adapter',
|
5
|
-
%w[net/http patron httpclient em-http-request curb],
|
6
|
-
[:method, :uri, :host, :path, :body, :headers]
|
7
|
-
|
8
|
-
it_performs('version checking',
|
9
|
-
:valid => %w[ 1.7.0 1.7.99 ],
|
10
|
-
:too_low => %w[ 0.9.9 0.9.10 0.1.30 1.0.30 1.6.9 ],
|
11
|
-
:too_high => %w[ 1.8.0 1.10.0 2.0.0 ]
|
12
|
-
) do
|
13
|
-
def stub_version(version)
|
14
|
-
WebMock.stub(:version).and_return(version)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe VCR::Middleware::CassetteArguments do
|
4
|
-
describe '#name' do
|
5
|
-
it 'initially returns nil' do
|
6
|
-
subject.name.should be_nil
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'stores the given value, returning it when no arg is given' do
|
10
|
-
subject.name :value1
|
11
|
-
subject.name.should eq(:value1)
|
12
|
-
|
13
|
-
subject.name :value2
|
14
|
-
subject.name.should eq(:value2)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '#options' do
|
19
|
-
it 'initially returns an empty hash' do
|
20
|
-
subject.options.should eq({})
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'merges the given hash options, returning them when no arg is given' do
|
24
|
-
subject.options :record => :new_episodes
|
25
|
-
subject.options.should eq({ :record => :new_episodes })
|
26
|
-
|
27
|
-
subject.options :erb => true
|
28
|
-
subject.options.should eq({ :record => :new_episodes, :erb => true })
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
@@ -1,230 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe VCR::RequestMatcher do
|
4
|
-
it 'raises an error when given invalid match attributes' do
|
5
|
-
expect {
|
6
|
-
VCR::RequestMatcher.new(VCR::Request.new, [:not, :valid, :options])
|
7
|
-
}.to raise_error(ArgumentError)
|
8
|
-
end
|
9
|
-
|
10
|
-
describe '#uri' do
|
11
|
-
def self.for_matcher(*attributes, &block)
|
12
|
-
context "for match_attributes = #{attributes.inspect}" do
|
13
|
-
subject { VCR::RequestMatcher.new(stub(:uri => uri), attributes).uri }
|
14
|
-
module_eval(&block)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
let(:uri) { 'http://foo.example.com/path/to/something?param=value' }
|
19
|
-
|
20
|
-
for_matcher do
|
21
|
-
it("returns a regex that matches any URI") { should eq(/.*/) }
|
22
|
-
end
|
23
|
-
|
24
|
-
for_matcher :uri do
|
25
|
-
it("returns the exact uri") { should eq(uri) }
|
26
|
-
end
|
27
|
-
|
28
|
-
for_matcher :host do
|
29
|
-
it("matches a basic URL for the same host") { should =~ 'http://foo.example.com/some/path' }
|
30
|
-
it("matches an https URL") { should =~ 'https://foo.example.com/some/path' }
|
31
|
-
it("ignores the case of the URL") { should =~ 'HTTP://FOO.EXAMPLE.COM/SOME/PATH' }
|
32
|
-
it("matches when the URL has the normal port") { should =~ 'http://foo.example.com:80/some/path' }
|
33
|
-
it("matches when the URL has another port") { should =~ 'http://foo.example.com:3750/some/path' }
|
34
|
-
it("matches when the URL has a username") { should =~ 'http://someone@foo.example.com/some/path' }
|
35
|
-
it("matches when the URL has a username and password") { should =~ 'http://admin:s3cr3t@foo.example.com/some/path' }
|
36
|
-
|
37
|
-
it("does not match when the host is wrong") { should_not =~ 'http://fof.example.com/path/to/something?param=value' }
|
38
|
-
it("does not match when the host includes some additional parts") { should_not =~ 'http://foo.example.com.more.domain.parts/path/to/something?param=value' }
|
39
|
-
end
|
40
|
-
|
41
|
-
for_matcher :path do
|
42
|
-
it("matches a basic URL for the same path") { should =~ 'http://domain.tld/path/to/something?p=v&q=r' }
|
43
|
-
it("matches an https URL") { should =~ 'https://domain.tld/path/to/something?p=v&q=r' }
|
44
|
-
it("ignores the case of the URL") { should =~ 'HTTP://DOMAIN.TLD/PATH/TO/SOMETHING?P=V&Q=R' }
|
45
|
-
it("matches with a trailing slash") { should =~ 'http://domain.tld/path/to/something/' }
|
46
|
-
it("matches without a trailing slash") { should =~ 'http://domain.tld/path/to/something' }
|
47
|
-
it("matches when the URL has the normal port") { should =~ 'http://domain.tld:80/path/to/something' }
|
48
|
-
it("matches when the URL has another port") { should =~ 'http://domain.tld:3750/path/to/something' }
|
49
|
-
it("matches when the URL has a username") { should =~ 'http://someone@domain.tld/path/to/something' }
|
50
|
-
it("matches when the URL has a username and password") { should =~ 'http://admin:s3cr3t@domain.tld/path/to/something' }
|
51
|
-
|
52
|
-
it("does not match when the path is wrong") { should_not =~ 'http://foo.example.com/some/other/path?param=value' }
|
53
|
-
it("does not match when the path includes some additional parts") { should_not =~ 'http://foo.example.com/path/to/something/else?param=value' }
|
54
|
-
end
|
55
|
-
|
56
|
-
for_matcher :host, :path do
|
57
|
-
it("matches a basic URL for the same host and path") { should =~ 'http://foo.example.com/path/to/something?p=v' }
|
58
|
-
it("matches an https URL") { should =~ 'https://foo.example.com/path/to/something?p=v&q=r' }
|
59
|
-
it("ignores the case of the URL") { should =~ 'HTTP://FOO.EXAMPLE.COM/PATH/TO/SOMETHING?P=V&Q=R' }
|
60
|
-
it("matches with a trailing slash and some query params") { should =~ 'http://foo.example.com/path/to/something/?p=v&q=r' }
|
61
|
-
it("matches with a trailing slash and no query params") { should =~ 'http://foo.example.com/path/to/something/' }
|
62
|
-
it("matches without a trailing slash and some query params") { should =~ 'http://foo.example.com/path/to/something?p=v&q=r' }
|
63
|
-
it("matches without a trailing slash and no query params") { should =~ 'http://foo.example.com/path/to/something' }
|
64
|
-
it("matches when the URL has the normal port") { should =~ 'http://foo.example.com:80/path/to/something?p=v' }
|
65
|
-
it("matches when the URL has another port") { should =~ 'http://foo.example.com:3750/path/to/something?p=v' }
|
66
|
-
it("matches when the URL has a username") { should =~ 'http://someone@foo.example.com/path/to/something?p=v' }
|
67
|
-
it("matches when the URL has a username and password") { should =~ 'http://admin:s3r3t@foo.example.com/path/to/something?p=v' }
|
68
|
-
|
69
|
-
it("does not match when the host is wrong") { should_not =~ 'http://fof.example.com/path/to/something?p=v' }
|
70
|
-
it("does not match when the path is wrong") { should_not =~ 'http://foo.example.com/pth/to/something?p=v' }
|
71
|
-
it("does not match when the host includes some additional parts") { should_not =~ 'http://foo.example.com.and.more.parts/path/to/something?p=v' }
|
72
|
-
it("does not match when the path includes some additional parts") { should_not =~ 'http://foo.example.com/path/to/something/else?p=v' }
|
73
|
-
end
|
74
|
-
|
75
|
-
[[:uri, :host], [:uri, :path], [:uri, :host, :path]].each do |attributes|
|
76
|
-
for_matcher(*attributes) do
|
77
|
-
it "raises an appropriate error" do
|
78
|
-
expect { subject }.to raise_error(/match_attributes cannot include/)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
it "returns the request's URI when it is a regex, regardless of the match attributes" do
|
84
|
-
[:uri, :host, :path].each do |attribute|
|
85
|
-
matcher = VCR::RequestMatcher.new(stub(:uri => /some regex/), [attribute])
|
86
|
-
matcher.uri.should eq(/some regex/)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe '#method' do
|
92
|
-
it 'returns the request method when the match attributes include :method' do
|
93
|
-
matcher = VCR::RequestMatcher.new(stub(:method => :get), [:method])
|
94
|
-
matcher.method.should eq(:get)
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'returns nil when the match attributes do not include :method' do
|
98
|
-
matcher = VCR::RequestMatcher.new(stub(:method => :get), [])
|
99
|
-
matcher.method.should be_nil
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
describe '#body' do
|
104
|
-
it 'returns the request body when the match attributes include :body' do
|
105
|
-
matcher = VCR::RequestMatcher.new(stub(:body => 'id=7'), [:body])
|
106
|
-
matcher.body.should eq('id=7')
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'returns nil when the match attributes do not include :body' do
|
110
|
-
matcher = VCR::RequestMatcher.new(stub(:body => 'id=7'), [])
|
111
|
-
matcher.method.should be_nil
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
describe '#headers' do
|
116
|
-
it 'returns the request headers when the match attributes include :headers' do
|
117
|
-
matcher = VCR::RequestMatcher.new(stub(:headers => { 'key' => 'value' }), [:headers])
|
118
|
-
matcher.headers.should eq({ 'key' => 'value' })
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'returns nil when the match attributes do not include :headers' do
|
122
|
-
matcher = VCR::RequestMatcher.new(stub(:headers => { 'key' => 'value' }), [])
|
123
|
-
matcher.headers.should be_nil
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def matcher(*different_values)
|
128
|
-
match_attributes = [:method, :uri, :body, :headers]
|
129
|
-
if different_values.include?(:match_attributes)
|
130
|
-
match_attributes -= [:body]
|
131
|
-
end
|
132
|
-
|
133
|
-
request_object = different_values.include?(:request) ? 'request2' : 'request'
|
134
|
-
m = VCR::RequestMatcher.new(request_object, match_attributes)
|
135
|
-
|
136
|
-
%w( uri method body headers ).each do |attr|
|
137
|
-
m.should respond_to(attr)
|
138
|
-
m.stub!(attr).and_return(different_values.include?(attr.to_sym) ? attr.next : attr)
|
139
|
-
end
|
140
|
-
|
141
|
-
m
|
142
|
-
end
|
143
|
-
|
144
|
-
def matchers_varying_on(attribute)
|
145
|
-
return matcher, matcher(attribute)
|
146
|
-
end
|
147
|
-
|
148
|
-
def matcher_with_headers(headers)
|
149
|
-
VCR::RequestMatcher.new(VCR::Request.new(:get, 'http://foo.com/', nil, headers), [:method, :uri, :headers])
|
150
|
-
end
|
151
|
-
|
152
|
-
describe '#hash' do
|
153
|
-
it 'returns the same code for two objects when #match_attributes, #method, #uri, #body and #headers are the same, even when the request object is different' do
|
154
|
-
m1, m2 = matchers_varying_on(:request)
|
155
|
-
m1.hash.should eq(m2.hash)
|
156
|
-
end
|
157
|
-
|
158
|
-
it 'returns the same code for two objects when the matchers are the same, but #match_attributes has its elements in a different order' do
|
159
|
-
m1, m2 = matcher, matcher
|
160
|
-
m1.match_attributes = [:method, :uri, :body, :headers]
|
161
|
-
m2.match_attributes = [:method, :body, :uri, :headers]
|
162
|
-
m1.hash.should eq(m2.hash)
|
163
|
-
end
|
164
|
-
|
165
|
-
[:match_attributes, :method, :uri, :body, :headers].each do |different_attr|
|
166
|
-
it "returns different codes for two objects when ##{different_attr} is different, even when the request object is the same" do
|
167
|
-
m1, m2 = matchers_varying_on(different_attr)
|
168
|
-
m1.hash.should_not == m2.hash
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
context 'for headers' do
|
173
|
-
it 'returns the same code for the same headers' do
|
174
|
-
m1 = matcher_with_headers('x-http-header' => ['val1'])
|
175
|
-
m2 = matcher_with_headers('x-http-header' => ['val1'])
|
176
|
-
m1.hash.should eq(m2.hash)
|
177
|
-
end
|
178
|
-
|
179
|
-
it 'returns the same code when the header keys are ordered differently' do
|
180
|
-
m1 = matcher_with_headers('x-http-header1' => ['val1'], 'x-http-header2' => ['val2'])
|
181
|
-
m2 = matcher_with_headers('x-http-header2' => ['val2'], 'x-http-header1' => ['val1'])
|
182
|
-
m1.hash.should eq(m2.hash)
|
183
|
-
end
|
184
|
-
|
185
|
-
it 'returns the same code when the header value arrays are ordered differently' do
|
186
|
-
m1 = matcher_with_headers('x-http-header' => ['val1', 'val2'])
|
187
|
-
m2 = matcher_with_headers('x-http-header' => ['val2', 'val1'])
|
188
|
-
m1.hash.should eq(m2.hash)
|
189
|
-
end
|
190
|
-
|
191
|
-
it 'returns a different code when the header values are different' do
|
192
|
-
m1 = matcher_with_headers('x-http-header' => ['val1'])
|
193
|
-
m2 = matcher_with_headers('x-http-header' => ['val2'])
|
194
|
-
m1.hash.should_not == m2.hash
|
195
|
-
end
|
196
|
-
|
197
|
-
it 'returns a different code when the header keys are different' do
|
198
|
-
m1 = matcher_with_headers('x-http-header1' => ['val1'])
|
199
|
-
m2 = matcher_with_headers('x-http-header2' => ['val1'])
|
200
|
-
m1.hash.should_not == m2.hash
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
[:eql?, :==].each do |equality_method|
|
206
|
-
describe "##{equality_method.to_s}" do
|
207
|
-
it 'returns true when #match_attributes, #method, #uri, #body and #headers are the same, even when the request object is different' do
|
208
|
-
m1, m2 = matchers_varying_on(:request)
|
209
|
-
m1.send(equality_method, m2).should be_true
|
210
|
-
m2.send(equality_method, m1).should be_true
|
211
|
-
end
|
212
|
-
|
213
|
-
it 'returns true when the matchers are the same, but #match_attributes has its elements in a different order' do
|
214
|
-
m1, m2 = matcher, matcher
|
215
|
-
m1.match_attributes = [:method, :uri, :body, :headers]
|
216
|
-
m2.match_attributes = [:method, :body, :uri, :headers]
|
217
|
-
m1.send(equality_method, m2).should be_true
|
218
|
-
m2.send(equality_method, m1).should be_true
|
219
|
-
end
|
220
|
-
|
221
|
-
[:match_attributes, :method, :uri, :body, :headers].each do |different_attr|
|
222
|
-
it "returns false when ##{different_attr} is different, even when the request object is the same" do
|
223
|
-
m1, m2 = matchers_varying_on(different_attr)
|
224
|
-
m1.send(equality_method, m2).should be_false
|
225
|
-
m2.send(equality_method, m1).should be_false
|
226
|
-
end
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|