Skip to content

Commit 0b7f05a

Browse files
committed
[Fix #1310] Fix a false positive for RSpec/Capybara/SpecificMatcher
Fix: #1310 Updated to not offense in the case of non-replaceable css selectors. ```ruby expect(page).to have_css('button body') expect(page).to have_css('a,h1') expect(page).to have_css('table>tr') expect(page).to have_css('select+option') ```
1 parent 594c06f commit 0b7f05a

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Master (Unreleased)
44

5+
* Fix a false positive for `RSpec/Capybara/SpecificMatcher`. ([@ydah][])
6+
57
## 2.12.0 (2022-07-02)
68

79
* Fix incorrect path suggested by `RSpec/FilePath` cop when second argument contains spaces. ([@tejasbubane][])

lib/rubocop/cop/rspec/capybara/specific_matcher.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def specific_matcher(arg)
5656
end
5757

5858
def acceptable_pattern?(arg)
59-
arg.match?(/\[.+=\w+\]/)
59+
arg.match?(/\[.+=\w+\]/) || arg.match?(/[ >,+]/)
6060
end
6161

6262
def message(node, matcher)

spec/rubocop/cop/rspec/capybara/specific_matcher_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@
7777
RUBY
7878
end
7979

80+
it 'does not register an offense for abstract matcher when ' \
81+
'first argument is element with sub matcher' do
82+
expect_no_offenses(<<-RUBY)
83+
expect(page).to have_css('button body')
84+
expect(page).to have_css('a,h1')
85+
expect(page).to have_css('table>tr')
86+
expect(page).to have_css('select+option')
87+
RUBY
88+
end
89+
8090
it 'does not register an offense for abstract matcher when ' \
8191
'first argument is dstr' do
8292
expect_no_offenses(<<-'RUBY')

0 commit comments

Comments
 (0)