1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix a bug where NameError#name returns a qualified name in string

Ruby's original behaviour is that :

  * It only returns a const name, not a qualified aname
  * It returns a symbol, not a string
This commit is contained in:
Yuki Nishijima 2014-06-24 10:07:29 -07:00
parent 44c9489a68
commit 98f0cab396
2 changed files with 5 additions and 5 deletions

View file

@ -187,7 +187,7 @@ module ActiveSupport #:nodoc:
# top-level constant. # top-level constant.
def guess_for_anonymous(const_name) def guess_for_anonymous(const_name)
if Object.const_defined?(const_name) if Object.const_defined?(const_name)
raise NameError.new "#{const_name} cannot be autoloaded from an anonymous class or module", const_name.to_s raise NameError.new "#{const_name} cannot be autoloaded from an anonymous class or module", const_name
else else
Object Object
end end
@ -516,7 +516,7 @@ module ActiveSupport #:nodoc:
end end
end end
name_error = NameError.new("uninitialized constant #{qualified_name}", qualified_name) name_error = NameError.new("uninitialized constant #{qualified_name}", const_name)
name_error.set_backtrace(caller.reject {|l| l.starts_with? __FILE__ }) name_error.set_backtrace(caller.reject {|l| l.starts_with? __FILE__ })
raise name_error raise name_error
end end

View file

@ -367,11 +367,11 @@ class DependenciesTest < ActiveSupport::TestCase
with_autoloading_fixtures do with_autoloading_fixtures do
e = assert_raise(NameError) { A::DoesNotExist.nil? } e = assert_raise(NameError) { A::DoesNotExist.nil? }
assert_equal "uninitialized constant A::DoesNotExist", e.message assert_equal "uninitialized constant A::DoesNotExist", e.message
assert_equal "A::DoesNotExist", e.name assert_equal :DoesNotExist, e.name
e = assert_raise(NameError) { A::B::DoesNotExist.nil? } e = assert_raise(NameError) { A::B::DoesNotExist.nil? }
assert_equal "uninitialized constant A::B::DoesNotExist", e.message assert_equal "uninitialized constant A::B::DoesNotExist", e.message
assert_equal "A::B::DoesNotExist", e.name assert_equal :DoesNotExist, e.name
end end
end end
@ -539,7 +539,7 @@ class DependenciesTest < ActiveSupport::TestCase
mod = Module.new mod = Module.new
e = assert_raise(NameError) { mod::E } e = assert_raise(NameError) { mod::E }
assert_equal 'E cannot be autoloaded from an anonymous class or module', e.message assert_equal 'E cannot be autoloaded from an anonymous class or module', e.message
assert_equal 'E', e.name assert_equal :E, e.name
end end
end end