Reputation: 13949
I have many jobs that are calling other nested jobs using perform_later
. However, during some tests on Cucumber, I'd like to execute those jobs immediately after to proceed with the rests of the tests.
I thought it would be enough to add
# features/support/active_job.rb
World(ActiveJob::TestHelper)
And to call jobs using this in a step definition file
perform_enqueued_jobs do
# call step that calls MyJob.perform_later(*args)
end
However I run into something like that
undefined method `perform_enqueued_jobs' for #<ActiveJob::QueueAdapters::AsyncAdapter:0x007f98fd03b900> (NoMethodError)
What am I missing / doing wrong ?
Upvotes: 5
Views: 1312
Reputation: 4953
I switched to the :test adapter in tests and it worked out for me:
# initialisers/test.rb
config.active_job.queue_adapter = :test
# features/support/env.rb
World(ActiveJob::TestHelper)
Upvotes: 1
Reputation: 13949
It would seem as long as you call .perform_now
inside the cucumber step, even if there are nested jobs with .deliver_later
inside, it does work too
#support/active_job.rb
World(ActiveJob::TestHelper)
#my_job_steps.rb
Given(/^my job starts$/) do
MyJob.perform_now(logger: 'stdout')
end
#jobs/my_job.rb
...
MyNestedJob.perform_later(*args) # is triggered during the step
...
Also, in my environment/test.rb
file I didn't write anything concerning ActiveJob, the default was working fine. I believe the default adapter for tests is :inline
so calling .deliver_later
_now
shouldn't matter
Upvotes: 0