ruby on rails - Using rspec to test ActionMailer with should_receive -
i have rspec test this:
it "should ..." # mailer = mock # mailer.should_receive(:deliver) mailer.should_receive(:notification_to_sender)#.and_return(mailer) visit transactions_path expect page.should_not have_css("table#transactions_list tbody tr") find('#some_button').click page.should have_css("table#transactions_list tbody tr", :count => 1) end.to change{transaction.count}.by(1) end if remove commented pieces @ top, test passes. commented sections in place (how i'd expect write it) test fails.
i got commented pieces off of googling around net, don't understand it's doing or why fixes it. seems there should cleaner way test emails without this.
can shed light? thanks!
i'm using rails 3 , rspec-rails 2.10.1
i think want instance of mailer receive notification_to_sender not class. rails api
you never instantiate mailer class. rather, delivery instance methods automatically wrapped in class methods start word deliver_ followed name of mailer method deliver. signup_notification method defined above delivered invoking notifier.deliver_signup_notification.
therefore use
mailer.any_instance.should_receive(:notification_to_sender) also, if need last delivered message, use
actionmailer::base.deliveries.last i think should solve problem.
Comments
Post a Comment