diff --git a/changelog/fix_a_false_positive_for_minitest_empty_line_before_assertion_methods.md b/changelog/fix_a_false_positive_for_minitest_empty_line_before_assertion_methods.md new file mode 100644 index 00000000..8537bd6b --- /dev/null +++ b/changelog/fix_a_false_positive_for_minitest_empty_line_before_assertion_methods.md @@ -0,0 +1 @@ +* [#210](/~https://github.com/rubocop/rubocop-minitest/issues/210): Fix a false positive for `Minitest/EmptyLineBeforeAssertionMethodsTest` when using assertion method with block arg before other assertion method. ([@koic][]) diff --git a/lib/rubocop/cop/minitest/empty_line_before_assertion_methods.rb b/lib/rubocop/cop/minitest/empty_line_before_assertion_methods.rb index a59c071f..061fe2e8 100644 --- a/lib/rubocop/cop/minitest/empty_line_before_assertion_methods.rb +++ b/lib/rubocop/cop/minitest/empty_line_before_assertion_methods.rb @@ -53,7 +53,7 @@ def accept_previous_line?(previous_line_node, node) return true if !previous_line_node.is_a?(RuboCop::AST::Node) || previous_line_node.args_type? || node.parent.basic_conditional? - previous_line_node.send_type? && assertion_method?(previous_line_node) + assertion_method?(previous_line_node) end def use_heredoc_argument?(node) diff --git a/lib/rubocop/cop/mixin/minitest_exploration_helpers.rb b/lib/rubocop/cop/mixin/minitest_exploration_helpers.rb index 1173997c..323524ac 100644 --- a/lib/rubocop/cop/mixin/minitest_exploration_helpers.rb +++ b/lib/rubocop/cop/mixin/minitest_exploration_helpers.rb @@ -78,7 +78,7 @@ def assertions(def_node) end def assertion_method?(node) - return false unless node.send_type? + return false if !node.send_type? && !node.block_type? ASSERTION_PREFIXES.any? do |prefix| method_name = node.method_name diff --git a/test/rubocop/cop/minitest/empty_line_before_assertion_methods_test.rb b/test/rubocop/cop/minitest/empty_line_before_assertion_methods_test.rb index 008be8af..7ae7e45e 100644 --- a/test/rubocop/cop/minitest/empty_line_before_assertion_methods_test.rb +++ b/test/rubocop/cop/minitest/empty_line_before_assertion_methods_test.rb @@ -395,4 +395,15 @@ class FooTest < Minitest::Test end RUBY end + + def test_does_not_register_offense_when_using_assert_raises_with_block_arg_before_assertion_method + assert_no_offenses(<<~RUBY) + def test_do_something + assert_raises(CustomError) do + do_something + end + assert(thing) + end + RUBY + end end