提交 7520770c 编写于 作者: J Jeremy Kemper

Don't require AV::TestCases to have a helper class. Only include the helper...

Don't require AV::TestCases to have a helper class. Only include the helper class in setup if it hasn't been already.
上级 c5d37c06
require 'active_support/test_case'
module ActionView
class NonInferrableHelperError < ActionViewError
def initialize(name)
super "Unable to determine the helper to test from #{name}. " +
"You'll need to specify it using tests YourHelper in your " +
"test case definition"
end
end
class TestCase < ActiveSupport::TestCase
class_inheritable_accessor :helper_class
@@helper_class = nil
......@@ -29,7 +21,7 @@ def helper_class
def determine_default_helper_class(name)
name.sub(/Test$/, '').constantize
rescue NameError
raise NonInferrableHelperError.new(name)
nil
end
end
......@@ -42,7 +34,9 @@ def determine_default_helper_class(name)
setup :setup_with_helper_class
def setup_with_helper_class
self.class.send(:include, helper_class)
if helper_class && !self.class.ancestors.include?(helper_class)
self.class.send(:include, helper_class)
end
end
class TestController < ActionController::Base
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册