Description
What Ruby, Rails and RSpec versions are you using?
Ruby version: 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x86_64-darwin21]
Rails version: 7.0.0
RSpec 3.10
- rspec-core 3.10.1
- rspec-expectations 3.10.1
- rspec-mocks 3.10.2
- rspec-rails 5.0.2
- rspec-support 3.10.3
Observed behaviour
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.
I reported this on Rails forum here and a member of the core team suggested the following:
"This seems to be a bug in RSpec that doesn’t implement the tagged_logger. Please report the issue in the RSpec issue tracker."
Expected behaviour
The spec should finish and allow to raise_error
to check for the expected exception. This spec is working as expected in Rails 6.