Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minitest/MultipleAssertions unexpectedly counts the block node #223

Closed
yykamei opened this issue Jan 15, 2023 · 1 comment · Fixed by #224
Closed

Minitest/MultipleAssertions unexpectedly counts the block node #223

yykamei opened this issue Jan 15, 2023 · 1 comment · Fixed by #224
Labels
bug Something isn't working

Comments

@yykamei
Copy link

yykamei commented Jan 15, 2023

As far as I see, Minitest/MultipleAssertions counts the block node as assertion method, with the fix for #210, so the cop issues a violation unexpectedly if code includes assertion methods that are called with block. I'm not sure how to solve this problem while considering #210, so I just opened an issue here.

Expected behavior

Given the code below, I expect rubocop-minitest does not issue problems on Minitest/MultipleAssertions, which is configured as the default; it means Max is 3.

# frozen_string_literal: true

require "test_helper"

class MyMethodTest < Minitest::Test
  def my_method(value)
    raise "error" if value == 2

    value + 2
  end

  test "test!" do
    assert_raises RuntimeError do
      my_method(2)
    end

    assert_equal 3, my_method(1)
    assert_equal 5, my_method(3)
  end
end

This is the expected command output:

❯ bundle exec rubocop test/my_method_test.rb
Inspecting 1 file
.

1 file inspected, no offenses detected

Actual behavior

❯ bundle exec rubocop test/my_method_test.rb
Inspecting 1 file
C

Offenses:

test/my_method_test.rb:12:3: C: Minitest/MultipleAssertions: Test case has too many assertions [4/3].
  test "test!" do ...
  ^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected

Steps to reproduce the problem

I created a repository to reproduce this problem.

https://github.com/yykamei/rubocop-minitest-issue

RuboCop version

❯ bundle exec rubocop -V
1.43.0 (using Parser 3.2.0.0, rubocop-ast 1.24.1, running on ruby 3.2.0) [x86_64-darwin21]
  - rubocop-minitest 0.26.0
@yykamei
Copy link
Author

yykamei commented Jan 16, 2023

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants