Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed Dependencies so load errors are not masked behind a 'Expected x…

….rb to define X' message when mechanism is not set to :load [#87 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information...
commit 77e45352e7e947f1df1bfb8fe7d9e4e133224dd9 1 parent f701533
@tomafro tomafro authored josh committed
View
19 activesupport/lib/active_support/dependencies.rb
@@ -82,9 +82,10 @@ def require_or_load(file_name, const_path = nil)
# infinite loop with mutual dependencies.
loaded << expanded
- if load?
- log "loading #{file_name}"
- begin
+ begin
+ if load?
+ log "loading #{file_name}"
+
# Enable warnings iff this file has not been loaded before and
# warnings_on_first_load is set.
load_args = ["#{file_name}.rb"]
@@ -95,13 +96,13 @@ def require_or_load(file_name, const_path = nil)
else
enable_warnings { result = load_file(*load_args) }
end
- rescue Exception
- loaded.delete expanded
- raise
+ else
+ log "requiring #{file_name}"
+ result = require file_name
end
- else
- log "requiring #{file_name}"
- result = require file_name
+ rescue Exception
+ loaded.delete expanded
+ raise
end
# Record history *after* loading so first load gets warnings.
View
20 activesupport/test/dependencies_test.rb
@@ -673,7 +673,7 @@ def test_autoload_doesnt_shadow_no_method_error_with_relative_constant
assert !defined?(::RaisesNoMethodError), "::RaisesNoMethodError is defined but it should have failed!"
end
end
-
+
ensure
Object.class_eval { remove_const :RaisesNoMethodError if const_defined?(:RaisesNoMethodError) }
end
@@ -686,11 +686,20 @@ def test_autoload_doesnt_shadow_no_method_error_with_absolute_constant
assert !defined?(::RaisesNoMethodError), "::RaisesNoMethodError is defined but it should have failed!"
end
end
-
+
ensure
Object.class_eval { remove_const :RaisesNoMethodError if const_defined?(:RaisesNoMethodError) }
end
+ def test_autoload_doesnt_shadow_error_when_mechanism_not_set_to_load
+ with_loading 'autoloading_fixtures' do
+ Dependencies.mechanism = :require
+ 2.times do
+ assert_raise(NameError) {"RaisesNameError".constantize}
+ end
+ end
+ end
+
def test_autoload_doesnt_shadow_name_error
with_loading 'autoloading_fixtures' do
assert !defined?(::RaisesNameError), "::RaisesNameError is defined but it hasn't been referenced yet!"
@@ -714,7 +723,7 @@ def test_autoload_doesnt_shadow_name_error
ensure
Object.class_eval { remove_const :RaisesNoMethodError if const_defined?(:RaisesNoMethodError) }
end
-
+
def test_remove_constant_handles_double_colon_at_start
Object.const_set 'DeleteMe', Module.new
DeleteMe.const_set 'OrMe', Module.new
@@ -724,7 +733,7 @@ def test_remove_constant_handles_double_colon_at_start
Dependencies.remove_constant "::DeleteMe"
assert ! defined?(DeleteMe)
end
-
+
def test_load_once_constants_should_not_be_unloaded
with_loading 'autoloading_fixtures' do
Dependencies.load_once_paths = Dependencies.load_paths
@@ -737,7 +746,7 @@ def test_load_once_constants_should_not_be_unloaded
Dependencies.load_once_paths = []
Object.class_eval { remove_const :A if const_defined?(:A) }
end
-
+
def test_load_once_paths_should_behave_when_recursively_loading
with_loading 'dependencies', 'autoloading_fixtures' do
Dependencies.load_once_paths = [Dependencies.load_paths.last]
@@ -753,5 +762,4 @@ def test_load_once_paths_should_behave_when_recursively_loading
ensure
Dependencies.load_once_paths = []
end
-
end

0 comments on commit 77e4535

Please sign in to comment.
Something went wrong with that request. Please try again.