Skip to content

Commit

Permalink
Fixes #828 by changing URIAddressablePattern#matches_with_variations?…
Browse files Browse the repository at this point in the history
… to include variations without the scheme as well
  • Loading branch information
eikes committed Jul 18, 2019
1 parent 37f4d1a commit 8b14148
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
3 changes: 1 addition & 2 deletions lib/webmock/request_pattern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ def to_s
def matches_with_variations?(uri)
normalized_template = Addressable::Template.new(WebMock::Util::URI.heuristic_parse(@pattern.pattern))

WebMock::Util::URI.variations_of_uri_as_strings(uri, only_with_scheme: true)
.any? { |u| normalized_template.match(u) }
WebMock::Util::URI.variations_of_uri_as_strings(uri).any? { |u| normalized_template.match(u) }
end
end

Expand Down
34 changes: 32 additions & 2 deletions spec/unit/util/uri_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'spec_helper'


URIS_WITHOUT_PATH_OR_PARAMS =
[
"www.example.com",
Expand Down Expand Up @@ -65,7 +64,6 @@
"http://www.example.com:88/"
].sort


URIS_FOR_HTTPS =
[
"https://www.example.com",
Expand All @@ -74,6 +72,25 @@
"https://www.example.com:443/"
].sort

URIS_FOR_LOCALHOST =
[
"localhost",
"localhost/",
"localhost:80",
"localhost:80/",
"http://localhost",
"http://localhost/",
"http://localhost:80",
"http://localhost:80/"
].sort

URIS_WITH_SCHEME =
[
"http://www.example.com",
"http://www.example.com/",
"http://www.example.com:80",
"http://www.example.com:80/"
].sort

describe WebMock::Util::URI do

Expand Down Expand Up @@ -115,6 +132,19 @@
end
end

it "should find all variations of the same uri for all variations of host names uris without a period" do
URIS_FOR_LOCALHOST.each do |uri|
expect(WebMock::Util::URI.variations_of_uri_as_strings(uri).sort).to eq(URIS_FOR_LOCALHOST)
end
end

it "should find all variations of the same uri with scheme for all variations when only_with_scheme is true" do
URIS_WITHOUT_PATH_OR_PARAMS.each do |uri|
variations_of_uri_with_scheme = WebMock::Util::URI.variations_of_uri_as_strings(uri, only_with_scheme: true)
expect(variations_of_uri_with_scheme.sort).to eq(URIS_WITH_SCHEME)
end
end

end

describe "normalized uri equality" do
Expand Down

0 comments on commit 8b14148

Please sign in to comment.