mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Added more informative exception when using helper :some_helper and the helper requires another file that fails, you'll get an error message tells you what file actually failed to load, rather than falling back on assuming it was the helper file itself #346 [dblack]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@250 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
f408fcd610
commit
a04b1f3d8a
3 changed files with 17 additions and 3 deletions
|
@ -1,5 +1,8 @@
|
|||
*SVN*
|
||||
|
||||
* Added more informative exception when using helper :some_helper and the helper requires another file that fails, you'll get an
|
||||
error message tells you what file actually failed to load, rather than falling back on assuming it was the helper file itself #346 [dblack]
|
||||
|
||||
* Fixed regression with Base#reset_session that wouldn't use the the DEFAULT_SESSION_OPTIONS [adam@the-kramers.net]
|
||||
|
||||
* Fixed error rendering of rxml documents to not just swallow the exception and return 0 (still not guessing the right line, but hey)
|
||||
|
|
|
@ -55,8 +55,13 @@ module ActionController #:nodoc:
|
|||
class_name = Inflector.camelize(file_name)
|
||||
begin
|
||||
require_dependency(file_name)
|
||||
rescue LoadError
|
||||
raise LoadError, "Missing helper file helpers/#{file_name}.rb"
|
||||
rescue LoadError => load_error
|
||||
requiree = / -- (.*?)(\.rb)?$/.match(load_error).to_a[1]
|
||||
if requiree == file_name
|
||||
raise LoadError, "Missing helper file helpers/#{file_name}.rb"
|
||||
else
|
||||
raise LoadError, "Can't load file: #{requiree}"
|
||||
end
|
||||
end
|
||||
raise ArgumentError, "Missing #{class_name} module in helpers/#{file_name}.rb" unless Object.const_defined?(class_name)
|
||||
add_template_helper(Object.const_get(class_name))
|
||||
|
|
|
@ -70,6 +70,12 @@ class HelperTest < Test::Unit::TestCase
|
|||
assert_raise(LoadError) { @controller_class.helper :missing }
|
||||
end
|
||||
|
||||
def test_declare_missing_file_from_helper
|
||||
require 'broken_helper'
|
||||
rescue LoadError => e
|
||||
assert_nil /\bbroken_helper\b/.match(e.to_s)[1]
|
||||
end
|
||||
|
||||
def test_helper_block
|
||||
assert_nothing_raised {
|
||||
@controller_class.helper { def block_helper_method; end }
|
||||
|
@ -107,4 +113,4 @@ class HelperTest < Test::Unit::TestCase
|
|||
self.class.const_set('TestHelper', helper_module)
|
||||
$VERBOSE = old_verbose
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue