webmock 3.5.1 → 3.11.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +15 -12
- data/CHANGELOG.md +223 -0
- data/README.md +94 -26
- data/Rakefile +0 -2
- data/lib/webmock.rb +1 -0
- data/lib/webmock/http_lib_adapters/async_http_client_adapter.rb +214 -0
- data/lib/webmock/http_lib_adapters/curb_adapter.rb +10 -1
- data/lib/webmock/http_lib_adapters/em_http_request_adapter.rb +1 -1
- data/lib/webmock/http_lib_adapters/excon_adapter.rb +3 -0
- data/lib/webmock/http_lib_adapters/http_rb/client.rb +4 -1
- data/lib/webmock/http_lib_adapters/http_rb/response.rb +11 -1
- data/lib/webmock/http_lib_adapters/http_rb/streamer.rb +2 -2
- data/lib/webmock/http_lib_adapters/httpclient_adapter.rb +23 -6
- data/lib/webmock/http_lib_adapters/manticore_adapter.rb +33 -15
- data/lib/webmock/http_lib_adapters/net_http.rb +35 -17
- data/lib/webmock/http_lib_adapters/patron_adapter.rb +1 -1
- data/lib/webmock/request_body_diff.rb +1 -1
- data/lib/webmock/request_pattern.rb +76 -48
- data/lib/webmock/response.rb +11 -5
- data/lib/webmock/rspec.rb +2 -1
- data/lib/webmock/stub_registry.rb +26 -11
- data/lib/webmock/test_unit.rb +1 -3
- data/lib/webmock/util/query_mapper.rb +4 -2
- data/lib/webmock/util/uri.rb +8 -8
- data/lib/webmock/version.rb +1 -1
- data/lib/webmock/webmock.rb +10 -3
- data/spec/acceptance/async_http_client/async_http_client_spec.rb +353 -0
- data/spec/acceptance/async_http_client/async_http_client_spec_helper.rb +73 -0
- data/spec/acceptance/curb/curb_spec.rb +23 -5
- data/spec/acceptance/em_http_request/em_http_request_spec_helper.rb +1 -1
- data/spec/acceptance/excon/excon_spec_helper.rb +2 -0
- data/spec/acceptance/http_rb/http_rb_spec.rb +11 -0
- data/spec/acceptance/manticore/manticore_spec.rb +51 -0
- data/spec/acceptance/net_http/net_http_spec.rb +12 -0
- data/spec/acceptance/shared/callbacks.rb +2 -1
- data/spec/acceptance/shared/request_expectations.rb +7 -0
- data/spec/acceptance/shared/returning_declared_responses.rb +36 -15
- data/spec/acceptance/shared/stubbing_requests.rb +40 -0
- data/spec/support/webmock_server.rb +1 -0
- data/spec/unit/request_pattern_spec.rb +119 -3
- data/spec/unit/response_spec.rb +22 -18
- data/spec/unit/util/query_mapper_spec.rb +7 -0
- data/spec/unit/util/uri_spec.rb +74 -2
- data/spec/unit/webmock_spec.rb +54 -5
- data/test/test_webmock.rb +6 -0
- data/webmock.gemspec +10 -2
- metadata +53 -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
|
477
|
+
describe "using #reset" do
|
467
478
|
before do
|
468
479
|
@curl = Curl::Easy.new
|
469
480
|
@curl.url = "http://example.com"
|
470
|
-
|
471
|
-
|
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
|
487
|
+
it "should clear all memoized response fields" do
|
476
488
|
@curl.reset
|
477
|
-
expect(@curl
|
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
|
@@ -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,57 @@ 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
|
73
|
+
|
74
|
+
context 'when used in a streaming mode' do
|
75
|
+
let(:webmock_server_url) {"http://#{WebMockServer.instance.host_with_port}/"}
|
76
|
+
let(:result_chunks) { [] }
|
77
|
+
|
78
|
+
def manticore_streaming_get
|
79
|
+
Manticore.get(webmock_server_url).tap do |req|
|
80
|
+
req.on_success do |response|
|
81
|
+
response.body do |chunk|
|
82
|
+
result_chunks << chunk
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'when connections are allowed' do
|
89
|
+
it 'works' do
|
90
|
+
WebMock.allow_net_connect!
|
91
|
+
expect { manticore_streaming_get.call }.to_not raise_error
|
92
|
+
expect(result_chunks).to_not be_empty
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'when stubbed' do
|
97
|
+
it 'works' do
|
98
|
+
stub_body = 'hello!'
|
99
|
+
stub_request(:get, webmock_server_url).to_return(body: stub_body)
|
100
|
+
expect { manticore_streaming_get.call }.to_not raise_error
|
101
|
+
expect(result_chunks).to eq [stub_body]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
54
105
|
end
|
55
106
|
end
|
56
107
|
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["
|
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["
|
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
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
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
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
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
|
@@ -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
|