webmock 3.5.1 → 3.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +15 -12
  3. data/CHANGELOG.md +211 -0
  4. data/README.md +92 -26
  5. data/Rakefile +0 -2
  6. data/lib/webmock.rb +1 -0
  7. data/lib/webmock/http_lib_adapters/async_http_client_adapter.rb +214 -0
  8. data/lib/webmock/http_lib_adapters/curb_adapter.rb +10 -1
  9. data/lib/webmock/http_lib_adapters/em_http_request_adapter.rb +1 -1
  10. data/lib/webmock/http_lib_adapters/excon_adapter.rb +3 -0
  11. data/lib/webmock/http_lib_adapters/http_rb/client.rb +4 -1
  12. data/lib/webmock/http_lib_adapters/http_rb/response.rb +11 -1
  13. data/lib/webmock/http_lib_adapters/http_rb/streamer.rb +2 -2
  14. data/lib/webmock/http_lib_adapters/httpclient_adapter.rb +23 -6
  15. data/lib/webmock/http_lib_adapters/manticore_adapter.rb +25 -14
  16. data/lib/webmock/http_lib_adapters/net_http.rb +35 -17
  17. data/lib/webmock/http_lib_adapters/patron_adapter.rb +1 -1
  18. data/lib/webmock/request_body_diff.rb +1 -1
  19. data/lib/webmock/request_pattern.rb +76 -48
  20. data/lib/webmock/response.rb +11 -5
  21. data/lib/webmock/rspec.rb +2 -1
  22. data/lib/webmock/stub_registry.rb +26 -11
  23. data/lib/webmock/test_unit.rb +1 -3
  24. data/lib/webmock/util/query_mapper.rb +4 -2
  25. data/lib/webmock/util/uri.rb +8 -8
  26. data/lib/webmock/version.rb +1 -1
  27. data/lib/webmock/webmock.rb +10 -3
  28. data/spec/acceptance/async_http_client/async_http_client_spec.rb +353 -0
  29. data/spec/acceptance/async_http_client/async_http_client_spec_helper.rb +73 -0
  30. data/spec/acceptance/curb/curb_spec.rb +23 -5
  31. data/spec/acceptance/em_http_request/em_http_request_spec_helper.rb +1 -1
  32. data/spec/acceptance/excon/excon_spec_helper.rb +2 -0
  33. data/spec/acceptance/http_rb/http_rb_spec.rb +11 -0
  34. data/spec/acceptance/manticore/manticore_spec.rb +19 -0
  35. data/spec/acceptance/net_http/net_http_spec.rb +12 -0
  36. data/spec/acceptance/shared/callbacks.rb +2 -1
  37. data/spec/acceptance/shared/request_expectations.rb +7 -0
  38. data/spec/acceptance/shared/returning_declared_responses.rb +36 -15
  39. data/spec/acceptance/shared/stubbing_requests.rb +40 -0
  40. data/spec/support/webmock_server.rb +1 -0
  41. data/spec/unit/request_pattern_spec.rb +119 -3
  42. data/spec/unit/response_spec.rb +22 -18
  43. data/spec/unit/util/query_mapper_spec.rb +7 -0
  44. data/spec/unit/util/uri_spec.rb +74 -2
  45. data/spec/unit/webmock_spec.rb +54 -5
  46. data/test/test_webmock.rb +6 -0
  47. data/webmock.gemspec +9 -2
  48. metadata +39 -10
@@ -411,6 +411,17 @@ unless RUBY_PLATFORM =~ /java/
411
411
  it_should_behave_like "Curb"
412
412
  include CurbSpecHelper::NamedHttp
413
413
 
414
+ it "should reset @webmock_method after each call" do
415
+ stub_request(:post, "www.example.com").with(body: "01234")
416
+ c = Curl::Easy.new
417
+ c.url = "http://www.example.com"
418
+ c.post_body = "01234"
419
+ c.http_post
420
+ expect {
421
+ c.perform
422
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com))
423
+ end
424
+
414
425
  it "should work with blank arguments for post" do
415
426
  stub_request(:post, "www.example.com").with(body: "01234")
