Skip to content

Commit 6f44d3d

Browse files
committed
Fix the message for unexpected argument
Use just `self` instead of `self.class`, in `URI::Generic.build`. Since this is a class method, `self.class` is always `Class` even in inherited sub classes, and does not have `#component` method.
1 parent d79b3f5 commit 6f44d3d

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/uri/generic.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ def self.build(args)
126126
end
127127
end
128128
else
129-
component = self.class.component rescue ::URI::Generic::COMPONENT
129+
component = self.component rescue ::URI::Generic::COMPONENT
130130
raise ArgumentError,
131-
"expected Array of or Hash of components of #{self.class} (#{component.join(', ')})"
131+
"expected Array of or Hash of components of #{self} (#{component.join(', ')})"
132132
end
133133

134134
tmp << nil

test/uri/test_generic.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,19 @@ def test_build
868868
assert_equal("http://[::1]/bar/baz", u.to_s)
869869
assert_equal("[::1]", u.host)
870870
assert_equal("::1", u.hostname)
871+
872+
assert_raise_with_message(ArgumentError, /URI::Generic/) {
873+
URI::Generic.build(nil)
874+
}
875+
876+
c = Class.new(URI::Generic) do
877+
def self.component; raise; end
878+
end
879+
expected = /\(#{URI::Generic::COMPONENT.join(', ')}\)/
880+
message = "fallback to URI::Generic::COMPONENT if component raised"
881+
assert_raise_with_message(ArgumentError, expected, message) {
882+
c.build(nil)
883+
}
871884
end
872885

873886
def test_build2

0 commit comments

Comments
 (0)