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 e609604
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
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 @@
* Fix raise error when using assert with block
13 changes: 10 additions & 3 deletions lib/rubocop/cop/mixin/predicate_assertion_handleable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ def on_send(node)

first_argument = arguments.first

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

add_offense(node, message: offense_message(arguments)) do |corrector|
autocorrect(corrector, node, arguments)
Expand Down Expand Up @@ -59,6 +57,15 @@ def new_arguments(arguments)
def correct_receiver(receiver)
receiver ? receiver.source : 'self'
end

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

false
end
end
end
end
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

0 comments on commit e609604

Please sign in to comment.