From 4f751c2711a6cf2b84c1e51f925a59cd2ba0f6eb Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Tue, 4 Apr 2023 15:26:54 +1000 Subject: [PATCH] Leverage test helpers for enqueued jobs The production code calls `perform_later` and it's better to do the same in specs. Handy test helper allow us to control the execution. Credit to https://github.com/cyrillefr. --- spec/jobs/report_job_spec.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/spec/jobs/report_job_spec.rb b/spec/jobs/report_job_spec.rb index 9211ee0e44..f8a7f03622 100644 --- a/spec/jobs/report_job_spec.rb +++ b/spec/jobs/report_job_spec.rb @@ -11,8 +11,9 @@ describe ReportJob do let(:format) { :csv } it "generates a report" do - job = ReportJob.new - job.perform(*report_args) + job = perform_enqueued_jobs(only: ReportJob) do + ReportJob.perform_later(*report_args) + end expect_csv_report(job) end @@ -20,10 +21,7 @@ describe ReportJob do job = ReportJob.perform_later(*report_args) expect(job.done?).to eq false - # This performs the job in the same process but that's good enought for - # testing the job code. I hope that we can rely on the job worker. - ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true - job.retry_job + perform_enqueued_jobs(only: ReportJob) expect(job.done?).to eq true expect_csv_report(job)