Jar*_*eck 1 ruby rspec ruby-on-rails rspec-rails rails-activejob
我们可以检查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
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来断言:
MyMailer.my_particular_email已排队,我相信once会与这个匹配器一起工作。
expect {
post :create
}.to have_enqueued_mail(MyMailer, :my_particular_email).once
Run Code Online (Sandbox Code Playgroud)