rubocop / rubocop-minitest

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

[Fix #292] ensure all kinds of assignments are correctly handled when counting assertions #293

Closed G-Rath closed 11 months ago

G-Rath commented 11 months ago

Fixes #292 Fixes #295

This ensures that Minitest/MultipleAssertions properly counts assertions when dealing with assignments - I expect (and hope) this is pretty rare in real-world code, but it is technically correct for the cop to be doing and the actual support isn't that complex.

I've only added a single test to ensure all the types of assignment work, and then a test using the standard assignment operator for each different kind of complex node (block, if, rescue, etc) since they all work the same except for mass assignment and it would be very tedious to write all those tests; they could be done through loops but I'm not sure its worth it vs the complexity.

Speaking of mass assignment, that is the fly in the ointment - I've added support for single method and array, and then had it just bail otherwise because I expect this to be the rarest of rare cases and worst case a follow-up PR can be done expanding its support; I know already that this doesn't cover assigning hashes (i.e. x, y => { "value" => assert("why...?") }).


Before submitting the PR make sure the following are checked:

koic commented 11 months ago

Thanks!