Reputation: 55
I have such method in my application controller
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
i have tried to stub it
allow(ApplicationController).to receive(:client_signed_in?).and_return(true)
also
allow(ApplicationController).to receive(:@client_signed_in).and_return(true)
but in both cases it have returned nil
how to fix it?
Upvotes: 3
Views: 1850
Reputation: 3175
try using
allow(controller).to receive(:client_signed_in?).and_return(true)
Or
allow_any_instance_of(ApplicationController).to receive(:client_signed_in?).and_return(true)
Upvotes: 0
Reputation: 1900
Try this one:
allow_any_instance_of(ApplicationController)
.to receive(:client_signed_in?)
.and_return(true)
The thing is that you stub method of Class, instead of object.
Upvotes: 4