Cucumber 为什么可以';我不能在Rails 5中测试电子邮件发送吗?

Cucumber 为什么可以';我不能在Rails 5中测试电子邮件发送吗?,cucumber,ruby-on-rails-5,actionmailer,Cucumber,Ruby On Rails 5,Actionmailer,我尝试在一个简单的Rails 5应用程序中使用和测试电子邮件发送,并使用以下简单案例。你能帮我看看为什么它不起作用吗 app/mailers/test_mailer.rb class TestMailer < ApplicationMailer def welcome_email @greeting = "Hi" mail to: "to@example.org", subject: 'welcome!' end end 功能/步骤/测试步骤.rb Given "

我尝试在一个简单的Rails 5应用程序中使用和测试电子邮件发送,并使用以下简单案例。你能帮我看看为什么它不起作用吗

app/mailers/test_mailer.rb

class TestMailer < ApplicationMailer
  def welcome_email
    @greeting = "Hi"
    mail to: "to@example.org", subject: 'welcome!'
  end
end
功能/步骤/测试步骤.rb

Given "we say {string}"  do |say_it|
  puts say_it
end

Given "{int} email is in the queue"  do |mail_count|
  puts "method    : #{ActionMailer::Base.delivery_method}"
  puts "deliveries: #{ActionMailer::Base.perform_deliveries}"
  ActionMailer::Base.deliveries.count.should eq mail_count
end

Then "send an email"  do
  TestMailer.welcome_email.deliver_later
end

它不断响应队列中没有项目。

不要稍后交付,请立即交付。如果您稍后投递,您必须先运行后台作业,然后才能将邮件添加到队列中

正如我对@diabolist的响应一样,我必须修改Cumber测试设置以支持
:async
,而不是
:inline
。这意味着:

config/environments/test.rb

...
config.active_job.queue.adapter = :test
...
功能/支持/env.rb

...
World( ActiveJob::TestHelper )
Around() do |scenario, block|
  perform_enqueued_jobs do
    block.call
  end
end

我意识到我可能已经将测试适配器切换到了
:inline
,但这将允许我稍后进行一些队列测试-尤其是使用执行的
方法。

谢谢。你让我走上了正确的道路。我忽略了4.2->5.x将默认队列适配器切换为:async from:inline的事实,我必须正确地支持这一点。这不是答案,因为我肯定不会改变所需的功能来支持测试,但它帮助我了解了问题所在-谢谢!欢迎您,我不是建议您更改生产功能,而是建议您让您的测试以某种方式立即发送邮件。很抱歉没有说清楚。不管怎样,我很高兴能帮上忙:)啊!好啊谢谢你的澄清。
...
World( ActiveJob::TestHelper )
Around() do |scenario, block|
  perform_enqueued_jobs do
    block.call
  end
end