[rspec-users] Rspec with ActionMailer and .deliver

Chris Mear chrismear at gmail.com
Tue Aug 16 18:18:02 EDT 2011


On 16 Aug 2011, at 17:30, Jason R. wrote:

> Chris M. wrote in post #1014770:
>> CurriculumCommentMailer.should_receive(:comment_update).and_return(double("mailer").stub(:deliver))
>> 
>> That's odd -- I would expect that second version to work if the first
>> version is working. What error did you get? Was it the same "undefined
>> method `deliver' for nil:NilClass" as before?
> 
> It was giving this error:
> NoMethodError: undefined method `deliver' for
> #<RSpec::Mocks::MessageExpectation:0x10542bb88>
> 
> But, I changed the test to this and it works fine:
> CurriculumCommentMailer.should_receive(:comment_update).and_return(double("mailer",
> :deliver => true))

Ah, of course! Because #stub doesn't return the object whose method you're stubbing, it returns a message expectation. I should have spotted that…

Chris



More information about the rspec-users mailing list