Skip to content

Commit

Permalink
[Fix #210] Fix a false positive for `Minitest/EmptyLineBeforeAssertio…
Browse files Browse the repository at this point in the history
…nMethodsTest`

Fixes #210.

This PR fixes a false positive for `Minitest/EmptyLineBeforeAssertionMethodsTest`
when using assertion method with block arg before other assertion method.
  • Loading branch information
koic committed Dec 30, 2022
1 parent 1ed0cfa commit 55b1800
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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][])
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/minitest_exploration_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 55b1800

Please sign in to comment.