Add assert_includes suggestion to Minitest/AssertMatch cop - #348
Open
bquorning wants to merge 2 commits into
Open
Add assert_includes suggestion to Minitest/AssertMatch cop#348bquorning wants to merge 2 commits into
assert_includes suggestion to Minitest/AssertMatch cop#348bquorning wants to merge 2 commits into
Conversation
bquorning
force-pushed
the
assert-match-to-includes
branch
2 times, most recently
from
April 30, 2026 13:42
5495d54 to
a7b7bf7
Compare
bquorning
marked this pull request as ready for review
April 30, 2026 13:43
bquorning
force-pushed
the
assert-match-to-includes
branch
2 times, most recently
from
April 30, 2026 16:06
9884fc0 to
2857521
Compare
13 tasks
Contributor
Author
|
cc @koic |
bquorning
force-pushed
the
assert-match-to-includes
branch
2 times, most recently
from
June 6, 2026 17:12
0e4257f to
af585bf
Compare
Before adding extra checks to assert_includes, it helps to unpack the on_send method first.
Extend the AssertIncludes cop to suggest `assert_includes` instead of
`assert_match` when the regex is a simple string literal without
regex-specific features (anchors, quantifiers, character classes, etc.).
Examples:
# bad
assert_match(/foo/, 'foobar')
assert_match(/http:\/\/example\.com/, response.body)
# good
assert_includes('foobar', 'foo')
assert_includes(response.body, 'http://example.com')
# still uses assert_match (has regex features)
assert_match(/^foo/, 'foobar') # anchor
assert_match(/foo+/, 'foobar') # quantifier
assert_match(/fo[ob]/, 'foobar') # character class
Implementation:
- Override on_send to handle both assert(collection.include?) and
assert_match patterns
- Add regexp_parser dependency for regex analysis
- Expand RESTRICT_ON_SEND to include :assert_match
- Add helper methods to detect simple regexes and convert to strings
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
bquorning
force-pushed
the
assert-match-to-includes
branch
from
June 23, 2026 14:37
af585bf to
1586af0
Compare
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.
Extends the
Minitest/AssertIncludescop to suggestassert_includeswhenassert_matchis used with simple literal regexes that don't require regex-specific features.See also rubocop/rubocop-rspec#2169.
Changes
assert_matchcalls with regexes that contain only literal characters (no anchors, character classes, quantifiers, alternations, metacharacters, etc.)assert_includesas a more semantic and clearer alternative for simple substring matchingregexp_parsera direct dependency (already a transitive dependency viarubocop) to properly parse and analyze regex patternshttp:\/\/example\.com→http://example.com)Examples
Before 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.🤖 Generated with Claude Code