未验证 提交 d1d98f3a 编写于 作者: X Xavier Noria 提交者: GitHub

Merge pull request #39116 from kamipo/fix_missing_helper_error

Fix `modules_for_helpers` to will raise `MissingHelperError`
# frozen_string_literal: true
$:.unshift File.expand_path("lib", __dir__)
$:.unshift File.expand_path("fixtures/helpers", __dir__)
$:.unshift File.expand_path("fixtures/alternate_helpers", __dir__)
ENV["TMPDIR"] = File.expand_path("tmp", __dir__)
......@@ -23,6 +21,19 @@
require "active_support/dependencies"
require "active_model"
module ActionViewTestSuiteUtils
def self.require_helpers(helpers_dirs)
Array(helpers_dirs).each do |helpers_dir|
Dir.glob("#{helpers_dir}/**/*_helper.rb") do |helper_file|
require helper_file
end
end
end
end
ActionViewTestSuiteUtils.require_helpers("#{__dir__}/fixtures/helpers")
ActionViewTestSuiteUtils.require_helpers("#{__dir__}/fixtures/alternate_helpers")
ActiveSupport::Dependencies.hook!
Thread.abort_on_exception = true
......
......@@ -79,10 +79,10 @@ def test_helpers_with_symbol
end
def test_declare_missing_helper
e = assert_raise AbstractController::Helpers::MissingHelperError do
e = assert_raise NameError do
AbstractHelpers.helper :missing
end
assert_equal "helpers/missing_helper.rb", e.path
assert_equal "uninitialized constant MissingHelper", e.message
end
def test_helpers_with_module_through_block
......@@ -109,19 +109,9 @@ def test_includes_controller_default_helper
end
class InvalidHelpersTest < ActiveSupport::TestCase
def test_controller_raise_error_about_real_require_problem
e = assert_raise(LoadError) { AbstractInvalidHelpers.helper(:invalid_require) }
assert_equal "No such file to load -- very_invalid_file_name.rb", e.message
end
def test_controller_raise_error_about_missing_helper
e = assert_raise(AbstractController::Helpers::MissingHelperError) { AbstractInvalidHelpers.helper(:missing) }
assert_equal "Missing helper file helpers/missing_helper.rb", e.message
end
def test_missing_helper_error_has_the_right_path
e = assert_raise(AbstractController::Helpers::MissingHelperError) { AbstractInvalidHelpers.helper(:missing) }
assert_equal "helpers/missing_helper.rb", e.path
e = assert_raise(NameError) { AbstractInvalidHelpers.helper(:missing) }
assert_equal "uninitialized constant MissingHelper", e.message
end
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册