提交 7c785592 编写于 作者: W wycats

Safely cleans up a test to avoid relying on a particular test order

上级 70916f6a
......@@ -89,16 +89,23 @@ class ATestHelperTest < ActionView::TestCase
end
test "helper class that is being tested is always included in view instance" do
self.class.helper_class.module_eval do
def render_from_helper
render :partial => 'customer', :collection => @customers
# This ensure is a hidious hack to deal with these tests bleeding
# methods between eachother
begin
self.class.helper_class.module_eval do
def render_from_helper
render :partial => 'customer', :collection => @customers
end
end
end
TestController.stubs(:controller_path).returns('test')
TestController.stubs(:controller_path).returns('test')
@customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')]
assert_match /Hello: EloyHello: Manfred/, render(:partial => 'test/from_helper')
@customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')]
assert_match /Hello: EloyHello: Manfred/, render(:partial => 'test/from_helper')
ensure
self.class.helper_class.remove_method :render_from_helper
end
end
test "no additional helpers should shared across test cases" do
......@@ -147,10 +154,16 @@ def render_from_helper
end
test "is able to make methods available to the view" do
_helpers.module_eval do
def render_from_helper; from_test_case end
# This ensure is a hidious hack to deal with these tests bleeding
# methods between eachother
begin
_helpers.module_eval do
def render_from_helper; from_test_case end
end
assert_equal 'Word!', render(:partial => 'test/from_helper')
ensure
_helpers.remove_method :render_from_helper
end
assert_equal 'Word!', render(:partial => 'test/from_helper')
end
def from_test_case; 'Word!'; end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册