Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to turn off ActionMailer emails when cucumber testing is happening on development?

Currently, my local development environment is setup to be able to send out actual emails. Because of this, deliveries are being made, and nothing is kept in the ActionMailer::Base.deliveries table. Is it possible to disable email sending in cucumber tests? If so, what is the syntax to do this? Or is there a better way to test emails being sent?

authentication_steps.rb:

Then /^I should receive a confirmation email$/ do
  email = ActionMailer::Base.deliveries.last
  email.subject.should == "Welcome to our website!"
end

app/config/development.rb

  ...
  # Don't care if the mailer can't send
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.perform_deliveries    = true

  # Setup for local testing of emails using gmail test account
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {  :address => 'smtp.sendgrid.net',
                                           :port => 587,
                                           :domain => ENV['MAIL_DOMAIN'],
                                           :authentication => 'plain',
                                           :enable_starttls_auto => true,
                                           :user_name => ENV['MAIL_USERNAME'],
                                           :password => ENV['MAIL_PASSWORD']
                                           }
  ...

Thanks

like image 373
Goalie Avatar asked May 15 '12 21:05

Goalie


1 Answers

 config.action_mailer.delivery_method = :test

or

just before tests

ActionMailer::Base.delivery_method = :test
like image 198
Yuri Barbashov Avatar answered Nov 02 '22 04:11

Yuri Barbashov