Skip to content

Commit db6071b

Browse files
committed
[ruby/pathname] Raise the previous message
Fix ruby/pathname#75. ruby/pathname@5ba967b274
1 parent a8a188e commit db6071b

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

pathname_builtin.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ class Pathname
213213
#
214214
def initialize(path)
215215
@path = File.path(path).dup
216+
rescue TypeError => e
217+
raise e.class, "Pathname.new requires a String, #to_path or #to_str", cause: nil
216218
end
217219

218220
#

test/pathname/test_pathname.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ def test_initialize
486486
assert_equal(p1, p2)
487487

488488
obj = Object.new
489-
assert_raise(TypeError) { Pathname.new(obj) }
489+
assert_raise_with_message(TypeError, /#to_path or #to_str/) { Pathname.new(obj) }
490490

491491
obj = Object.new
492492
def obj.to_path; "a/path"; end

0 commit comments

Comments
 (0)