问题描述
基本上,测试配置设置了它在 Rails 4 中的工作方式(将传递方法设置为测试等),除了我已替换的不推荐使用的选项之外,邮件仅使用 Deliver_now 发送,而不是 Delivery_later.Deliver_later 在开发环境中工作,即使两个环境的配置相同.
Basically, with the test config set up exactly how it worked in Rails 4 (delivery method set as test etc), aside from deprecated options which I have replaced, mail only sends with deliver_now, not deliver_later. Deliver_later works in the development environment, even when the config is identical between the two environments.
测试环境邮件程序配置:
Test environment mailer config:
config.action_mailer.delivery_method = :test
config.action_mailer.perform_deliveries = true
config.action_mailer.perform_caching = false
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
推荐答案
我有同样的问题,我转而使用断言
I have the same issue, and i have instead resorted to using assertions on
enqueued_jobs.size
断言我的邮件已排队.此外,我对使用 delivery_now 的邮件程序类进行了单元测试.
to assert my mail has been queued. Additionally i have unit tests on the mailer class where i use deliver_now.
这需要包含 ActiveJob:TestHelper
This requires including ActiveJob:TestHelper
class ActiveSupport::TestCase
include ActiveJob::TestHelper
end
这篇关于稍后交付在 Rails 5 的测试环境中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!