I've got a integration test that is run through capybara. It visits a webpage, creates an object, and renders the results. When the object is created, the controller enqueues several jobs that create some related objects.
When I run my integration test, I want to be able to examine the rendered page as if those jobs had finished. The 2 obvious solutions are:
- Set the queue adapter as :inline
- Manually execute/clear the enqueued jobs after creating the object.
For 1), I've attempted to set the queue adapter in a before(:each)
to :inline, but this does not change the adapter, it continues to use the test adapter (which is set in my test.rb config file):
before(:each) { ActiveJob::Base.queue_adapter = :inline }
after(:each) { ActiveJob::Base.queue_adapter = :test }
it "should work" do
puts ActiveJob::Base.queue_adapter
end
which outputs: #<ActiveJob::QueueAdapters::TestAdapter:0x007f93a1061ee0 @enqueued_jobs=[], @performed_jobs=[]>
For 2), I'm not sure if this is actually possible. ActiveJob::TestHelpers
provides perform_enqueued_jobs
, but this methods isn't helpful, as it seems to work only for jobs explicitly referenced in the passed in block.