Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Fix false positives for `RSpec/SpecFilePathFormat` when matching spec partials. ([@ydah])
- Fix incorrect autocorrection for `RSpec/DescribedClass` when using nested example groups with `EnforcedStyle: explicit`. ([@ydah])
- Fix `RSpec/MatchWithSimpleRegex` to ignore `match` nested inside `include` matchers. ([@ydah])

## 3.10.2 (2026-06-06)

Expand Down
7 changes: 7 additions & 0 deletions lib/rubocop/cop/rspec/match_with_simple_regex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ class MatchWithSimpleRegex < Base
(send nil? :match $regexp)
PATTERN

# @!method include_matcher_argument?(node)
def_node_matcher :include_matcher_argument?, <<~PATTERN
^(send nil? :include ...)
PATTERN

def on_send(node)
return if include_matcher_argument?(node)

match_with_regexp?(node) do |regexp|
next unless simple_regexp?(regexp)

Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/rspec/match_with_simple_regex_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@
RUBY
end

it 'does not register an offense when using match within an ' \
'include matcher' do
expect_no_offenses(<<~RUBY)
expect(errors).to include(match(/message/))
expect(errors).to include(match(/message/), match(/warning/))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is a valid use case for an example like this?

RUBY
end

it 'does not register an offense when using match with anchor at start' do
expect_no_offenses(<<~RUBY)
expect('foobar').to match(/^foo/)
Expand Down