From b310af02c664b42f1d6e00b0c4b5618c72eefa74 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Fri, 8 Nov 2024 10:21:01 +0100 Subject: [PATCH] Fix wrong error message for unknown constant on `URI` `const_get` will raise if the constant is not found --- lib/uri/common.rb | 4 ++-- test/uri/test_common.rb | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/uri/common.rb b/lib/uri/common.rb index fe8475f..fce498b 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -52,9 +52,9 @@ def self.const_missing(const) elsif value = RFC2396_PARSER.regexp[const] warn "URI::#{const} is obsolete. Use RFC2396_PARSER.regexp[#{const.inspect}] explicitly.", uplevel: 1 if $VERBOSE value - elsif value = RFC2396_Parser.const_get(const) + elsif RFC2396_Parser.const_defined?(const) warn "URI::#{const} is obsolete. Use RFC2396_Parser::#{const} explicitly.", uplevel: 1 if $VERBOSE - value + RFC2396_Parser.const_get(const) else super end diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb index 176efb8..b086ffc 100644 --- a/test/uri/test_common.rb +++ b/test/uri/test_common.rb @@ -14,7 +14,8 @@ def test_fallback_constants orig_verbose = $VERBOSE $VERBOSE = nil - assert_raise(NameError) { URI::FOO } + e = assert_raise(NameError) { URI::FOO } + assert_equal(e.message, "uninitialized constant URI::FOO") assert_equal URI::ABS_URI, URI::RFC2396_PARSER.regexp[:ABS_URI] assert_equal URI::PATTERN, URI::RFC2396_Parser::PATTERN