416
427
  c = Curl::Easy.new
@@ -463,18 +474,25 @@ unless RUBY_PLATFORM =~ /java/
463
474
  include CurbSpecHelper::ClassPerform
464
475
  end
465
476
 
466
- describe "using .reset" do
477
+ describe "using #reset" do
467
478
  before do
468
479
  @curl = Curl::Easy.new
469
480
  @curl.url = "http://example.com"
470
- body = "on_success fired"
471
- stub_request(:any, "example.com").to_return(body: body)
481
+ stub_request(:any, "example.com").
482
+ to_return(body: "abc",
483
+ headers: { "Content-Type" => "application/json" })
472
484
  @curl.http_get
473
485
  end
474
486
 
475
- it "should clear the body_str" do
487
+ it "should clear all memoized response fields" do
476
488
  @curl.reset
477
- expect(@curl.body_str).to eq(nil)
489
+ expect(@curl).to have_attributes(
490
+ body_str: nil,
491
+ content_type: nil,
492
+ header_str: nil,
493
+ last_effective_url: nil,
494
+ response_code: 0,
495
+ )
478
496
  end
479
497
  end
480
498
  end
@@ -50,7 +50,7 @@ module EMHttpRequestSpecHelper
50
50
  end
51
51
 
52
52
  def client_timeout_exception_class
53
- "WebMock timeout error"
53
+ 'Errno::ETIMEDOUT'
54
54
  end
55
55
 
56
56
  def connection_refused_exception_class
@@ -28,6 +28,8 @@ module ExconSpecHelper
28
28
  res
29
29
  end
30
30
 
31
+ Excon.set_raise_on_warnings!(true)
32
+
31
33
  OpenStruct.new \
32
34
  body: response.body,
33
35
  headers: headers,
@@ -72,6 +72,17 @@ describe "HTTP.rb" do
72
72
  end
73
73
 
74
74
  context "streamer" do
75
+ it "can be read to a provided buffer" do
76
+ stub_request(:get, "example.com/foo")
77
+ .to_return(status: 200, body: "Hello world! ")
78
+ response = HTTP.get "http://example.com/foo"
79
+
80
+ buffer = ""
81
+ response.body.readpartial(1024, buffer)
82
+
83
+ expect(buffer).to eq "Hello world! "
84
+ end
85
+
75
86
  it "can be closed" do
76
87
  stub_request :get, "example.com/foo"
77
88
  response = HTTP.get "http://example.com/foo"
@@ -51,6 +51,25 @@ if RUBY_PLATFORM =~ /java/
51
51
  response = Manticore.head("http://example-foo.com")
52
52
  expect(response.code).to eq(204)
53
53
  end
54
+
55
+ context "when a custom failure handler is defined" do
56
+ let(:failure_handler) { proc {} }
57
+
58
+ before do
59
+ allow(failure_handler).to receive(:call).with(kind_of(Manticore::Timeout)) do |ex|
60
+ raise ex
61
+ end
62
+ end
63
+
64
+ it "handles timeouts by invoking the failure handler" do
65
+ stub_request(:get, "http://example-foo.com").to_timeout
66
+ request = Manticore.get("http://example-foo.com").tap do |req|
67
+ req.on_failure(&failure_handler)
68
+ end
69
+ expect { request.call }.to raise_error(Manticore::Timeout)
70
+ expect(failure_handler).to have_received(:call)
71
+ end
72
+ end
54
73
  end
55
74
  end
56
75
  end
@@ -201,6 +201,18 @@ describe "Net:HTTP" do
201
201
  expect(Net::HTTP.get_response(Addressable::URI.parse('http://www.example.com/hello?a=1')).body).to eq("abc")
202
202
  end
203
203
 
204
+ it "should support method calls on stubbed socket" do
205
+ WebMock.allow_net_connect!
206
+ stub_request(:get, 'www.google.com')#.with(headers: {"My-Header" => 99})
207
+ req = Net::HTTP::Get.new('/')
208
+ Net::HTTP.start('www.google.com') do |http|
209
+ http.request(req, '')
210
+ socket = http.instance_variable_get(:@socket)
211
+ expect(socket).to be_a(StubSocket)
212
+ expect { socket.io.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) }.to_not raise_error
213
+ end
214
+ end
215
+
204
216
  describe "connecting on Net::HTTP.start" do
