Skip to content

Can not change ActiveJob::Base.queue_adapter in Rails 6 system spec #2232

@jrochkind

Description

@jrochkind

Rails 6.0.2 (or 6.0.1), rspec-rails 4.0.0.beta3, rspec-core 3.9.0.

I am used to being able to set ActiveJob::Base.queue_adapter to :inline in some tests and :test in others -- depending on nature of test, one or the other may be more convenient.

In particular in system tests (which I understand are now recommended by rspec-rails over the older rspec-specific feature tests), it is often convenient to use :inline, to get actual behavior.

However, under Rails 6, I am unable to set ActiveJob::Base.queue_adapter in a system test, it remains set to the Rails TestAdapter.

This spec would be expected to pass, but fails:

require 'rails_helper'

describe "Testing Jobs System Spec", type: :system do
  class MyJob < ApplicationJob
    queue_as :default

    def perform(*args)
    end
  end


  it "does something" do
    expect_any_instance_of(MyJob).to receive(:perform)

    ActiveJob::Base.queue_adapter = :inline
    #puts ActiveJob::Base.queue_adapter
    MyJob.perform_later("one")
  end
end

Above fails. However, it passes if you change to type: :model or type: :job (or probably any type but :system).

It is a regression in the sense that this identical test will also pass under Rails 5.2.3 , rspec-rails 5.0.0.beta3 (or rspec-rails 4.x), rspec-core 3.9.0.

It is confusing how rspec-rails relates to ordinary rails here. It's possible this is a bug/change in Rails itself, but i haven't yet figured out how to reproduce it for a report to Rails in a way that makes sense.

Either way, I believe this action (setting ActiveJob::Base.queue_adapter on a per-test basis, specifically in system tests) is something rspec users will want to do, and were able to do in Rails 5.x, but no seem to be in Rails 6.x. I believe it is a problem.

Some related context may be provided in: rails/rails#37270 Although the original reporter there says their problem was resolved by Rails 6.0.2 -- however, the problem being reported here still reproduces in Rails 6.0.2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions