mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
raise the same exception in order to keep path info
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
This commit is contained in:
parent
00d8ee8e30
commit
56a1bb2f10
2 changed files with 15 additions and 1 deletions
|
@ -305,7 +305,8 @@ module ActiveSupport #:nodoc:
|
|||
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
|
||||
|
|
|
@ -39,6 +39,19 @@ class DependenciesTest < ActiveSupport::TestCase
|
|||
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'
|
||||
|
|
Loading…
Reference in a new issue