【发布时间】:2021-08-17 18:27:28
【问题描述】:
我们可以检查enqueued_jobs.length,前提是电子邮件是唯一可能的后台作业类型。
it 'sends exactly one, particular email' do
expect { post :create }.to(
# First, we can check about the particular email we care about.
have_enqueued_mail(MyMailer, :my_particular_email)
)
# But we also have to check that no other email was sent.
expect(ActiveJob::Base.queue_adapter.enqueued_jobs.length).to eq(1)
end
有没有更好的方法来断言:
-
MyMailer.my_particular_email已入队, - 没有其他电子邮件入队,
- 我们不在乎是否有其他非电子邮件后台作业入队
【问题讨论】:
标签: ruby-on-rails ruby rspec rspec-rails rails-activejob