在开发中进行黄瓜测试时,是否可以关闭 ActionMailer 电子邮件? [英] Is it possible to turn off ActionMailer emails when cucumber testing is happening on development?

查看:35
本文介绍了在开发中进行黄瓜测试时,是否可以关闭 ActionMailer 电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

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

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']
                                           }
  ...

谢谢

推荐答案

 config.action_mailer.delivery_method = :test

就在测试之前

ActionMailer::Base.delivery_method = :test

这篇关于在开发中进行黄瓜测试时,是否可以关闭 ActionMailer 电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