简体   繁体   English

使用RSpec和Action Mailer进行测试:清除排队的电子邮件?

[英]Testing with RSpec and Action Mailer: Clearing enqueued emails?

The Active Job Test Helper provides the helpful method, clear_enqueued_jobs. 活动作业测试助手提供了有用的方法clear_enqueued_jobs。

Is there an equivalent for Action Mailer to clear enqueued emails? Action Mailer是否可以清除排队的电子邮件?

Yes you can configure rspec to clear the mailers before each test like: 是的,您可以将rspec配置为在每次测试之前清除邮件,例如:

RSpec.configure do |config|
  config.before(:each) do
    ActionMailer::Base.deliveries.clear
  end
end

In case of enqueue mails, Active Job Test Helper is included in ActiveMailer::TestHelper so you should be able to use the clear_enqueued_jobs method too. 对于入队邮件,ActiveMailer :: TestHelper中包含Active Job Test Helper,因此您也应该能够使用clear_enqueued_jobs方法。

Source: https://github.com/rails/rails/blob/94b5cd3a20edadd6f6b8cf0bdf1a4d4919df86cb/actionmailer/lib/action_mailer/test_helper.rb#L9 来源: https : //github.com/rails/rails/blob/94b5cd3a20edadd6f6b8cf0bdf1a4d4919df86cb/actionmailer/lib/action_mailer/test_helper.rb#L9

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM