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 #284

Closed broksonic21 closed 11 months ago

broksonic21 commented 11 months ago

Expected behavior

Bumping to 0.34.1 shouldn't return errors, but getting throughout our code base

Actual behavior


Offenses:

REDACTED:73:7: W: Minitest/MultipleAssertions: Test case has too many assertions [4/3].
      def test_REDACTED ...
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
REDACTED:85:7: W: Minitest/MultipleAssertions: Test case has too many assertions [18/3].
      def test_REDACTED ...
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 2 offenses detected

1 error occurred:
An error occurred while Minitest/MultipleAssertions cop was inspecting REDACTED:7:4.
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.0.6) [arm64-darwin22]

Steps to reproduce the problem

dont' have a private repo yet, but seeing this through out code base. Is there a way to get even deeper verbose logs?

RuboCop version

1.59.0 (using Parser 3.2.2.4, rubocop-ast 1.30.0, running on ruby 3.0.6) [arm64-darwin22]
  - rubocop-capybara 2.19.0
  - rubocop-graphql 1.4.0
  - rubocop-minitest 0.34.1
  - rubocop-performance 1.20.0
  - rubocop-rails 2.23.0
  - rubocop-rake 0.6.0
andyw8 commented 11 months ago

You can pass the --debug option. But it would be best if you can provide a minimal example of the code it's being run against.

broksonic21 commented 11 months ago

Looks like it's here: https://github.com/rubocop/rubocop-minitest/blob/master/lib/rubocop/cop/mixin/minitest_exploration_helpers.rb#L104

An error occurred while Minitest/MultipleAssertions cop was inspecting /Users/REDACTED/REDACTED:7:4.
undefined method `assignment?' for nil:NilClass
/Users/REDACTED/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/mixin/minitest_exploration_helpers.rb:104:in `assertion_method?'
/Users/REDACTED/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/mixin/minitest_exploration_helpers.rb:104:in `assertion_method?'
/Users/REDACTED/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:68:in `assertions_count'
/Users/REDACTED/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:65:in `block in assertions_count'
/Users/REDACTED/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node/mixin/descendence.rb:28:in `block in each_child_node'
/Users/REDACTED/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node/mixin/descendence.rb:25:in `each'
/Users/REDACTED/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node/mixin/descendence.rb:25:in `each_child_node'
/Users/REDACTED/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:65:in `each'
/Users/REDACTED/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:65:in `sum'
/Users/REDACTED/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:65:in `assertions_count'
/Users/REDACTED/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:65:in `block in assertions_count'
/Users/REDACTED/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node/mixin/descendence.rb:28:in `block in each_child_node'
/Users/REDACTED/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node/mixin/descendence.rb:25:in `each'
/Users/REDACTED/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node/mixin/descendence.rb:25:in `each_child_node'
/Users/REDACTED/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:65:in `each'
/Users/REDACTED/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:65:in `sum'
/Users/REDACTED/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:65:in `assertions_count'
/Users/REDACTED/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/rubocop-minitest-0.34.1/lib/rubocop/cop/minitest/multiple_assertions.rb:65:in `block in assertions_count'
/Users/REDACTED/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node/mixin/descendence.rb:28:in `block in each_child_node'
/Users/REDACTED/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node/mixin/descendence.rb:25:in `each'
broksonic21 commented 11 months ago
# frozen_string_literal: true

class FooTest < ::Test

  def test_it_fails
    _, b = try_update(foo: 3) do
      see(bar: c.bar, baz: "baz")
    end

    assert_eq c.id, b.id
    assert_eq c.foo, b.foo
  end

end

reproes this.

broksonic21 commented 11 months ago

nothing to do with asserts, it looks like:

# frozen_string_literal: true

class FooTest < ::Test

  def test_it_fails
    _d, _b = try_update(foo: 3) do
      see(bar: c.bar, baz: "baz")
    end
  end

end

has same error - must be anytime there's a split return value?

koic commented 11 months ago

This issue is a dup with #283. Thank you for your feedback.