rubocop / rubocop-minitest

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

Nested classes with destructuring make `Minitest/MultipleAssertions` to fail #295

Closed cmolina closed 11 months ago

cmolina commented 11 months ago

There is a problem when trying to run rubocop over nested classes that include destructuring, particularly with the Minitest/MultipleAssertions cop.

I saw this error when trying to update rubocop-minitest from 0.34.2 to 0.34.3.


Expected behavior

I'd like to get no errors when running rubocop over this file:

# frozen_string_literal: true

require 'test_helper'

class ParentTest < ActiveSupport::TestCase
  class SpecificTests < ActiveSupport::TestCase
    test 'destructuring' do
      _, item_two = list

      assert_equal 2, item_two
    end

    private

    def list
      [1, 2]
    end
  end
end

Actual behavior

There is an error on Minitest/MultipleAssertions

Rubocop output:

For /Users/cmolina/project/app: configuration from /Users/cmolina/project/app/.rubocop.yml
configuration from /Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-rails-2.23.1/config/default.yml
configuration from /Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-rails-2.23.1/config/default.yml
Default configuration from /Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/config/default.yml
configuration from /Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-performance-1.20.1/config/default.yml
configuration from /Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-performance-1.20.1/config/default.yml
configuration from /Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-minitest-0.34.3/config/default.yml
configuration from /Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-minitest-0.34.3/config/default.yml
configuration from /Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-rake-0.6.0/config/default.yml
configuration from /Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-rake-0.6.0/config/default.yml
configuration from /Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-factory_bot-2.24.0/config/default.yml
configuration from /Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-factory_bot-2.24.0/lib/../config/default.yml
Use parallel by default.
Skipping parallel inspection: only a single file needs inspection
Inspecting 1 file
Scanning /Users/cmolina/project/app/test/models/item_test.rb
An error occurred while Minitest/MultipleAssertions cop was inspecting /Users/cmolina/project/app/test/models/item_test.rb:5:0.
undefined method `expression' for s(:masgn,
  s(:mlhs,
    s(:lvasgn, :_),
    s(:lvasgn, :item_two)),
  s(:send, nil, :list)):RuboCop::AST::Node
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-minitest-0.34.3/lib/rubocop/cop/minitest/multiple_assertions.rb:78:in `assertions_count_in_assignment'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-minitest-0.34.3/lib/rubocop/cop/minitest/multiple_assertions.rb:70:in `assertions_count_based_on_type'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-minitest-0.34.3/lib/rubocop/cop/minitest/multiple_assertions.rb:56:in `assertions_count'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-minitest-0.34.3/lib/rubocop/cop/minitest/multiple_assertions.rb:72:in `block in assertions_count_based_on_type'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node/mixin/descendence.rb:28:in `block in each_child_node'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node/mixin/descendence.rb:25:in `each'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node/mixin/descendence.rb:25:in `each_child_node'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-minitest-0.34.3/lib/rubocop/cop/minitest/multiple_assertions.rb:72:in `each'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-minitest-0.34.3/lib/rubocop/cop/minitest/multiple_assertions.rb:72:in `sum'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-minitest-0.34.3/lib/rubocop/cop/minitest/multiple_assertions.rb:72:in `assertions_count_based_on_type'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-minitest-0.34.3/lib/rubocop/cop/minitest/multiple_assertions.rb:56:in `assertions_count'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-minitest-0.34.3/lib/rubocop/cop/minitest/multiple_assertions.rb:40:in `block in on_class'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-minitest-0.34.3/lib/rubocop/cop/minitest/multiple_assertions.rb:39:in `each'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-minitest-0.34.3/lib/rubocop/cop/minitest/multiple_assertions.rb:39:in `on_class'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:107:in `public_send'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:107:in `block (2 levels) in trigger_responding_cops'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:171:in `with_cop_error_handling'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:106:in `block in trigger_responding_cops'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:105:in `each'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:105:in `trigger_responding_cops'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:69:in `on_class'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `each'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:20:in `walk'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:87:in `investigate'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cop/team.rb:156:in `investigate_partial'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cop/team.rb:98:in `investigate'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:345:in `block in inspect_file'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:344:in `each'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:344:in `flat_map'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:344:in `inspect_file'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:287:in `block in do_inspection_loop'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:321:in `block in iterate_until_no_changes'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:314:in `loop'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:314:in `iterate_until_no_changes'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:283:in `do_inspection_loop'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:164:in `block in file_offenses'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:189:in `file_offense_cache'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:163:in `file_offenses'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:154:in `process_file'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:135:in `block in each_inspected_file'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:134:in `each'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:134:in `reduce'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:134:in `each_inspected_file'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:120:in `inspect_files'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:73:in `run'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cli/command.rb:11:in `run'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cli/environment.rb:18:in `run'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cli.rb:118:in `run_command'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cli.rb:125:in `execute_runners'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cli.rb:51:in `block in run'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cli.rb:77:in `profile_if_needed'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/lib/rubocop/cli.rb:43:in `run'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/exe/rubocop:19:in `block in '
/nix/store/hff15k475cbvi9kx350g8ha2ayqycmss-ruby-3.2.2/lib/ruby/3.2.0/benchmark.rb:311:in `realtime'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/rubocop-1.59.0/exe/rubocop:19:in `'
/Users/cmolina/.local/share/gem/ruby/3.2.0/bin/rubocop:25:in `load'
/Users/cmolina/.local/share/gem/ruby/3.2.0/bin/rubocop:25:in `'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/bundler-2.3.12/lib/bundler/cli/exec.rb:58:in `load'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/bundler-2.3.12/lib/bundler/cli/exec.rb:58:in `kernel_load'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/bundler-2.3.12/lib/bundler/cli/exec.rb:23:in `run'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/bundler-2.3.12/lib/bundler/cli.rb:483:in `exec'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/bundler-2.3.12/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/bundler-2.3.12/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/bundler-2.3.12/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/bundler-2.3.12/lib/bundler/cli.rb:31:in `dispatch'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/bundler-2.3.12/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/bundler-2.3.12/lib/bundler/cli.rb:25:in `start'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/bundler-2.3.12/exe/bundle:48:in `block in '
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/bundler-2.3.12/lib/bundler/friendly_errors.rb:103:in `with_friendly_errors'
/Users/cmolina/.local/share/gem/ruby/3.2.0/gems/bundler-2.3.12/exe/bundle:36:in `'
/Users/cmolina/.local/share/gem/ruby/3.2.0/bin/bundle:25:in `load'
/Users/cmolina/.local/share/gem/ruby/3.2.0/bin/bundle:25:in `
' . 1 file inspected, no offenses detected 1 error occurred: An error occurred while Minitest/MultipleAssertions cop was inspecting /Users/cmolina/project/app/test/models/item_test.rb:5:0. Errors are usually caused by RuboCop bugs. Please, report your problems to RuboCop's issue tracker. https://github.com/rubocop/rubocop/issues Mention the following information in the issue report: 1.59.0 (using Parser 3.2.2.4, rubocop-ast 1.30.0, running on ruby 3.2.2) [arm64-darwin22] Finished in 0.23714800004381686 seconds

Steps to reproduce the problem

Run rubocop over that file.

RuboCop version

$ bundle exec rubocop -V
1.59.0 (using Parser 3.2.2.4, rubocop-ast 1.30.0, running on ruby 3.2.2) [arm64-darwin22]
  - rubocop-factory_bot 2.24.0
  - rubocop-minitest 0.34.3
  - rubocop-performance 1.20.1
  - rubocop-rails 2.23.1
  - rubocop-rake 0.6.0
cmolina commented 11 months ago

hi @koic. Do you have an ETA on when this fix is going to be released? Thanks.

koic commented 11 months ago

https://github.com/rubocop/rubocop-minitest/releases/tag/v0.34.4 has been released.