Rspec-rails: Integration tests not respecting queue adapter

Created on 1 Apr 2020  路  8Comments  路  Source: rspec/rspec-rails

What Ruby, Rails and RSpec versions are you using?

Ruby version: 2.6.6
Rails version: 6.0.2.2
RSpec version: 4.0.0

Observed behaviour

Integration tests that use ActiveJob are ignoring the configured queue adapter and instead use the built in test queue. In our case we're using Sidekiq and tests are failing when doing a delayed send with ActionMailer because emails are being queued up internally even though we've configured Sidekiq to run them inline.

This is similar to #2232 / #2242 but for integration tests. Related to rails/rails#37270

Expected behaviour

Integration tests should use the configured queue adapter.

Can you provide an example app?

https://github.com/gaffneyc/rails_email_deliveries

Instructions for running the test are in the README.

All 8 comments

In given example repo, spec passes after mv spec/integration spec/request

Isn't request spec same as integration spec?

Isn't request spec same as integration spec?

Sadly for the moment it is different.

Ah @benoittgt thats a mistaken assumption, placing specs in spec/integration is an alias for a request spec (configured here): lib/rspec/rails/configuration.rb:34

The directory for request specs is spec/requests so spec/request is dropping the request example group which is why its working, (no rails magic).

Sorry, Jon is true. I confused with system specs.

This is tricky to resolve because it is a designed behaviour of the integration tests in rails, they are deliberately blowing away the configured adaptor in favour of the test one which then allows you to check on jobs etc. We can prevent this behaviour but we'd "lose" the default integration...

With more investigation unless something happens to resolve rails/rails#37270 we can't really do much without completely "undo'ing" their work, which would also be surprising to probably more people, except maybe we could provide a helper to do the workaround for people, if someone wanted to work on that feel free to follow up here.

This is all incredibly confusing, but I am not currently having any problems using system tests rather than integration tests, rails 6 and rspec-rails 4. (The various types of tests are certainly confusing; rails own behavior here is certainly confusing).

This is all incredibly confusing, but I am not currently having any problems using system tests rather than integration tests, rails 6 and rspec-rails 4. (The various types of tests are certainly confusing; rails own behavior here is certainly confusing).

Yes both Rails and ourselves have fixed this for system specs/tests by not including the default integration test behaviour and thus not pulling in the active job helpers for this behaviour. This means that they are entirely dependent on your configuration rather than Rails magically setting them.

Was this page helpful?
0 / 5 - 0 ratings