Rails 2.3.x-如何在功能测试(无RSpec)中添加辅助方法(从视图调用)?
|
请不要告诉我“搜索更多”或其他内容导致所有类似问题的解决方案失败。
简单:
我有功能测试。我想做一个简单的获取,看看是否呈现适当的内容
测试“如果用户应该看到标题则显示标题”
得到:index
assert_match / headline /,response.body
结束
测试“如果用户不应该看到标题,则不显示标题”
得到:index
assert_no_match / headline /,response.body
结束
和一个简单的视图
<%如果show_headline?(arg)%>
标题
<%结束%>
和一个助手:
模块TheHelper
def show_headline?(arg)
arg吗? hard_code_logic:even_harder_logic
结束
结束
所以我需要做的是测试:
测试“如果用户应该看到标题则显示标题”
Something.stubs(:show_headline?)。returns(true)
得到:index
assert_match / headline /,response.body
结束
测试“如果用户不应该看到标题,则不显示标题”
Something.stubs(:show_headline?)。returns(false)
得到:index
assert_no_match / headline /,response.body
结束
问题是什么是东西?我想存根,因为我已经在单元/助手中测试了助手。
将获取帮助器模块重新混合到控制器类之后。请不要给我其他答案的链接,我读了它们(但是我当然可能读错了它们),它们对我不起作用。我在Mocha 0.9.8中使用Rails 2.3.10。
无效的事情:
TheController.any_instance.stubs(:show_headline?)
ActionView :: Base.any_instance ...
@ controller.stubs ...
更新:
唯一有效的模拟是:
<%self.stubs(:show_headline?)。返回值(true)>%
<%如果show_headline?(arg)%>
标题
<%结束%>
但是我当然不会用...也许这是一个线索
没有找到相关结果
已邀请:
0 个回复