RSpec stub helper method in controller spec

萝らか妹 提交于 2019-12-02 23:56:49

You can stub it from the controller spec:

controller.stub!(:signed_in?).and_return(true) # emulate signed in user
controller.stub!(:signed_in?).and_return(false) # emulate unsigned user

Object 'controller' is predefined in a controller specs.

UPDATE:

With RSpec 3 syntax:

allow(controller).to receive(:signed_in?).and_return(true)
allow(controller).to receive(:signed_in?).and_return(false)

Thanks to @jakeonrails for reminding.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!