Skip to content
Browse files

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
  • Loading branch information...
1 parent 00d8ee8 commit 56a1bb2f1066d0c119834019916f1e4b05fffec0 @tenderlove tenderlove committed Jun 12, 2012
Showing with 15 additions and 1 deletion.
  1. +2 −1 activesupport/lib/active_support/dependencies.rb
  2. +13 −0 activesupport/test/dependencies_test.rb
View
3 activesupport/lib/active_support/dependencies.rb
@@ -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
View
13 activesupport/test/dependencies_test.rb
@@ -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'

0 comments on commit 56a1bb2

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