我的应用程序控制器中有这样的方法
friends
我试图将其存根
before_filter :client_signed_in?
def client_signed_in?
if cookies.signed[:client_id]
@current_client = Client.find_by_id cookies.signed[:client_id]
@client_signed_in = true unless @current_client.nil?
end
end
也
allow(ApplicationController).to receive(:client_signed_in?).and_return(true)
但在这两种情况下都返回了allow(ApplicationController).to receive(:@client_signed_in).and_return(true)
如何解决?
答案 0 :(得分:0)
尝试使用
allow(controller).to receive(:client_signed_in?).and_return(true)
或者
allow_any_instance_of(ApplicationController).to receive(:client_signed_in?).and_return(true)
答案 1 :(得分:0)
试试这个:
allow_any_instance_of(ApplicationController)
.to receive(:client_signed_in?)
.and_return(true)
问题在于你是Class的方法而不是对象。