5

目前,我的本地开发环境已设置为能够发送实际电子邮件。正因为如此,交付正在进行中,并且没有任何东西保留在ActionMailer::Base.deliveries表中。是否可以在黄瓜测试中禁用电子邮件发送?如果是这样,这样做的语法是什么?还是有更好的方法来测试正在发送的电子邮件?

authentication_steps.rb:

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

应用程序/配置/开发.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']
                                           }
  ...

谢谢

4

1 回答 1

10
 config.action_mailer.delivery_method = :test

或者

就在测试之前

ActionMailer::Base.delivery_method = :test
于 2012-05-15T21:44:57.703 回答