How to ensure background jobs run in integration tests?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


How to ensure background jobs run in integration tests?



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:



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)


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=>


#<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.


ActiveJob::TestHelpers


perform_enqueued_jobs









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

How to scale/resize CVPixelBufferRef in objective C, iOS