I was digging into this further when I then found if I use assert_raises with an empty block an error is raised by Minitest/AssertRaisesCompoundBody, which is definitely a bug - it doesn't look like this was introduced by #285 though.
~I'd also appreciate if someone could weight in on the possible miscount from Minitest/MultipleAssertions - namely, are calls within assert_raises blocks just considered assertions, or is it actually a bug?~ I confirmed this is a bug and have opened https://github.com/rubocop/rubocop-minitest/issues/289
Expected behavior
Rubocop should pass, since the code is valid
Actual behavior
Rubocop raises an error.
Steps to reproduce the problem
class MyTests < ActiveSupport::TestCase
test "#render errors include stack traces" do
err = assert_raises React::ServerRendering::PrerenderError do
# @renderer.render("NonExistentComponent", {}, nil)
end
assert_match(/NonExistentComponent/, err.to_s, "it names the component")
assert_match(/\n/, err.to_s, "it includes the multi-line backtrace")
end
end
Initially this was because the CI for
react-rails
started to fail using the latest version ofrubocop-minitest
(CI run: https://github.com/reactjs/react-rails/actions/runs/7359116855/job/20033404076?pr=1306), which looks to be because of #285 possibly introducing a bug so that asserts in some cases are now being miscounted.I was digging into this further when I then found if I use
assert_raises
with an empty block an error is raised byMinitest/AssertRaisesCompoundBody
, which is definitely a bug - it doesn't look like this was introduced by #285 though.~I'd also appreciate if someone could weight in on the possible miscount from
Minitest/MultipleAssertions
- namely, are calls withinassert_raises
blocks just considered assertions, or is it actually a bug?~ I confirmed this is a bug and have opened https://github.com/rubocop/rubocop-minitest/issues/289Expected behavior
Rubocop should pass, since the code is valid
Actual behavior
Rubocop raises an error.
Steps to reproduce the problem
RuboCop version
Full output with stack trace
``` For /home/jones/workspace/projects-scrap/rubocop-minitest-bug: configuration from /home/jones/workspace/projects-scrap/rubocop-minitest-bug/.rubocop.yml configuration from /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-minitest-0.34.2/config/default.yml configuration from /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-minitest-0.34.2/config/default.yml Default configuration from /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/config/default.yml Use parallel by default. Running parallel inspection Loading cache from /home/jones/.cache/rubocop_cache/db832e8713e45fee0102ff91441af06e8109b720/6d7a3b621ca1730e04accd938619e4bdab66cfb1/d2e653419e56c908210debf3043ada3d3f1d6fc2 An error occurred while Minitest/AssertRaisesCompoundBody cop was inspecting /home/jones/workspace/projects-scrap/rubocop-minitest-bug/test/mine_test.rb:5:10. undefined method `begin_type?' for nil:NilClass /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-minitest-0.34.2/lib/rubocop/cop/minitest/assert_raises_compound_body.rb:40:in `multi_statement_begin?' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-minitest-0.34.2/lib/rubocop/cop/minitest/assert_raises_compound_body.rb:32:in `on_block' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:107:in `public_send' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:107:in `block (2 levels) in trigger_responding_cops' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:171:in `with_cop_error_handling' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:106:in `block in trigger_responding_cops' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:105:in `each' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:105:in `trigger_responding_cops' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:69:in `on_block' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:135:in `on_lvasgn' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:71:in `on_lvasgn' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `each' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `on_dstr' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:71:in `on_begin' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:158:in `on_block' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:71:in `on_block' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:154:in `on_class' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:71:in `on_class' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:20:in `walk' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:87:in `investigate' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cop/team.rb:156:in `investigate_partial' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cop/team.rb:98:in `investigate' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:345:in `block in inspect_file' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:344:in `each' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:344:in `flat_map' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:344:in `inspect_file' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:287:in `block in do_inspection_loop' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:321:in `block in iterate_until_no_changes' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:314:in `loop' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:314:in `iterate_until_no_changes' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:283:in `do_inspection_loop' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:164:in `block in file_offenses' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:189:in `file_offense_cache' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:163:in `file_offenses' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:99:in `block in warm_cache' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/parallel-1.24.0/lib/parallel.rb:627:in `call_with_index' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/parallel-1.24.0/lib/parallel.rb:597:in `process_incoming_jobs' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/parallel-1.24.0/lib/parallel.rb:577:in `block in worker' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/parallel-1.24.0/lib/parallel.rb:568:in `fork' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/parallel-1.24.0/lib/parallel.rb:568:in `worker' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/parallel-1.24.0/lib/parallel.rb:559:in `block in create_workers' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/parallel-1.24.0/lib/parallel.rb:558:in `each' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/parallel-1.24.0/lib/parallel.rb:558:in `each_with_index' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/parallel-1.24.0/lib/parallel.rb:558:in `create_workers' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/parallel-1.24.0/lib/parallel.rb:497:in `work_in_processes' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/parallel-1.24.0/lib/parallel.rb:291:in `map' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/parallel-1.24.0/lib/parallel.rb:235:in `each' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:99:in `warm_cache' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:72:in `run' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cli/command.rb:11:in `run' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cli/environment.rb:18:in `run' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cli.rb:118:in `run_command' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cli.rb:125:in `execute_runners' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cli.rb:51:in `block in run' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cli.rb:77:in `profile_if_needed' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cli.rb:43:in `run' /home/jones/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-1.59.0/exe/rubocop:19:in `block in