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

Add regression test for NameError#name

This commit is contained in:
Arthur Neves 2014-06-20 09:55:41 -04:00
parent b36df0f6c8
commit bd3fde0931
No known key found for this signature in database
GPG key ID: 04A390FB1E433E17
2 changed files with 5 additions and 2 deletions

View file

@ -187,7 +187,7 @@ module ActiveSupport #:nodoc:
# top-level constant.
def guess_for_anonymous(const_name)
if Object.const_defined?(const_name)
raise NameError.new "#{const_name} cannot be autoloaded from an anonymous class or module", const_name
raise NameError.new "#{const_name} cannot be autoloaded from an anonymous class or module", const_name.to_s
else
Object
end

View file

@ -367,9 +367,11 @@ class DependenciesTest < ActiveSupport::TestCase
with_autoloading_fixtures do
e = assert_raise(NameError) { A::DoesNotExist.nil? }
assert_equal "uninitialized constant A::DoesNotExist", e.message
assert_equal "A::DoesNotExist", e.name
e = assert_raise(NameError) { A::B::DoesNotExist.nil? }
assert_equal "uninitialized constant A::B::DoesNotExist", e.message
assert_equal "A::B::DoesNotExist", e.name
end
end
@ -537,6 +539,7 @@ class DependenciesTest < ActiveSupport::TestCase
mod = Module.new
e = assert_raise(NameError) { mod::E }
assert_equal 'E cannot be autoloaded from an anonymous class or module', e.message
assert_equal 'E', e.name
end
end
@ -954,7 +957,7 @@ class DependenciesTest < ActiveSupport::TestCase
assert_kind_of Class, A::B # Necessary to load A::B for the test
ActiveSupport::Dependencies.mark_for_unload(A::B)
ActiveSupport::Dependencies.remove_unloadable_constants!
A::B # Make sure no circular dependency error
end
end