Skip to content

Commit

Permalink
Merge pull request #273 from fatkodima/fix-empty_line_before_assertio…
Browse files Browse the repository at this point in the history
…n_methods-assert_raises

Fix a false positive for `Minitest/EmptyLineBeforeAssertionMethods` and `assert_raises`
  • Loading branch information
koic authored Oct 30, 2023
2 parents a8bd8a7 + 790a1f3 commit e085786
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#271](https://github.com/rubocop/rubocop-minitest/issues/271): Fix a false positive for `Minitest/EmptyLineBeforeAssertionMethods` and `assert_raises`. ([@fatkodima][])
1 change: 1 addition & 0 deletions lib/rubocop/cop/mixin/minitest_exploration_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def assertions_count(node)
end

def assertion_method?(node)
return assertion_method?(node.expression) if node.assignment?
return false if !node.send_type? && !node.block_type? && !node.numblock_type?

ASSERTION_PREFIXES.any? do |prefix|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,30 @@ def test_do_something
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.
do_something do
do_something_more
end
assert_equal(expected, actual)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Add empty line before assertion.
end
RUBY

assert_correction(<<~RUBY)
def test_do_something
do_something do
do_something_more
end
assert_equal(expected, actual)
end
RUBY
end

def test_does_not_register_offense_when_using_assertion_method_with_assignment_before_assertion_method
assert_no_offenses(<<~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
Expand Down

0 comments on commit e085786

Please sign in to comment.