Skip to content

Commit 00bd15a

Browse files
committed
Merge branch 'ixti-fix-request-pattern-regression'
2 parents d451d65 + 160788d commit 00bd15a

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

lib/webmock/request_pattern.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ def create_uri_pattern(uri)
8686
URICallablePattern.new(uri)
8787
elsif uri.is_a?(::URI::Generic)
8888
URIStringPattern.new(uri.to_s)
89-
elsif uri.is_a?(String)
90-
URIStringPattern.new(uri)
89+
elsif uri.respond_to?(:to_str)
90+
URIStringPattern.new(uri.to_str)
9191
else
92-
raise ArgumentError.new("URI should be a String, Regexp, Addressable::Template or a callable object. Got: #{uri.class}")
92+
raise ArgumentError.new("URI should be a String, Regexp, Addressable::Template, a callable object, or respond to #to_str. Got: #{uri.class}")
9393
end
9494
end
9595
end

spec/unit/request_pattern_spec.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,42 @@ def match(request_signature)
376376
end
377377
end
378378

379+
describe "when uri is described as Addressable::URI" do
380+
it "should match request query params" do
381+
expect(WebMock::RequestPattern.new(:get, Addressable::URI.parse("www.example.com"), query: {"a" => ["b", "c"]})).
382+
to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
383+
end
384+
385+
it "should not match request query params if params don't match" do
386+
expect(WebMock::RequestPattern.new(:get, Addressable::URI.parse("www.example.com"), query: {"x" => ["b", "c"]})).
387+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
388+
end
389+
390+
it "should match when query params are declared as HashIncluding matcher matching params" do
391+
expect(WebMock::RequestPattern.new(:get, Addressable::URI.parse("www.example.com"),
392+
query: WebMock::Matchers::HashIncludingMatcher.new({"a" => ["b", "c"]}))).
393+
to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
394+
end
395+
396+
it "should not match when query params are declared as HashIncluding matcher not matching params" do
397+
expect(WebMock::RequestPattern.new(:get, Addressable::URI.parse("www.example.com"),
398+
query: WebMock::Matchers::HashIncludingMatcher.new({"x" => ["b", "c"]}))).
399+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
400+
end
401+
402+
it "should match when query params are declared as RSpec HashIncluding matcher matching params" do
403+
expect(WebMock::RequestPattern.new(:get, Addressable::URI.parse("www.example.com"),
404+
query: RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => ["b", "c"]}))).
405+
to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
406+
end
407+
408+
it "should not match when query params are declared as RSpec HashIncluding matcher not matching params" do
409+
expect(WebMock::RequestPattern.new(:get, Addressable::URI.parse("www.example.com"),
410+
query: RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => ["b", "d"]}))).
411+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
412+
end
413+
end
414+
379415
describe "when uri is described as string" do
380416
it "should match when query params are the same as declared in hash" do
381417
expect(WebMock::RequestPattern.new(:get, "www.example.com", query: {"a" => ["b", "c"]})).

0 commit comments

Comments
 (0)