rubocop / rubocop-minitest

Code style checking for Minitest files.
https://docs.rubocop.org/rubocop-minitest
MIT License
144 stars 44 forks source link

Check for assertion method receiver - fixes #321 #322

Open MatzFan opened 2 months ago

MatzFan commented 2 months ago

Counting assertions based on a string prefix of "assert" or "refute" is replaced by a symbol comparison against the 38 Minitest assertion methods.

Earlopain commented 2 months ago

This is not the best solution. It will ignore all custom assertions the user may have written themselves, and test methods provided by gems like rails.

I think it would be better to instead only look at methods that have no receiver.

MatzFan commented 2 months ago

@Earlopain

It will ignore all custom assertions the user may have written themselves, and test methods provided by gems like rails.

Apologies, I didn't see that tested for anywhere.

I think it would be better to instead only look at methods that have no receiver.

Or where the receiver is not a kind_of Minitest::Test?

Earlopain commented 2 months ago

Apologies, I didn't see that tested for anywhere.

I guess the assert_something call you changed could be counted as that but yes, it isn't very explicit in the test suite yet. Let's just add a testcase for custom assertion methods with this PR.

Or where the receiver is not a kind_of Minitest::Test?

Perhaps, but not decidable by rubocop. It can't tell if MyCustomTestCase or AcitveSupport::TestCase inherit from Minitest::Test. Just no receiver seems fine, unless you see a problem with that yourself.


Please add a changelog entry for this, and write a meaningful commit message starting with [Fix #321]. Thanks!

MatzFan commented 2 months ago

Will take a :eyes: