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.
Files changed (166) hide show
  1. data/.gitignore +2 -0
  2. data/.travis.yml +6 -2
  3. data/CHANGELOG.md +49 -1
  4. data/Gemfile +1 -5
  5. data/Guardfile +0 -5
  6. data/README.md +3 -2
  7. data/Rakefile +11 -16
  8. data/cucumber.yml +0 -4
  9. data/features/.nav +14 -2
  10. data/features/cassettes/automatic_re_recording.feature +4 -6
  11. data/features/cassettes/dynamic_erb.feature +6 -8
  12. data/features/cassettes/exclusive.feature +111 -0
  13. data/features/cassettes/format.feature +16 -14
  14. data/features/cassettes/naming.feature +4 -6
  15. data/features/cassettes/no_cassette.feature +25 -28
  16. data/features/cassettes/update_content_length_header.feature +9 -9
  17. data/features/configuration/allow_http_connections_when_no_cassette.feature +6 -8
  18. data/features/configuration/cassette_library_dir.feature +4 -6
  19. data/features/configuration/default_cassette_options.feature +12 -10
  20. data/features/configuration/filter_sensitive_data.feature +12 -17
  21. data/features/configuration/{stub_with.feature → hook_into.feature} +63 -62
  22. data/features/configuration/hooks.feature +23 -33
  23. data/features/configuration/ignore_hosts.feature +16 -17
  24. data/features/configuration/ignore_localhost.feature +33 -42
  25. data/features/http_libraries/em_http_request.feature +7 -8
  26. data/features/http_libraries/net_http.feature +26 -28
  27. data/features/middleware/faraday.feature +17 -56
  28. data/features/middleware/rack.feature +8 -11
  29. data/features/record_modes/all.feature +5 -7
  30. data/features/record_modes/new_episodes.feature +5 -7
  31. data/features/record_modes/none.feature +6 -6
  32. data/features/record_modes/once.feature +6 -8
  33. data/features/request_matching/README.md +28 -0
  34. data/features/request_matching/body.feature +81 -0
  35. data/features/request_matching/custom_matcher.feature +125 -0
  36. data/features/request_matching/headers.feature +85 -0
  37. data/features/request_matching/host.feature +85 -0
  38. data/features/request_matching/identical_request_sequence.feature +79 -0
  39. data/features/request_matching/method.feature +86 -0
  40. data/features/request_matching/path.feature +86 -0
  41. data/features/request_matching/playback_repeats.feature +87 -0
  42. data/features/request_matching/uri.feature +84 -0
  43. data/features/request_matching/uri_without_param.feature +85 -0
  44. data/features/step_definitions/cli_steps.rb +4 -28
  45. data/features/support/env.rb +11 -9
  46. data/features/support/http_lib_filters.rb +2 -11
  47. data/features/support/vcr_cucumber_helpers.rb +4 -5
  48. data/features/test_frameworks/cucumber.feature +17 -18
  49. data/features/test_frameworks/rspec.feature +8 -12
  50. data/features/test_frameworks/shoulda.feature +5 -8
  51. data/features/test_frameworks/test_unit.feature +5 -8
  52. data/lib/vcr.rb +38 -58
  53. data/lib/vcr/cassette.rb +41 -60
  54. data/lib/vcr/cassette/http_interaction_list.rb +56 -0
  55. data/lib/vcr/cassette/reader.rb +29 -31
  56. data/lib/vcr/configuration.rb +76 -0
  57. data/lib/vcr/deprecations.rb +39 -0
  58. data/lib/vcr/errors.rb +22 -0
  59. data/lib/vcr/library_hooks.rb +19 -0
  60. data/lib/vcr/library_hooks/excon.rb +136 -0
  61. data/lib/vcr/library_hooks/fakeweb.rb +110 -0
  62. data/lib/vcr/library_hooks/faraday.rb +3 -0
  63. data/lib/vcr/library_hooks/typhoeus.rb +98 -0
  64. data/lib/vcr/library_hooks/webmock.rb +100 -0
  65. data/lib/vcr/middleware/faraday.rb +43 -36
  66. data/lib/vcr/middleware/rack.rb +28 -4
  67. data/lib/vcr/request_handler.rb +43 -0
  68. data/lib/vcr/request_ignorer.rb +31 -0
  69. data/lib/vcr/request_matcher_registry.rb +86 -0
  70. data/lib/vcr/structs/http_interaction.rb +24 -18
  71. data/lib/vcr/structs/normalizers/body.rb +1 -1
  72. data/lib/vcr/structs/normalizers/header.rb +1 -1
  73. data/lib/vcr/structs/normalizers/status_message.rb +1 -1
  74. data/lib/vcr/structs/normalizers/uri.rb +1 -1
  75. data/lib/vcr/structs/request.rb +0 -13
  76. data/lib/vcr/structs/response.rb +2 -9
  77. data/lib/vcr/structs/response_status.rb +0 -4
  78. data/lib/vcr/test_frameworks/cucumber.rb +1 -1
  79. data/lib/vcr/test_frameworks/rspec.rb +1 -1
  80. data/lib/vcr/util/hooks.rb +28 -19
  81. data/lib/vcr/util/internet_connection.rb +29 -2
  82. data/lib/vcr/util/version_checker.rb +60 -0
  83. data/lib/vcr/version.rb +1 -1
  84. data/script/FullBuildRakeFile +0 -7
  85. data/script/full_build +1 -1
  86. data/spec/capture_warnings.rb +36 -31
  87. data/spec/fixtures/{1.9.1/cassette_spec → cassette_spec}/empty.yml +0 -0
  88. data/spec/fixtures/{not_1.9.1/cassette_spec → cassette_spec}/example.yml +0 -0
  89. data/spec/fixtures/{not_1.9.1/cassette_spec → cassette_spec}/with_localhost_requests.yml +0 -0
  90. data/spec/fixtures/{not_1.9.1/fake_example.com_responses.yml → fake_example.com_responses.yml} +0 -0
  91. data/spec/fixtures/{not_1.9.1/match_requests_on.yml → match_requests_on.yml} +0 -0
  92. data/spec/monkey_patches.rb +40 -11
  93. data/spec/spec_helper.rb +7 -43
  94. data/spec/support/http_library_adapters.rb +3 -13
  95. data/spec/support/shared_example_groups/{http_library.rb → hook_into_http_library.rb} +39 -111
  96. data/spec/support/shared_example_groups/version_checking.rb +9 -9
  97. data/spec/vcr/cassette/http_interaction_list_spec.rb +178 -0
  98. data/spec/vcr/cassette/reader_spec.rb +2 -2
  99. data/spec/vcr/cassette_spec.rb +121 -156
  100. data/spec/vcr/configuration_spec.rb +143 -0
  101. data/spec/vcr/deprecations_spec.rb +91 -0
  102. data/spec/vcr/{http_stubbing_adapters → library_hooks}/excon_spec.rb +6 -9
  103. data/spec/vcr/library_hooks/fakeweb_spec.rb +83 -0
  104. data/spec/vcr/{http_stubbing_adapters → library_hooks}/typhoeus_spec.rb +7 -11
  105. data/spec/vcr/library_hooks/webmock_spec.rb +17 -0
  106. data/spec/vcr/library_hooks_spec.rb +51 -0
  107. data/spec/vcr/middleware/faraday_spec.rb +17 -44
  108. data/spec/vcr/middleware/rack_spec.rb +94 -58
  109. data/spec/vcr/request_ignorer_spec.rb +54 -0
  110. data/spec/vcr/request_matcher_registry_spec.rb +223 -0
  111. data/spec/vcr/structs/request_spec.rb +0 -33
  112. data/spec/vcr/structs/response_spec.rb +0 -24
  113. data/spec/vcr/structs/response_status_spec.rb +0 -9
  114. data/spec/vcr/util/hooks_spec.rb +3 -5
  115. data/spec/vcr/version_spec.rb +1 -1
  116. data/spec/vcr_spec.rb +79 -91
  117. data/vcr.gemspec +1 -1
  118. metadata +83 -103
  119. data/features/cassettes/request_matching.feature +0 -383
  120. data/lib/vcr/config.rb +0 -84
  121. data/lib/vcr/deprecations/cassette.rb +0 -29
  122. data/lib/vcr/deprecations/config.rb +0 -18
  123. data/lib/vcr/deprecations/http_stubbing_adapters/common.rb +0 -9
  124. data/lib/vcr/deprecations/http_stubbing_adapters/fakeweb.rb +0 -11
  125. data/lib/vcr/extensions/net_http.rb +0 -32
  126. data/lib/vcr/http_stubbing_adapters/common.rb +0 -202
  127. data/lib/vcr/http_stubbing_adapters/excon.rb +0 -178
  128. data/lib/vcr/http_stubbing_adapters/fakeweb.rb +0 -107
  129. data/lib/vcr/http_stubbing_adapters/faraday.rb +0 -26
  130. data/lib/vcr/http_stubbing_adapters/multi_object_proxy.rb +0 -43
  131. data/lib/vcr/http_stubbing_adapters/typhoeus.rb +0 -115
  132. data/lib/vcr/http_stubbing_adapters/webmock.rb +0 -120
  133. data/lib/vcr/middleware/cassette_arguments.rb +0 -19
  134. data/lib/vcr/middleware/common.rb +0 -20
  135. data/lib/vcr/request_matcher.rb +0 -94
  136. data/lib/vcr/rspec.rb +0 -2
  137. data/lib/vcr/util/basic_object.rb +0 -43
  138. data/lib/vcr/util/ping.rb +0 -30
  139. data/lib/vcr/util/regexes.rb +0 -37
  140. data/spec/fixtures/1.9.1/0_3_1_cassette.yml +0 -29
  141. data/spec/fixtures/1.9.1/cassette_spec/example.yml +0 -110
  142. data/spec/fixtures/1.9.1/cassette_spec/with_localhost_requests.yml +0 -109
  143. data/spec/fixtures/1.9.1/example_net_http.yml +0 -14
  144. data/spec/fixtures/1.9.1/example_net_http_request.yml +0 -12
  145. data/spec/fixtures/1.9.1/example_net_http_response.yml +0 -25
  146. data/spec/fixtures/1.9.1/fake_example.com_responses.yml +0 -108
  147. data/spec/fixtures/1.9.1/match_requests_on.yml +0 -185
  148. data/spec/fixtures/not_1.9.1/0_3_1_cassette.yml +0 -29
  149. data/spec/fixtures/not_1.9.1/cassette_spec/empty.yml +0 -0
  150. data/spec/fixtures/not_1.9.1/example_net_http.yml +0 -14
  151. data/spec/fixtures/not_1.9.1/example_net_http_request.yml +0 -12
  152. data/spec/fixtures/not_1.9.1/example_net_http_response.yml +0 -25
  153. data/spec/support/shared_example_groups/http_stubbing_adapter.rb +0 -133
  154. data/spec/support/shared_example_groups/ignore_localhost_deprecation.rb +0 -28
  155. data/spec/vcr/config_spec.rb +0 -181
  156. data/spec/vcr/deprecations/cassette_spec.rb +0 -57
  157. data/spec/vcr/deprecations/config_spec.rb +0 -30
  158. data/spec/vcr/deprecations/http_stubbing_adapters/common_spec.rb +0 -7
  159. data/spec/vcr/deprecations/http_stubbing_adapters/fakeweb_spec.rb +0 -16
  160. data/spec/vcr/extensions/net_http_spec.rb +0 -80
  161. data/spec/vcr/http_stubbing_adapters/fakeweb_spec.rb +0 -19
  162. data/spec/vcr/http_stubbing_adapters/faraday_spec.rb +0 -76
  163. data/spec/vcr/http_stubbing_adapters/multi_object_proxy_spec.rb +0 -101
  164. data/spec/vcr/http_stubbing_adapters/webmock_spec.rb +0 -17
  165. data/spec/vcr/middleware/cassette_arguments_spec.rb +0 -32
  166. 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