Skip to content

Commit

Permalink
[Fix #187] Fix an error for Minitest/EmptyLineBeforeAssertionMethods
Browse files Browse the repository at this point in the history
Fixes #187.

This PR fixes an error for `Minitest/EmptyLineBeforeAssertionMethods`
when using method call with block.
  • Loading branch information
koic committed Oct 31, 2022
1 parent e3176a8 commit 1bb5d1b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#187](https://github.com/rubocop/rubocop-minitest/issues/187): Fix an error for `Minitest/EmptyLineBeforeAssertionMethods` when using method call with block. ([@koic][])
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class EmptyLineBeforeAssertionMethods < Base
def on_send(node)
return unless assertion_method?(node)
return unless (previous_line_node = node.left_sibling)
return unless previous_line_node.is_a?(RuboCop::AST::Node)
return if accept_previous_line?(previous_line_node, node)

previous_line_node = previous_line_node.arguments.last if use_heredoc_argument?(previous_line_node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,26 @@ def test_do_something
RUBY
end

def test_registers_offense_when_using_method_call_with_block_arg_before_assertion_method
assert_offense(<<~RUBY)
def test_do_something
block = -> { raise CustomError, 'This is really bad' }
error = assert_raises(CustomError, &block)
assert_equal 'This is really bad', error.message
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Add empty line before assertion.
end
RUBY

assert_correction(<<~RUBY)
def test_do_something
block = -> { raise CustomError, 'This is really bad' }
error = assert_raises(CustomError, &block)
assert_equal 'This is really bad', error.message
end
RUBY
end

def test_does_not_register_offense_when_using_empty_line_before_assertion_methods
assert_no_offenses(<<~RUBY)
def test_do_something
Expand Down

0 comments on commit 1bb5d1b

Please sign in to comment.