Skip to content

Commit

Permalink
Fix raise error when usgin assert with block
Browse files Browse the repository at this point in the history
  • Loading branch information
ippachi committed Jun 13, 2022
1 parent 6116460 commit c9bd43a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_raise_error_using_assert_with_block.md
@@ -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
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
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

0 comments on commit c9bd43a

Please sign in to comment.