Skip to content

Commit

Permalink
raise the same exception in order to keep path info
Browse files Browse the repository at this point in the history
Ruby 2.0.0 implements LoadError#path, but newly raised load errors will
not contain the path information.  Replace the error message, copy
blame, and rereaise the same exception object
  • Loading branch information
tenderlove committed Jun 12, 2012
1 parent 00d8ee8 commit 56a1bb2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion activesupport/lib/active_support/dependencies.rb
Expand Up @@ -305,7 +305,8 @@ def depend_on(file_name, message = "No such file to load -- %s.rb")
require_or_load(path || file_name)
rescue LoadError => load_error
if file_name = load_error.message[/ -- (.*?)(\.rb)?$/, 1]
raise LoadError.new(message % file_name).copy_blame!(load_error)
load_error.message.replace(message % file_name)
load_error.copy_blame!(load_error)
end
raise
end
Expand Down
13 changes: 13 additions & 0 deletions activesupport/test/dependencies_test.rb
Expand Up @@ -39,6 +39,19 @@ def with_autoloading_fixtures(&block)
with_loading 'autoloading_fixtures', &block
end

def test_depend_on_path
skip "LoadError#path does not exist" if RUBY_VERSION < '2.0.0'

expected = assert_raises(LoadError) do
Kernel.require 'omgwtfbbq'
end

e = assert_raises(LoadError) do
ActiveSupport::Dependencies.depend_on 'omgwtfbbq'
end
assert_equal expected.path, e.path
end

def test_tracking_loaded_files
require_dependency 'dependencies/service_one'
require_dependency 'dependencies/service_two'
Expand Down

0 comments on commit 56a1bb2

Please sign in to comment.