Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make dependencies.rb add a name to NameError

  • Loading branch information...
commit 4588b62e268f35fe253a65911150cd92f397da40 1 parent 5472080
@arthurnn arthurnn authored yuki24 committed
View
3  activesupport/CHANGELOG.md
@@ -1,3 +1,6 @@
+* Make Dependencies pass a name to NameError error.
+ *arthurnn*, *Yuki Nishijima*
+
* Fixed precision error in NumberHelper when using Rationals.
before:
View
8 activesupport/lib/active_support/dependencies.rb
@@ -186,7 +186,7 @@ def const_missing(const_name)
# and we assume therefore the user wants to refer to a top-level constant.
def guess_for_anonymous(const_name)
if Object.const_defined?(const_name)
- raise NameError, "#{const_name} cannot be autoloaded from an anonymous class or module"
+ raise NameError.new "#{const_name} cannot be autoloaded from an anonymous class or module", const_name
else
Object
end
@@ -515,9 +515,9 @@ def load_missing_constant(from_mod, const_name)
end
end
- raise NameError,
- "uninitialized constant #{qualified_name}",
- caller.reject { |l| l.starts_with? __FILE__ }
+ 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
# Remove the constants that have been autoloaded, and those that have been
View
5 activesupport/test/dependencies_test.rb
@@ -367,9 +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 :DoesNotExist, e.name
e = assert_raise(NameError) { A::B::DoesNotExist.nil? }
assert_equal "uninitialized constant A::B::DoesNotExist", e.message
+ assert_equal :DoesNotExist, e.name
end
end
@@ -537,6 +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
end
end
@@ -954,7 +957,7 @@ def test_access_unloaded_constants_for_reload
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
Please sign in to comment.
Something went wrong with that request. Please try again.