我想编写测试以检查是否执行了作业。它看起来如下:
test "remember method was sent" do
assert_performed_jobs 0
assert_enqueued_jobs 1 do
SendRememberEmailJob.perform_later('some@mail.com', 0)
end
assert_performed_jobs 1
end
class SendRememberEmailJob < ActiveJob::Base
queue_as :default
def perform(email,time, task)
UserMailer.delay(run_at:time.hours.from_now).remember_mail(email,task)
end
end
当我进行测试时,我总是遇到1次失败:
1 jobs expected, but 0 was performed.
Expected: 1
Actual: 0
我不知道它是否有帮助,但我使用 delayed_job 。提前感谢
答案 0 :(得分:0)
问题可能正在发生,因为delayed_jobs默认运行后台进程中的作业,因此您的测试不会等待它完成测试失败。 尝试禁用DelayedJobs,以便作业实时运行。
你可以这样做:
Delayed::Worker.delay_jobs = false