Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a false positive for Minitest/EmptyLineBeforeAssertionMethods and assert_raises #273

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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