Permalink
Browse files

Make dependencies.rb add a name to NameError

  • Loading branch information...
1 parent af8035d commit 61a73c21d8bef2e54d06d7e5639bf5fc9079ba44 @yuki24 yuki24 committed Jun 25, 2014
@@ -1,3 +1,6 @@
+* Make Dependencies pass a name to NameError error.
+ *arthurnn*, *Yuki Nishijima*
+
## Rails 4.0.6 (unreleased) ##
* `Hash#deep_transform_keys` and `Hash#deep_transform_keys!` now transform hashes
@@ -446,7 +446,7 @@ def load_missing_constant(from_mod, const_name)
raise ArgumentError, "A copy of #{from_mod} has been removed from the module tree but is still active!"
end
- raise NameError, "#{from_mod} is not missing constant #{const_name}!" if from_mod.const_defined?(const_name, false)
+ raise NameError.new("#{from_mod} is not missing constant #{const_name}!", const_name) if from_mod.const_defined?(const_name, false)
qualified_name = qualified_name_for from_mod, const_name
path_suffix = qualified_name.underscore
@@ -498,9 +498,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
@@ -360,12 +360,14 @@ def test_non_existing_const_raises_name_error_with_fully_qualified_name
flunk "No raise!!"
rescue NameError => e
assert_equal "uninitialized constant A::DoesNotExist", e.message
+ assert_equal :DoesNotExist, e.name
end
begin
A::B::DoesNotExist.nil?
flunk "No raise!!"
rescue NameError => e
assert_equal "uninitialized constant A::B::DoesNotExist", e.message
+ assert_equal :DoesNotExist, e.name
end
end
end
@@ -524,8 +526,9 @@ def test_const_missing_should_not_double_load
with_autoloading_fixtures do
require_dependency '././counting_loader'
assert_equal 1, $counting_loaded_times
- assert_raise(NameError) { ActiveSupport::Dependencies.load_missing_constant Object, :CountingLoader }
+ e = assert_raise(NameError) { ActiveSupport::Dependencies.load_missing_constant Object, :CountingLoader }
assert_equal 1, $counting_loaded_times
+ assert_equal :CountingLoader, e.name
end
end

0 comments on commit 61a73c2

Please sign in to comment.