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..2263472c --- /dev/null +++ b/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][]) diff --git a/lib/rubocop/cop/mixin/predicate_assertion_handleable.rb b/lib/rubocop/cop/mixin/predicate_assertion_handleable.rb index 9c2f36a6..b8229c1d 100644 --- a/lib/rubocop/cop/mixin/predicate_assertion_handleable.rb +++ b/lib/rubocop/cop/mixin/predicate_assertion_handleable.rb @@ -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| @@ -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 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