205
217
  before(:each) do
206
218
  @http = Net::HTTP.new('www.google.com', 443)
@@ -111,7 +111,8 @@ shared_context "callbacks" do |*adapter_info|
111
111
  end
112
112
 
113
113
  it "should pass real response to callback with headers" do
114
- expect(@response.headers["Content-Length"]).to eq("11")
114
+ expect(@response.headers["X-Powered-By"]).to eq( "ASP.NET")
115
+ expect(@response.headers["Content-Length"]).to eq("11") unless adapter_info.include?(:no_content_length_header)
115
116
  end
116
117
 
117
118
  it "should pass response to callback with body" do
@@ -172,6 +172,13 @@ shared_context "request expectations" do |*adapter_info|
172
172
  expect(a_request(:get, "www.example.com").with(query: hash_excluding(a: ['b', 'c']))).to have_been_made
173
173
  }.not_to raise_error
174
174
  end
175
+
176
+ it 'should satisfy expectation if the request was executed with an empty array in the query params' do
177
+ expect {
178
+ http_request(:get, "http://www.example.com/?a[]")
179
+ expect(a_request(:get, "www.example.com").with(query: hash_including(a: []))).to have_been_made
180
+ }.not_to raise_error
181
+ end
175
182
  end
176
183
 
177
184
  context "when using flat array notation" do
@@ -64,7 +64,10 @@ shared_context "declared responses" do |*adapter_info|
64
64
  it "should return response with declared headers" do
65
65
  stub_request(:get, "www.example.com").to_return(headers: SAMPLE_HEADERS)
66
66
  response = http_request(:get, "http://www.example.com/")
67
- expect(response.headers["Content-Length"]).to eq("8888")
67
+ expect(response.headers["Accept"]).to eq("application/json")
68
+ unless adapter_info.include?(:no_content_length_header)
69
+ expect(response.headers["Content-Length"]).to eq("8888")
70
+ end
68
71
  end
69
72
 
70
73
  it "should return response with declared headers even if there are multiple headers with the same key" do
@@ -171,13 +174,22 @@ shared_context "declared responses" do |*adapter_info|
171
174
  end
172
175
 
173
176
  it "should return recorded headers" do
174
- expect(@response.headers).to eq({
175
- "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT",
176
- "Content-Type"=>"text/html; charset=UTF-8",
177
- "Content-Length"=>"419",
178
- "Connection"=>"Keep-Alive",
179
- "Accept"=>"image/jpeg, image/png"
180
- })
177
+ if adapter_info.include?(:no_content_length_header)
178
+ expect(@response.headers).to eq({
179
+ "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT",
180
+ "Content-Type"=>"text/html; charset=UTF-8",
181
+ "Connection"=>"Keep-Alive",
182
+ "Accept"=>"image/jpeg, image/png"
183
+ })
184
+ else
185
+ expect(@response.headers).to eq({
186
+ "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT",
187
+ "Content-Type"=>"text/html; charset=UTF-8",
188
+ "Content-Length"=>"419",
189
+ "Connection"=>"Keep-Alive",
190
+ "Accept"=>"image/jpeg, image/png"
191
+ })
192
+ end
181
193
  end
182
194
 
183
195
  it "should return recorded body" do
@@ -205,13 +217,22 @@ shared_context "declared responses" do |*adapter_info|
205
217
  end
206
218
 
207
219
  it "should return recorded headers" do
