Skip to content

Commit

Permalink
[Fix #190] Fix an incorrect autocorrect for `Minitest/EmptyLineBefore…
Browse files Browse the repository at this point in the history
…AssertionMethods`

Fixes #190.

This PR fixes an incorrect autocorrect for `Minitest/EmptyLineBeforeAssertionMethods`
when using method call with source code comment before assertion method.
  • Loading branch information
koic committed Nov 2, 2022
1 parent 7864020 commit 980995b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#190](https://github.com/rubocop/rubocop-minitest/issues/190): Fix an incorrect autocorrect for `Minitest/EmptyLineBeforeAssertionMethods` when using method call with source code comment before assertion method. ([@koic][])
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module Minitest
#
class EmptyLineBeforeAssertionMethods < Base
include MinitestExplorationHelpers
include RangeHelp
extend AutoCorrector

MSG = 'Add empty line before assertion.'
Expand Down Expand Up @@ -65,7 +66,7 @@ def register_offense(node, previous_line_node)
range = if heredoc?(previous_line_node)
previous_line_node.loc.heredoc_end
else
previous_line_node
range_by_whole_lines(previous_line_node.source_range, include_final_newline: true)
end

corrector.insert_after(range, "\n")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ def test_do_something
RUBY
end

def test_registers_offense_when_using_method_call_with_comment_before_assertion_method
assert_offense(<<~RUBY)
def test_do_something
do_something # comment
assert_equal(expected, actual)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Add empty line before assertion.
end
RUBY

assert_correction(<<~RUBY)
def test_do_something
do_something # comment
assert_equal(expected, actual)
end
RUBY
end

def test_registers_offense_when_using_method_call_with_line_breaked_args_before_assertion_method
assert_offense(<<~RUBY)
def test_do_something
Expand Down

0 comments on commit 980995b

Please sign in to comment.