rubocop / rubocop-minitest

Code style checking for Minitest files.
https://docs.rubocop.org/rubocop-minitest
MIT License
144 stars 44 forks source link

Minitest/MultipleAssertions Error with Conditional Assignment Operator #283

Closed unused closed 11 months ago

unused commented 11 months ago

Expected behavior

No Error when using a conditional assignment operator ||= anywhere in the test-file.

Actual behavior

With NewCops: enable rubocop-minitest raises an error when a conditional assignment is used.

Steps to reproduce the problem

Given the following configuration, an error is raised.

# .rubocop.yml
require:
  - rubocop-minitest

AllCops:
  NewCops: enable
$ cat some_test.rb 
# frozen_string_literal: true

require_relative '../../test_helper'

# Some test
class SomeTest < ActiveSupport::TestCase
  test 'assignment error' do
    @variabel ||= :value
  end
end
$ rubocop
Inspecting 1 file
An error occurred while Minitest/MultipleAssertions cop was inspecting /home/me/.../some_test.rb:6:0.
$ rubocop -d                                                                                                                                                                                                        
For /home/me/.../rubocop-minitest-assert-error: configuration from /home/me/.../.rubocop.yml      
Use parallel by default.                                                                                                                                                                                             
Skipping parallel inspection: only a single file needs inspection                                                                                                                                                    
Inspecting 1 file                                                                                                                                                                                                    
Scanning /home/me/.../some_test.rb                                                                                                                                                     
undefined method `assignment?' for nil:NilClass
/home/me/.../versions/3.2.2/lib/ruby/gems/3.2.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/mixin/minitest_exploration_helpers.rb:104:in `assertion_method?'

RuboCop version

$ rubocop -V
1.59.0 (using Parser 3.2.2.4, rubocop-ast 1.30.0, running on ruby 3.2.2) +server [x86_64-linux]
  - rubocop-minitest 0.34.1
tomhughes commented 11 months ago

I'm also seeing this but oddly only in github actions - when I run locally it doesn't happen.

I thought maybe it was because I was using 3.2 locally but actions was using 3.0 but I tried 3.2 in actions and that failed.

Here's a full back trace from one of our failures:

undefined method `assignment?' for nil:NilClass
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/mixin/minitest_exploration_helpers.rb:104:in `assertion_method?'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/mixin/minitest_exploration_helpers.rb:104:in `assertion_method?'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:68:in `assertions_count'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:65:in `block in assertions_count'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node/mixin/descendence.rb:28:in `block in each_child_node'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node/mixin/descendence.rb:25:in `each'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node/mixin/descendence.rb:25:in `each_child_node'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:65:in `each'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:65:in `sum'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:65:in `assertions_count'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:65:in `block in assertions_count'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node/mixin/descendence.rb:28:in `block in each_child_node'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node/mixin/descendence.rb:25:in `each'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node/mixin/descendence.rb:25:in `each_child_node'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:65:in `each'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:65:in `sum'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:65:in `assertions_count'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:65:in `block in assertions_count'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node/mixin/descendence.rb:28:in `block in each_child_node'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node/mixin/descendence.rb:25:in `each'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node/mixin/descendence.rb:25:in `each_child_node'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:65:in `each'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:65:in `sum'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:65:in `assertions_count'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:40:in `block in on_class'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:39:in `each'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:39:in `on_class'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:107:in `public_send'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:107:in `block (2 levels) in trigger_responding_cops'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:171:in `with_cop_error_handling'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:106:in `block in trigger_responding_cops'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:105:in `each'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:105:in `trigger_responding_cops'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:69:in `on_class'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:138:in `on_while'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:71:in `on_module'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `each'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:20:in `walk'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:87:in `investigate'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/cop/team.rb:156:in `investigate_partial'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/cop/team.rb:98:in `investigate'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:345:in `block in inspect_file'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:344:in `each'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:344:in `flat_map'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:344:in `inspect_file'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:287:in `block in do_inspection_loop'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:321:in `block in iterate_until_no_changes'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:314:in `loop'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:314:in `iterate_until_no_changes'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:283:in `do_inspection_loop'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:164:in `block in file_offenses'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:189:in `file_offense_cache'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:163:in `file_offenses'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:154:in `process_file'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:135:in `block in each_inspected_file'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:134:in `each'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:134:in `reduce'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:134:in `each_inspected_file'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:120:in `inspect_files'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:73:in `run'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/cli/command.rb:11:in `run'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/cli/environment.rb:18:in `run'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/cli.rb:118:in `run_command'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/cli.rb:125:in `execute_runners'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/cli.rb:51:in `block in run'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/cli.rb:77:in `profile_if_needed'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/lib/rubocop/cli.rb:43:in `run'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/exe/rubocop:19:in `block in <top (required)>'
/opt/hostedtoolcache/Ruby/3.0.6/x64/lib/ruby/3.0.0/benchmark.rb:308:in `realtime'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/rubocop-1.59.0/exe/rubocop:19:in `<top (required)>'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/bin/rubocop:25:in `load'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/bin/rubocop:25:in `<top (required)>'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/bundler-2.4.19/lib/bundler/cli/exec.rb:58:in `load'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/bundler-2.4.19/lib/bundler/cli/exec.rb:58:in `kernel_load'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/bundler-2.4.19/lib/bundler/cli/exec.rb:23:in `run'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/bundler-2.4.19/lib/bundler/cli.rb:492:in `exec'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/bundler-2.4.19/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/bundler-2.4.19/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/bundler-2.4.19/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/bundler-2.4.19/lib/bundler/cli.rb:34:in `dispatch'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/bundler-2.4.19/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/bundler-2.4.19/lib/bundler/cli.rb:28:in `start'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/bundler-2.4.19/exe/bundle:37:in `block in <top (required)>'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/bundler-2.4.19/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
/home/runner/work/openstreetmap-website/openstreetmap-website/vendor/bundle/ruby/3.0.0/gems/bundler-2.4.19/exe/bundle:29:in `<top (required)>'
/opt/hostedtoolcache/Ruby/3.0.6/x64/bin/bundle:25:in `load'
/opt/hostedtoolcache/Ruby/3.0.6/x64/bin/bundle:25:in `<main>'
broksonic21 commented 11 months ago

similar line is erroring for me as well, put notes up at https://github.com/rubocop/rubocop-minitest/issues/284