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 raise error when usgin assert with block #175

Merged
merged 1 commit into from
Jun 13, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/fix_raise_error_using_assert_with_block.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#175](https://github.com/rubocop/rubocop-minitest/pull/175): Fix raise error when using assert with block. ([@ippachi][])
7 changes: 6 additions & 1 deletion lib/rubocop/cop/mixin/predicate_assertion_handleable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ def on_send(node)

first_argument = arguments.first

return unless first_argument
return if first_argument.block_type? || first_argument.numblock_type?
return unless first_argument.respond_to?(:predicate_method?) && first_argument.predicate_method?
return unless predicate_method?(first_argument)
return unless first_argument.arguments.count.zero?

add_offense(node, message: offense_message(arguments)) do |corrector|
Expand All @@ -38,6 +39,10 @@ def peel_redundant_parentheses_from(arguments)
peel_redundant_parentheses_from(arguments.first.children)
end

def predicate_method?(first_argument)
first_argument.respond_to?(:predicate_method?) && first_argument.predicate_method?
end

def offense_message(arguments)
message_argument = arguments.last if arguments.first != arguments.last

Expand Down
10 changes: 10 additions & 0 deletions test/rubocop/cop/minitest/assert_predicate_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,14 @@ def test_do_something
end
RUBY
end

def test_does_not_raise_error_using_assert_with_block
assert_no_offenses(<<~RUBY)
class FooTest < Minitest::Test
def test_do_something
assert { true }
end
end
RUBY
end
end