Skip to content

Commit

Permalink
Raising an ArgumentError when uri is passed as Pathname object to stu…
Browse files Browse the repository at this point in the history
…b_request or assert_requested.
  • Loading branch information
bblimke committed Sep 18, 2024
1 parent 22efaba commit f651c25
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/webmock/request_pattern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ def create_uri_pattern(uri)
URIAddressablePattern.new(uri)
elsif uri.respond_to?(:call)
URICallablePattern.new(uri)
else
elsif uri.is_a?(String)
URIStringPattern.new(uri)
else
raise ArgumentError.new("URI should be a String, Regexp, Addressable::Template or a callable object. Got: #{uri.class}")
end
end

end


Expand Down
8 changes: 8 additions & 0 deletions spec/unit/request_pattern_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,14 @@ def match(request_signature)
end
end
end

describe "when uri is passed as Pathname" do
it "should raise an ArgumentError" do
expect {
WebMock::RequestPattern.new(:get, Pathname.new("www.example.com"))
}.to raise_error(ArgumentError, "URI should be a String, Regexp, Addressable::Template or a callable object. Got: Pathname")
end
end
end

describe "when matching requests with body" do
Expand Down

0 comments on commit f651c25

Please sign in to comment.