Optimize MinitestExplorationHelpers#test_cases helper - #364
Merged
koic merged 1 commit intoAug 24, 2026
Conversation
moberegger
marked this pull request as ready for review
August 17, 2026 17:53
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A follow up to #363
Optimizes the
MinitestExplorationHelpers#test_caseshelper. The intent of this helper was to findtestanditclass definitions, but this would actually descend into method bodies, which incurs a rather substantial traversal cost. The optimization basically terminates the traversal earlier.This does technically introduce a change in behavior. The old implementation could result in false positives/negatives where the proposed optimized version does not. For example, with something like
originally the cop would see
itand think it's a valid test definition even though it is not.itis a class level DSL, and in this case anitinstance method would be called. I am having trouble thinking of a good example here; I can't imagine this happening too often given that this is not valid syntax (at least as far as the minitest DSL is concerned), but I suppose there is a corner case here where the developer implemented their ownitinstance method helper or whatever that allowed this to run. I mention this mostly for completeness.Benchmarks below. This was run against 5,000 cop executions per rule. Note that the
Minitest/MultipleAssertionsbenchmark ran with the changes in #363 included.Minitest/MultipleAssertionsMinitest/NoAssertionsMinitest/NoTestCasesMinitest/DuplicateTestRunMinitest/NonPublicTestMethodBefore submitting the PR make sure the following are checked:
[Fix #issue-number](if the related issue exists).master(if not - rebase it).bundle exec rake default. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.mdif the new code introduces user-observable changes. See changelog entry format for details.