Skip to content

Commit

Permalink
Merge pull request #122 from ghiculescu/TestMethodName-multiple-asser…
Browse files Browse the repository at this point in the history
…toins

Fix `Minitest/TestMethodName` for tests with multiple assertions
  • Loading branch information
koic committed Feb 26, 2021
2 parents 5d15e21 + bfdd819 commit e33afe3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Bug fixes

* [#118](https://github.com/rubocop/rubocop-minitest/pull/118): **(BREAKING)** Fix `Minitest/AssertEmptyLiteral` by making it check for `assert_equal([], array)` instead of `assert([], array)`. ([@cstyles][])
* [#122](https://github.com/rubocop/rubocop-minitest/pull/122): Fix `Minitest/TestMethodName` for tests with multiple assertions. ([@ghiculescu][])

## 0.10.3 (2021-01-12)

Expand Down Expand Up @@ -182,3 +183,4 @@
[@fatkodima]: https://github.com/fatkodima
[@tsmmark]: https://github.com/tsmmark
[@cstyles]: https://github.com/cstyles
[@ghiculescu]: https://github.com/ghiculescu
2 changes: 1 addition & 1 deletion lib/rubocop/cop/minitest/test_method_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def class_elements(class_node)
end

def offense?(node)
return false if node.each_child_node(:send).none? { |send_node| assertion_method?(send_node.method_name) }
return false if assertions(node).none?

public?(node) && node.arguments.empty? && !test_method_name?(node) && !lifecycle_hook_method?(node)
end
Expand Down
31 changes: 31 additions & 0 deletions test/rubocop/cop/minitest/test_method_name_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,37 @@ def test_do_something_else
RUBY
end

def test_registers_offense_when_test_method_without_prefix_with_multiple_assertions
assert_offense(<<~RUBY)
class FooTest < Minitest::Test
def test_do_something
assert_equal(expected, actual)
assert_equal expected, actual
end
def do_something_else
^^^^^^^^^^^^^^^^^ Test method name should start with `test_` prefix.
assert_equal(expected, actual)
assert_equal expected, actual
end
end
RUBY

assert_correction(<<~RUBY)
class FooTest < Minitest::Test
def test_do_something
assert_equal(expected, actual)
assert_equal expected, actual
end
def test_do_something_else
assert_equal(expected, actual)
assert_equal expected, actual
end
end
RUBY
end

def test_checks_only_test_classes
assert_no_offenses(<<~RUBY)
class FooTest
Expand Down

0 comments on commit e33afe3

Please sign in to comment.