1
votes

I am writing tests for future functionality in my ruby on rails 4 application. After reading the RoR Guides, I found I could change the smtp settings in my config/environments/test.rb file to store emails in an array and not actually send them. After making that change I'm still receiving emails in my inbox when running my feature specs.

environments/test.rb

# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test

In production, my emails are being sent out via the Mandrill API. To double check my tests were running on the test environment, I ran: "RAILS_ENV=test rspec spec" and it still sent out emails.

feature spec

# Excerpt of feature spec
email = ActionMailer::Base.deliveries.last
email.body.raw_source.should include "Welcome!"

The above code fails with the following message:

expected to find text "Welcome!" in ""

If I'm correct, it looks like the emails aren't being store in the ActionMailer::Base.deliveries array.

1
are you using something like spring that needs to be restarted? - Doon
Where are you configuring mandrill? It might be overriding your environments/test.rb settings? - Dylan Markow
@DylanMarkow Your thought put me on the right track. Mandrill_mailer has its own offline testing interceptor. I can't seem to get it to work right now, but when/if I do- I'll come back and post the answer. - Questifer

1 Answers

1
votes

After reading more about the mandrill_mailer gem, I came across how to handle offline testing. The issue is because I'm using mandrill's API, there is no way to intercept the email with the standard SMTP intercept method of ActionMailer.

In the feature spec I added:

email = MandrillMailer::deliveries.last
expect(email).to_not be_nil

I also addded the following to spec_helper.rb

require 'mandrill_mailer/offline'