RSpec and rswag: How to perform enqueued jobs in test

1.5k Views Asked by At

I have an API project in Rails 5 using rswag for endpoint definition and testing.

One controller action, create, enqueues an ActiveJob with keyword arguments using perform_later(job_title: @job, date: @date)

When I use run_test! in my request spec for this action, I want to run the queued job immediately.

How do I force the job to run with the keyword arguments that were passed in the controller action?

1

There are 1 best solutions below

0
On

You can use perform_enqueued_jobs inside your run_test! block

run_test! do
  perform_enqueued_jobs
end