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>
This commit is contained in:
parent
f7015336f6
commit
77e45352e7
@ -82,9 +82,10 @@ def require_or_load(file_name, const_path = nil)
|
||||
# infinite loop with mutual dependencies.
|
||||
loaded << expanded
|
||||
|
||||
begin
|
||||
if load?
|
||||
log "loading #{file_name}"
|
||||
begin
|
||||
|
||||
# Enable warnings iff this file has not been loaded before and
|
||||
# warnings_on_first_load is set.
|
||||
load_args = ["#{file_name}.rb"]
|
||||
@ -95,14 +96,14 @@ def require_or_load(file_name, const_path = nil)
|
||||
else
|
||||
enable_warnings { result = load_file(*load_args) }
|
||||
end
|
||||
rescue Exception
|
||||
loaded.delete expanded
|
||||
raise
|
||||
end
|
||||
else
|
||||
log "requiring #{file_name}"
|
||||
result = require file_name
|
||||
end
|
||||
rescue Exception
|
||||
loaded.delete expanded
|
||||
raise
|
||||
end
|
||||
|
||||
# Record history *after* loading so first load gets warnings.
|
||||
history << expanded
|
||||
|
@ -691,6 +691,15 @@ def test_autoload_doesnt_shadow_no_method_error_with_absolute_constant
|
||||
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!"
|
||||
@ -753,5 +762,4 @@ def test_load_once_paths_should_behave_when_recursively_loading
|
||||
ensure
|
||||
Dependencies.load_once_paths = []
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user