Lets say I have the following code on ApplicationController :
class ApplicationController < ActionController::Base
helper_method :is_happy?
private
def is_happy?
true
end
end
and then, on my ApplicationHelper I have a method, which I would like to test like this:
def show_mood_text
return 'Happy' if is_happy?
'Sad'
end
I would like to test both cases, when is_happy? returns true and when it returns false . So, my option was to stub is_happy? method. For that, I did the following:
it 'returns Sad when when is sad' do
allow(helper).to receive(:is_happy?).and_return(false)
expect(helper.show_mood_text).to eq "Sad"
end
But when I try to run this test, I got the following error:
Failure/Error: allow(helper).to receive(:is_happy?).and_return(false)
#<ActionView::Base:0x00000000009e70> does not implement: is_happy?