I'm in the process of migrating from Rails 2 with rspec 1 to Rails 3 with
rspec 2, the process has been going pretty well, however, today I came
across an issue that I wanted to share.
I have a controller that sends out an email through a mailer.
Rails 2
code: CurriculumCommentMailer.deliver_comment_update(@curriculum_comment,
"created")
Rails 3 code: CurriculumCommentMailer.comment_update(@curriculum_comment,
"created").deliver
In my controller spec, I test to see if the email was sent out.
Rspec 1
it "emails the comment" do
CurriculumCommentMailer.should_receive(:deliver_comment_update)
post :create, :curriculum_comment =>
@curriculum_comment.attributes
end
Rspec 2
In my opinion, I expected the following code to work
it "emails the comment" do
CurriculumCommentMailer.should_receive(:comment_update)
post :create, :curriculum_comment =>
@curriculum_comment.attributes
end
However it does not. Since I'm calling should_receive on an object that
isn't a stub/mock/double, I expected should_receive to call the underlying
code, it does not so .deliver is called on a NilClass. (undefined method
`deliver' for nil:NilClass)
The following code does work
mailer = double("mailer")
mailer.stub(:deliver)
CurriculumCommentMailer.should_receive(:comment_update).and_return(mailer)
Whereas I expected this code to work, but it does not either
CurriculumCommentMailer.should_receive(:comment_update).and_return(double("mailer").stub(:deliver))
thanks for your advice,
Todd
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users