Undefined local variable or method `tagged_logger' inside Rails 7 ActiveSupport::Testing::Assertions

Inside an rspec support module, my app is calling perform_enqueued_jobs. The spec in question that is using this support module is expecting this call to raise an exception.

When I attempt to run this spec, the following is raised:

got #<NameError: undefined local variable or method `tagged_logger'

When I debug into perform_enqueued_jobs, I am taken into _assert_nothing_raised_or_warn inside activesupport-7.0.0/lib/active_support/testing/assertions.rb, When debugging the block below, it shows e as having the expected exception.

        rescue Minitest::UnexpectedError => e
          if tagged_logger && tagged_logger.warn?
            warning = <<~MSG
              #{self.class} - #{name}: #{e.error.class} raised.
              If you expected this exception, use `assert_raises` as near to the code that raises as possible.
              Other block based assertions (e.g. `#{assertion}`) can be used, as long as `assert_raises` is inside their block.
            MSG
            tagged_logger.warn warning
          end

          raise
        end

Debugging further reveals that the if tagged_logger check above is causing the undefined error.

Questions:

  1. Do I need to do something in config/environments/test.rb to set up a logger to work around this?
  2. Is this a bug? Specifically, should defined?(tagged_logger) be used instead?

The commit below introduced _assert_nothing_raised_or_warn with the block mentioned above.

This seems to be a bug in RSpec that doesn’t implement the tagged_logger. Please report the issue in the RSpec issue tracker.

undefined local variable or method `tagged_logger' during perform_enqueued_jobs · Issue #2545 · rspec/rspec-rails · GitHub is now open.

See undefined local variable or method `tagged_logger' during perform_enqueued_jobs · Issue #2545 · rspec/rspec-rails · GitHub. This seems like a reasonable change to make inside the if tagged_logger check. Thoughts?

FYI: I was able to make a change locally which allowed tagged_logger to get defined. Unfortunately, this caused a different issue to occur inside the _assert_nothing_raised_or_warn implementation. See undefined local variable or method `tagged_logger' during perform_enqueued_jobs · Issue #2545 · rspec/rspec-rails · GitHub.