diff options
author | Xavier Noria <fxn@hashref.com> | 2013-03-28 10:04:39 +0100 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2013-03-28 10:04:39 +0100 |
commit | 341e61154715c7e0f9f4eee7dd90580202735db7 (patch) | |
tree | ef56a826149c4f9803278a498c170ddf439e232b /activesupport | |
parent | 0417bc83164422119ab2dc4da92ec6ddff5a3d2f (diff) | |
download | rails-341e61154715c7e0f9f4eee7dd90580202735db7.tar.gz rails-341e61154715c7e0f9f4eee7dd90580202735db7.tar.bz2 rails-341e61154715c7e0f9f4eee7dd90580202735db7.zip |
determine_constant_from_test_name does not swallow NoMethodErrors [Yves Senn]
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/testing/constant_lookup.rb | 2 | ||||
-rw-r--r-- | activesupport/test/testing/constant_lookup_test.rb | 10 |
2 files changed, 12 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/testing/constant_lookup.rb b/activesupport/lib/active_support/testing/constant_lookup.rb index 52bfeb7179..1b2a75c35d 100644 --- a/activesupport/lib/active_support/testing/constant_lookup.rb +++ b/activesupport/lib/active_support/testing/constant_lookup.rb @@ -38,6 +38,8 @@ module ActiveSupport begin constant = names.join("::").constantize break(constant) if yield(constant) + rescue NoMethodError # subclass of NameError + raise rescue NameError # Constant wasn't found, move on ensure diff --git a/activesupport/test/testing/constant_lookup_test.rb b/activesupport/test/testing/constant_lookup_test.rb index 19280ba74a..aca2951450 100644 --- a/activesupport/test/testing/constant_lookup_test.rb +++ b/activesupport/test/testing/constant_lookup_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'dependencies_test_helpers' class Foo; end class Bar < Foo @@ -10,6 +11,7 @@ module FooBar; end class ConstantLookupTest < ActiveSupport::TestCase include ActiveSupport::Testing::ConstantLookup + include DependenciesTestHelpers def find_foo(name) self.class.determine_constant_from_test_name(name) do |constant| @@ -56,4 +58,12 @@ class ConstantLookupTest < ActiveSupport::TestCase assert_nil find_module("DoesntExist::Nadda::Nope") assert_nil find_module("DoesntExist::Nadda::Nope::NotHere") end + + def test_does_not_swallow_exception_on_no_method_error + assert_raises(NoMethodError) { + with_autoloading_fixtures { + self.class.determine_constant_from_test_name("RaisesNoMethodError") + } + } + end end |