mustwin-vcr 2.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +7 -0
  2. data/features/about_these_examples.md +18 -0
  3. data/features/cassettes/allow_unused_http_interactions.feature +100 -0
  4. data/features/cassettes/automatic_re_recording.feature +72 -0
  5. data/features/cassettes/decompress.feature +74 -0
  6. data/features/cassettes/dynamic_erb.feature +100 -0
  7. data/features/cassettes/exclusive.feature +126 -0
  8. data/features/cassettes/format.feature +323 -0
  9. data/features/cassettes/freezing_time.feature +68 -0
  10. data/features/cassettes/naming.feature +28 -0
  11. data/features/cassettes/no_cassette.feature +152 -0
  12. data/features/cassettes/update_content_length_header.feature +112 -0
  13. data/features/configuration/allow_http_connections_when_no_cassette.feature +55 -0
  14. data/features/configuration/cassette_library_dir.feature +31 -0
  15. data/features/configuration/debug_logging.feature +59 -0
  16. data/features/configuration/default_cassette_options.feature +100 -0
  17. data/features/configuration/filter_sensitive_data.feature +153 -0
  18. data/features/configuration/hook_into.feature +172 -0
  19. data/features/configuration/ignore_request.feature +192 -0
  20. data/features/configuration/preserve_exact_body_bytes.feature +108 -0
  21. data/features/configuration/query_parser.feature +84 -0
  22. data/features/configuration/uri_parser.feature +89 -0
  23. data/features/getting_started.md +82 -0
  24. data/features/hooks/after_http_request.feature +58 -0
  25. data/features/hooks/around_http_request.feature +57 -0
  26. data/features/hooks/before_http_request.feature +63 -0
  27. data/features/hooks/before_playback.feature +184 -0
  28. data/features/hooks/before_record.feature +172 -0
  29. data/features/http_libraries/em_http_request.feature +250 -0
  30. data/features/http_libraries/net_http.feature +179 -0
  31. data/features/middleware/faraday.feature +56 -0
  32. data/features/middleware/rack.feature +92 -0
  33. data/features/record_modes/all.feature +82 -0
  34. data/features/record_modes/new_episodes.feature +79 -0
  35. data/features/record_modes/none.feature +72 -0
  36. data/features/record_modes/once.feature +95 -0
  37. data/features/request_matching/README.md +30 -0
  38. data/features/request_matching/body.feature +91 -0
  39. data/features/request_matching/body_as_json.feature +90 -0
  40. data/features/request_matching/custom_matcher.feature +135 -0
  41. data/features/request_matching/headers.feature +85 -0
  42. data/features/request_matching/host.feature +95 -0
  43. data/features/request_matching/identical_request_sequence.feature +89 -0
  44. data/features/request_matching/method.feature +96 -0
  45. data/features/request_matching/path.feature +96 -0
  46. data/features/request_matching/playback_repeats.feature +98 -0
  47. data/features/request_matching/query.feature +97 -0
  48. data/features/request_matching/uri.feature +94 -0
  49. data/features/request_matching/uri_without_param.feature +101 -0
  50. data/features/step_definitions/cli_steps.rb +193 -0
  51. data/features/support/env.rb +44 -0
  52. data/features/support/http_lib_filters.rb +53 -0
  53. data/features/test_frameworks/cucumber.feature +211 -0
  54. data/features/test_frameworks/rspec_macro.feature +81 -0
  55. data/features/test_frameworks/rspec_metadata.feature +150 -0
  56. data/features/test_frameworks/test_unit.feature +49 -0
  57. data/lib/vcr.rb +347 -0
  58. data/lib/vcr/cassette.rb +291 -0
  59. data/lib/vcr/cassette/erb_renderer.rb +55 -0
  60. data/lib/vcr/cassette/http_interaction_list.rb +108 -0
  61. data/lib/vcr/cassette/migrator.rb +118 -0
  62. data/lib/vcr/cassette/persisters.rb +42 -0
  63. data/lib/vcr/cassette/persisters/file_system.rb +64 -0
  64. data/lib/vcr/cassette/serializers.rb +57 -0
  65. data/lib/vcr/cassette/serializers/json.rb +48 -0
  66. data/lib/vcr/cassette/serializers/psych.rb +48 -0
  67. data/lib/vcr/cassette/serializers/syck.rb +61 -0
  68. data/lib/vcr/cassette/serializers/yaml.rb +50 -0
  69. data/lib/vcr/configuration.rb +555 -0
  70. data/lib/vcr/deprecations.rb +109 -0
  71. data/lib/vcr/errors.rb +266 -0
  72. data/lib/vcr/extensions/net_http_response.rb +36 -0
  73. data/lib/vcr/library_hooks.rb +18 -0
  74. data/lib/vcr/library_hooks/excon.rb +27 -0
  75. data/lib/vcr/library_hooks/fakeweb.rb +196 -0
  76. data/lib/vcr/library_hooks/faraday.rb +51 -0
  77. data/lib/vcr/library_hooks/typhoeus.rb +120 -0
  78. data/lib/vcr/library_hooks/typhoeus_0.4.rb +103 -0
  79. data/lib/vcr/library_hooks/webmock.rb +164 -0
  80. data/lib/vcr/middleware/excon.rb +221 -0
  81. data/lib/vcr/middleware/excon/legacy_methods.rb +33 -0
  82. data/lib/vcr/middleware/faraday.rb +118 -0
  83. data/lib/vcr/middleware/rack.rb +79 -0
  84. data/lib/vcr/request_handler.rb +114 -0
  85. data/lib/vcr/request_ignorer.rb +43 -0
  86. data/lib/vcr/request_matcher_registry.rb +149 -0
  87. data/lib/vcr/structs.rb +578 -0
  88. data/lib/vcr/tasks/vcr.rake +9 -0
  89. data/lib/vcr/test_frameworks/cucumber.rb +64 -0
  90. data/lib/vcr/test_frameworks/rspec.rb +47 -0
  91. data/lib/vcr/util/hooks.rb +61 -0
  92. data/lib/vcr/util/internet_connection.rb +43 -0
  93. data/lib/vcr/util/logger.rb +59 -0
  94. data/lib/vcr/util/variable_args_block_caller.rb +13 -0
  95. data/lib/vcr/util/version_checker.rb +48 -0
  96. data/lib/vcr/version.rb +34 -0
  97. data/spec/acceptance/threading_spec.rb +34 -0
  98. data/spec/fixtures/cassette_spec/1_x_cassette.yml +110 -0
  99. data/spec/fixtures/cassette_spec/empty.yml +0 -0
  100. data/spec/fixtures/cassette_spec/example.yml +111 -0
  101. data/spec/fixtures/cassette_spec/with_localhost_requests.yml +111 -0
  102. data/spec/fixtures/fake_example_responses.yml +110 -0
  103. data/spec/fixtures/match_requests_on.yml +187 -0
  104. data/spec/lib/vcr/cassette/erb_renderer_spec.rb +53 -0
  105. data/spec/lib/vcr/cassette/http_interaction_list_spec.rb +295 -0
  106. data/spec/lib/vcr/cassette/migrator_spec.rb +195 -0
  107. data/spec/lib/vcr/cassette/persisters/file_system_spec.rb +69 -0
  108. data/spec/lib/vcr/cassette/persisters_spec.rb +39 -0
  109. data/spec/lib/vcr/cassette/serializers_spec.rb +176 -0
  110. data/spec/lib/vcr/cassette_spec.rb +618 -0
  111. data/spec/lib/vcr/configuration_spec.rb +326 -0
  112. data/spec/lib/vcr/deprecations_spec.rb +85 -0
  113. data/spec/lib/vcr/errors_spec.rb +162 -0
  114. data/spec/lib/vcr/extensions/net_http_response_spec.rb +86 -0
  115. data/spec/lib/vcr/library_hooks/excon_spec.rb +104 -0
  116. data/spec/lib/vcr/library_hooks/fakeweb_spec.rb +169 -0
  117. data/spec/lib/vcr/library_hooks/faraday_spec.rb +68 -0
  118. data/spec/lib/vcr/library_hooks/typhoeus_0.4_spec.rb +36 -0
  119. data/spec/lib/vcr/library_hooks/typhoeus_spec.rb +162 -0
  120. data/spec/lib/vcr/library_hooks/webmock_spec.rb +118 -0
  121. data/spec/lib/vcr/library_hooks_spec.rb +51 -0
  122. data/spec/lib/vcr/middleware/faraday_spec.rb +182 -0
  123. data/spec/lib/vcr/middleware/rack_spec.rb +115 -0
  124. data/spec/lib/vcr/request_ignorer_spec.rb +70 -0
  125. data/spec/lib/vcr/request_matcher_registry_spec.rb +345 -0
  126. data/spec/lib/vcr/structs_spec.rb +732 -0
  127. data/spec/lib/vcr/test_frameworks/cucumber_spec.rb +107 -0
  128. data/spec/lib/vcr/test_frameworks/rspec_spec.rb +83 -0
  129. data/spec/lib/vcr/util/hooks_spec.rb +158 -0
  130. data/spec/lib/vcr/util/internet_connection_spec.rb +37 -0
  131. data/spec/lib/vcr/util/version_checker_spec.rb +31 -0
  132. data/spec/lib/vcr/version_spec.rb +27 -0
  133. data/spec/lib/vcr_spec.rb +349 -0
  134. data/spec/monkey_patches.rb +182 -0
  135. data/spec/spec_helper.rb +62 -0
  136. data/spec/support/configuration_stubbing.rb +8 -0
  137. data/spec/support/cucumber_helpers.rb +35 -0
  138. data/spec/support/fixnum_extension.rb +10 -0
  139. data/spec/support/http_library_adapters.rb +289 -0
  140. data/spec/support/limited_uri.rb +21 -0
  141. data/spec/support/ruby_interpreter.rb +7 -0
  142. data/spec/support/shared_example_groups/excon.rb +63 -0
  143. data/spec/support/shared_example_groups/hook_into_http_library.rb +594 -0
  144. data/spec/support/shared_example_groups/request_hooks.rb +59 -0
  145. data/spec/support/sinatra_app.rb +86 -0
  146. data/spec/support/vcr_localhost_server.rb +76 -0
  147. data/spec/support/vcr_stub_helpers.rb +17 -0
  148. metadata +677 -0
@@ -0,0 +1,115 @@
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
+
@@ -0,0 +1,70 @@
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
+
@@ -0,0 +1,345 @@
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
+