208
- expect(@response.headers).to eq({
209
- "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT",
210
- "Content-Type"=>"text/html; charset=UTF-8",
211
- "Content-Length"=>"419",
212
- "Connection"=>"Keep-Alive",
213
- "Accept"=>"image/jpeg, image/png"
214
- })
220
+ if adapter_info.include?(:no_content_length_header)
221
+ expect(@response.headers).to eq({
222
+ "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT",
223
+ "Content-Type"=>"text/html; charset=UTF-8",
224
+ "Connection"=>"Keep-Alive",
225
+ "Accept"=>"image/jpeg, image/png"
226
+ })
227
+ else
228
+ expect(@response.headers).to eq({
229
+ "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT",
230
+ "Content-Type"=>"text/html; charset=UTF-8",
231
+ "Content-Length"=>"419",
232
+ "Connection"=>"Keep-Alive",
233
+ "Accept"=>"image/jpeg, image/png"
234
+ })
235
+ end
215
236
  end
216
237
 
217
238
  it "should return recorded body" do
@@ -68,6 +68,11 @@ shared_examples_for "stubbing requests" do |*adapter_info|
68
68
  stub_request(:get, 'www.example.com').with(query: hash_excluding(a: ['b', 'c'])).to_return(body: 'abc')
69
69
  expect(http_request(:get, 'http://www.example.com/?a[]=c&a[]=d&b=1').body).to eq('abc')
70
70
  end
71
+
72
+ it "should return stubbed response when stub expects an empty array" do
73
+ stub_request(:get, 'www.example.com').with(query: { a: [] }).to_return(body: 'abc')
74
+ expect(http_request(:get, 'http://www.example.com/?a[]').body).to eq('abc')
75
+ end
71
76
  end
72
77
 
73
78
  describe "based on method" do
@@ -588,6 +593,23 @@ shared_examples_for "stubbing requests" do |*adapter_info|
588
593
  end
589
594
  end
590
595
  end
596
+
597
+ context "when global stub should be invoked last" do
598
+ before do
599
+ WebMock.globally_stub_request(:after_local_stubs) do
600
+ { body: "global stub body" }
601
+ end
602
+ end
603
+
604
+ it "uses global stub when non-global stub is not defined" do
605
+ expect(http_request(:get, "http://www.example.com/").body).to eq("global stub body")
606
+ end
607
+
608
+ it "uses non-global stub first" do
609
+ stub_request(:get, "www.example.com").to_return(body: 'non-global stub body')
610
+ expect(http_request(:get, "http://www.example.com/").body).to eq("non-global stub body")
611
+ end
612
+ end
591
613
  end
592
614
 
593
615
  describe "when stubbing request with a block evaluated on request" do
@@ -635,4 +657,22 @@ shared_examples_for "stubbing requests" do |*adapter_info|
635
657
  }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
636
658
  end
637
659
  end
660
+
661
+ describe "in Rspec around(:each) hook" do
662
+ # order goes
663
+ # around(:each)
664
+ # before(:each)
665
+ # after(:each)
666
+ # anything after example.run in around(:each)
667
+ around(:each) do |example|
668
+ example.run
669
+ expect {
670
+ http_request(:get, "http://www.example.com/")
671
+ }.to_not raise_error # WebMock::NetConnectNotAllowedError
672
+ end
673
+
674
+ it "should still allow me to make a mocked request" do
675
+ stub_request(:get, "www.example.com")
676
+ end
677
+ end
638
678
  end
@@ -36,6 +36,7 @@ class WebMockServer
36
36
  end
37
37
  end
38
38
  server.start do |socket|
39
+ socket.read(1)
39
40
  socket.puts <<-EOT.gsub(/^\s+\|/, '')
40
41
  |HTTP/1.1 200 OK\r
41
42
  |Date: Fri, 31 Dec 1999 23:59:59 GMT\r
@@ -58,7 +58,7 @@ describe WebMock::RequestPattern do
58
58
  end
59
59
 
60
60
  it "should raise an error if neither options or block is provided" do
61
- expect { @request_pattern.with() }.to raise_error('#with method invoked with no arguments. Either options hash or block must be specified.')
61
+ expect { @request_pattern.with() }.to raise_error('#with method invoked with no arguments. Either options hash or block must be specified. Created a block with do..end? Try creating it with curly braces {} instead.')
62
62
  end
63
63
  end
64
64
 
