summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2025-12-07 12:31:42 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2025-12-07 23:20:25 +0900
commitdb6071b5216ac58976f8ab8181ff6eab02dfa8be (patch)
tree28467413f7acbaec0e4820128fc290b8103d82d2
parenta8a188e1fc8568185c2ca460b5a2e800e9cac4bd (diff)
[ruby/pathname] Raise the previous message
Fix ruby/pathname#75. https://github.com/ruby/pathname/commit/5ba967b274
-rw-r--r--pathname_builtin.rb2
-rw-r--r--test/pathname/test_pathname.rb2
2 files changed, 3 insertions, 1 deletions
diff --git a/pathname_builtin.rb b/pathname_builtin.rb
index 17299d4291..878603d4d6 100644
--- a/pathname_builtin.rb
+++ b/pathname_builtin.rb
@@ -213,6 +213,8 @@ class Pathname
#
def initialize(path)
@path = File.path(path).dup
+ rescue TypeError => e
+ raise e.class, "Pathname.new requires a String, #to_path or #to_str", cause: nil
end
#
diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb
index 10ab154220..3114d1458d 100644
--- a/test/pathname/test_pathname.rb
+++ b/test/pathname/test_pathname.rb
@@ -486,7 +486,7 @@ class TestPathname < Test::Unit::TestCase
assert_equal(p1, p2)
obj = Object.new
- assert_raise(TypeError) { Pathname.new(obj) }
+ assert_raise_with_message(TypeError, /#to_path or #to_str/) { Pathname.new(obj) }
obj = Object.new
def obj.to_path; "a/path"; end