for context:
class CommentObserver < ActiveRecord::Observer
def after_create(comment)
Notification.new_comment(comment).deliver
end
end
require 'spec_helper'
describe CommentObserver do
it "sends a notification mail after a new comment is created" do
@comment = Factory.build(:comment)
Notification.should_receive(:new_comment).with(@comment)
@comment.save
end
end
In this case, you want to check what is called in the notification deliver, so that when waiting is expected. The rest of the specification code is for setting the wait and starting it. Try it like this:
describe CommentObserver do
it "sends a notification mail after a new comment is created" do
@comment = Factory.build(:comment)
notification = mock(Notification)
notification.should_receive(:deliver)
Notification.stub(:new_comment).with(@comment).and_return(notification)
@comment.save
end
end
?
, , - .and_return() , should_receive nil.