ruby on rails - How to turn off ActionMailer in test environment? -


i'm receiving real emails when run tests rspec. i've made written in this question (i've add change environment config not send emails, no make effect @ all. i'm thinking setting replaced somewhere can't find where.

here config test env (config/enviroments/test.rb)

myapp::application.configure   config.action_mailer.delivery_method = :test   config.action_mailer.perform_deliveries = false end 

here mailers:

class applicationmailer < actionmailer::base   default from: 'hello@myapp.com'   layout 'mailer'    admin_email = 'admin@myapp.com' end  class adminmailer < applicationmailer   default to: "#{admin_email}"    def mandrill_client     @mandrill_client ||= mandrill::api.new mandrill_api_key   end    def new_user(user)     #set required params     mandrill_client.messages.send_template template_name, template_content, message   end  end 

it seems i've missed obvious. need in breaking up.

since use mandrill::api send emails, , not actionmailer, settings actionmailer have absolutely no effect on it.

you should either find corresponding setting in mandrill::api, or stub send method tests.

i suggest still use actionmailer mandrill smtp server:

config.action_mailer.smtp_settings = {   address: 'smtp.mandrillapp.com',   port: 587,   domain: rails.application.config_for(:global)['domain'],   authentication: 'plain',   enable_starttls_auto: true,   user_name: rails.application.secrets.email_provider_username,   password: rails.application.secrets.email_provider_apikey } 

Comments