Browse files

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
  • Loading branch information...
1 parent 44c9489 commit 98f0cab3965bf5f373182ee62c20c3d94fb47dad @yuki24 yuki24 committed Jun 24, 2014
Showing with 5 additions and 5 deletions.
  1. +2 −2 activesupport/lib/active_support/dependencies.rb
  2. +3 −3 activesupport/test/dependencies_test.rb
View
4 activesupport/lib/active_support/dependencies.rb
@@ -187,7 +187,7 @@ def const_missing(const_name)
# 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.to_s
+ raise NameError.new "#{const_name} cannot be autoloaded from an anonymous class or module", const_name
else
Object
end
@@ -516,7 +516,7 @@ def load_missing_constant(from_mod, const_name)
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__ })
raise name_error
end
View
6 activesupport/test/dependencies_test.rb
@@ -367,11 +367,11 @@ def test_non_existing_const_raises_name_error_with_fully_qualified_name
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
+ assert_equal :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
+ assert_equal :DoesNotExist, e.name
end
end
@@ -539,7 +539,7 @@ def test_const_missing_in_anonymous_modules_raises_if_the_constant_belongs_to_Ob
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
+ assert_equal :E, e.name
end
end

0 comments on commit 98f0cab

Please sign in to comment.