Reputation: 1123
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.
Upvotes: 1
Views: 852
Reputation: 1123
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'
Upvotes: 1