Skip to content

Commit

Permalink
Merge pull request #224 from fatkodima/fix-multiple_assertions
Browse files Browse the repository at this point in the history
Fix a false positive for `Minitest/MultipleAssertions` when using assertion method with block
  • Loading branch information
koic authored Jan 16, 2023
2 parents d30055e + b0c7bae commit 9633b33
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#223](https://github.com/rubocop/rubocop-minitest/issues/223): Fix a false positive for `Minitest/MultipleAssertions` when using assertion method with block. ([@fatkodima][])
5 changes: 3 additions & 2 deletions lib/rubocop/cop/minitest/multiple_assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ def on_class(class_node)
private

def assertions_count(node)
base = assertion_method?(node) ? 1 : 0
base + node.each_child_node.sum { |c| assertions_count(c) }
node.each_descendant(:send).count do |send_node|
assertion_method?(send_node)
end
end

def max_assertions
Expand Down
14 changes: 14 additions & 0 deletions test/rubocop/cop/minitest/multiple_assertions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ def test_asserts_twice
RUBY
end

def test_registers_offense_when_multiple_expectations_with_block
assert_offense(<<~RUBY)
class FooTest < Minitest::Test
def test_asserts_three_times
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Test case has too many assertions [3/1].
assert_equal(foo, bar)
assert_raises(SomeError) do
assert_equal(baz, bar)
end
end
end
RUBY
end

def test_checks_when_inheriting_some_class_and_class_name_ending_with_test
assert_offense(<<~RUBY)
class FooTest < ActiveSupport::TestCase
Expand Down

0 comments on commit 9633b33

Please sign in to comment.