在我的测试中,我确保在单独的帮助程序类中调用两个控制器方法:
controller.expects(:sign_in).with(user).returns(:ok)
controller.expects(:redirect_to).returns(:ok)
当我写我的助手类时,测试按预期工作并成功:
def call
@controller = context.controller
controller.sign_in user
controller.redirect_to remove_from_url(url)
end
但是当我改为:
def call
@controller = context.controller
controller do
sign_in user
redirect_to remove_from_url(url)
end
end
然后测试失败,正如我得到的消息:
expected exactly once, not yet invoked ...
为什么这段代码不一样?谢谢
1) controller.sign_in user
controller.redirect_to remove_from_url(url)
2) controller do
sign_in user
redirect_to remove_from_url(url)
end