Posts

Showing posts from April, 2017

Verifying Doubles with ActionMailer in Rails 4

Verifying doubles came out in RSpec 3, and it’s something that always sounded like such a brilliant yet obvious idea - make sure methods you stub actually exist. One friend in particular really stressed how many times this could have saved his tests from false positives. Sure, I thought, but usually I’d just modify something in the real code or modify the expectation to make sure it broke/worked in predictable ways, and move on. Then along came the perfect scenario while working on a little side project. Below is the original spec and the corresponding controller method it's testing. (Things aren't especially DRY and a bunch of expectations are crammed into a single test to make things more explicit for this post.) # spec it 'sends the admin a message about a new order' do   controller.stub(:params).and_return(fake_full_params)   expect(AdminMailer).to receive(:order_confirmation).with(fake_email_params).and_return(Mail::Message.new)   allow...