@@ -111,6 +111,21 @@ describe WebMock::RequestPattern do
111
111
  to match(WebMock::RequestSignature.new(:get, "www.example.com"))
112
112
  end
113
113
 
114
+ it "should match if uri matches requesst uri as URI object" do
115
+ expect(WebMock::RequestPattern.new(:get, URI.parse("www.example.com"))).
116
+ to match(WebMock::RequestSignature.new(:get, "www.example.com"))
117
+ end
118
+
119
+ it "should match if uri proc pattern returning true" do
120
+ expect(WebMock::RequestPattern.new(:get, ->(uri) { true })).
121
+ to match(WebMock::RequestSignature.new(:get, "www.example.com"))
122
+ end
123
+
124
+ it "should not match if uri proc pattern returns false" do
125
+ expect(WebMock::RequestPattern.new(:get, ->(uri) { false })).
126
+ not_to match(WebMock::RequestSignature.new(:get, "www.example.com"))
127
+ end
128
+
114
129
  it "should match if uri Addressable::Template pattern matches unescaped form of request uri" do
115
130
  expect(WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com/{any_path}"))).
116
131
  to match(WebMock::RequestSignature.new(:get, "www.example.com/my%20path"))
@@ -121,12 +136,41 @@ describe WebMock::RequestPattern do
121
136
  to match(WebMock::RequestSignature.new(:get, "www.example.com"))
122
137
  end
123
138
 
139
+ it "should match if uri Addressable::Template pattern matches request uri without TLD" do
140
+ expect(WebMock::RequestPattern.new(:get, Addressable::Template.new("localhost"))).
141
+ to match(WebMock::RequestSignature.new(:get, "localhost"))
142
+ end
143
+
124
144
  it "should match if Addressable::Template pattern that has ip address host matches request uri" do
125
145
  signature = WebMock::RequestSignature.new(:get, "127.0.0.1:3000/1234")
126
146
  uri = Addressable::Template.new("127.0.0.1:3000/{id}")
127
147
  expect(WebMock::RequestPattern.new(:get, uri)).to match(signature)
128
148
  end
129
149
 
150
+ it "should match if Addressable::Template pattern that has ip address host without port matches request uri" do
151
+ signature = WebMock::RequestSignature.new(:get, "127.0.0.1/1234")
152
+ uri = Addressable::Template.new("127.0.0.1/{id}")
153
+ expect(WebMock::RequestPattern.new(:get, uri)).to match(signature)
154
+ end
155
+
156
+ it "should match if Addressable::Template pattern host matches request uri" do
157
+ signature = WebMock::RequestSignature.new(:get, "www.example.com")
158
+ uri = Addressable::Template.new("{subdomain}.example.com")
159
+ expect(WebMock::RequestPattern.new(:get, uri)).to match(signature)
160
+ end
161
+
162
+ it "should not match if Addressable::Template pattern host does not match request uri" do
163
+ signature = WebMock::RequestSignature.new(:get, "www.bad-example.com")
164
+ uri = Addressable::Template.new("{subdomain}.example.com")
165
+ expect(WebMock::RequestPattern.new(:get, uri)).not_to match(signature)
166
+ end
167
+
168
+ it "should match if uri Addressable::Template pattern matches request uri without a schema and a path " do
169
+ signature = WebMock::RequestSignature.new(:get, "127.0.0.1:3000")
170
+ uri = Addressable::Template.new("127.0.0.1:3000")
171
+ expect(WebMock::RequestPattern.new(:get, uri)).to match(signature)
172
+ end
173
+
130
174
  it "should match for uris with same parameters as pattern" do
131
175
  expect(WebMock::RequestPattern.new(:get, "www.example.com?a=1&b=2")).
132
176
  to match(WebMock::RequestSignature.new(:get, "www.example.com?a=1&b=2"))
@@ -194,7 +238,7 @@ describe WebMock::RequestPattern do
194
238
  to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
195
239
  end
196
240
 
197
- it "should match request query params if params don't match" do
241
+ it "should not match request query params if params don't match" do
198
242
  expect(WebMock::RequestPattern.new(:get, /.*example.*/, query: {"x" => ["b", "c"]})).
199
243
  not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
200
244
  end
@@ -224,13 +268,85 @@ describe WebMock::RequestPattern do
224
268
  end
225
269
  end
226
270
 
271
+ describe "when uri is described as URI" do
272
+ it "should match request query params" do
273
+ expect(WebMock::RequestPattern.new(:get, URI.parse("www.example.com"), query: {"a" => ["b", "c"]})).
274
+ to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
275
+ end
276
+
277
+ it "should not match request query params if params don't match" do
278
+ expect(WebMock::RequestPattern.new(:get, URI.parse("www.example.com"), query: {"x" => ["b", "c"]})).
279
+ not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
280
+ end
281
+
282
+ it "should match when query params are declared as HashIncluding matcher matching params" do
283
+ expect(WebMock::RequestPattern.new(:get, URI.parse("www.example.com"),
284
+ query: WebMock::Matchers::HashIncludingMatcher.new({"a" => ["b", "c"]}))).
285
+ to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
286
+ end
287
+
288
+ it "should not match when query params are declared as HashIncluding matcher not matching params" do
289
+ expect(WebMock::RequestPattern.new(:get, URI.parse("www.example.com"),
290
+ query: WebMock::Matchers::HashIncludingMatcher.new({"x" => ["b", "c"]}))).
291
+ not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
292
+ end
293
+
294
+ it "should match when query params are declared as RSpec HashIncluding matcher matching params" do
295
+ expect(WebMock::RequestPattern.new(:get, URI.parse("www.example.com"),
296
+ query: RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => ["b", "c"]}))).
297
+ to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
298
+ end
299
+
300
+ it "should not match when query params are declared as RSpec HashIncluding matcher not matching params" do
301
+ expect(WebMock::RequestPattern.new(:get, URI.parse("www.example.com"),
302
+ query: RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => ["b", "d"]}))).
303
+ not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
304
+ end
305
+ end
306
+
307
+ describe "when uri is described as a proc" do
308
+ it "should match request query params" do
309
+ expect(WebMock::RequestPattern.new(:get, ->(uri) { true }, query: {"a" => ["b", "c"]})).
310
+ to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
311
+ end
312
+
313
+ it "should not match request query params if params don't match" do
314
+ expect(WebMock::RequestPattern.new(:get, ->(uri) { true }, query: {"x" => ["b", "c"]})).
315
+ not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
316
+ end
317
+
318
+ it "should match when query params are declared as HashIncluding matcher matching params" do
319
+ expect(WebMock::RequestPattern.new(:get, ->(uri) { true },
320
+ query: WebMock::Matchers::HashIncludingMatcher.new({"a" => ["b", "c"]}))).
321
+ to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
322
+ end
323
+
324
+ it "should not match when query params are declared as HashIncluding matcher not matching params" do
325
+ expect(WebMock::RequestPattern.new(:get, ->(uri) { true },
326
+ query: WebMock::Matchers::HashIncludingMatcher.new({"x" => ["b", "c"]}))).
327
+ not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
328
+ end
329
+
330
+ it "should match when query params are declared as RSpec HashIncluding matcher matching params" do
331
+ expect(WebMock::RequestPattern.new(:get, ->(uri) { true },
332
+ query: RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => ["b", "c"]}))).
333
+ to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
334
+ end
335
+
336
+ it "should not match when query params are declared as RSpec HashIncluding matcher not matching params" do
337
+ expect(WebMock::RequestPattern.new(:get, ->(uri) { true },
338
+ query: RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => ["b", "d"]}))).
339
+ not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
340
+ end
341
+ end
342
+
227
343
  describe "when uri is described as Addressable::Template" do
228
344
  it "should raise error if query params are specified" do
229
345
  expect(WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com"), query: {"a" => ["b", "c"]})).
230
346
  to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
231
347
  end
232
348
 
233
- it "should match request query params if params don't match" do
349
+ it "should not match request query params if params don't match" do
234
350
  expect(WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com"), query: {"x" => ["b", "c"]})).
235
351
  not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
236
352
  end