diff --git a/changelog/fix_raise_error_using_assert_with_block.md b/changelog/fix_raise_error_using_assert_with_block.md new file mode 100644 index 00000000..d9ae8c04 --- /dev/null +++ b/changelog/fix_raise_error_using_assert_with_block.md @@ -0,0 +1 @@ +* Fix raise error when using assert with block diff --git a/lib/rubocop/cop/mixin/predicate_assertion_handleable.rb b/lib/rubocop/cop/mixin/predicate_assertion_handleable.rb index 9c2f36a6..4a0f2048 100644 --- a/lib/rubocop/cop/mixin/predicate_assertion_handleable.rb +++ b/lib/rubocop/cop/mixin/predicate_assertion_handleable.rb @@ -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) @@ -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 diff --git a/test/rubocop/cop/minitest/assert_predicate_test.rb b/test/rubocop/cop/minitest/assert_predicate_test.rb index c65ebba0..8a5e9368 100644 --- a/test/rubocop/cop/minitest/assert_predicate_test.rb +++ b/test/rubocop/cop/minitest/assert_predicate_test.rb @@ -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