Skip to content

Commit

Permalink
[Fix #1310] Fix a false positive for RSpec/Capybara/SpecificMatcher
Browse files Browse the repository at this point in the history
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')
```
  • Loading branch information
ydah committed Jul 3, 2022
1 parent 594c06f commit 0b7f05a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Master (Unreleased)

* Fix a false positive for `RSpec/Capybara/SpecificMatcher`. ([@ydah][])

## 2.12.0 (2022-07-02)

* Fix incorrect path suggested by `RSpec/FilePath` cop when second argument contains spaces. ([@tejasbubane][])
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/capybara/specific_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def specific_matcher(arg)
end

def acceptable_pattern?(arg)
arg.match?(/\[.+=\w+\]/)
arg.match?(/\[.+=\w+\]/) || arg.match?(/[ >,+]/)
end

def message(node, matcher)
Expand Down
10 changes: 10 additions & 0 deletions spec/rubocop/cop/rspec/capybara/specific_matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@
RUBY
end

it 'does not register an offense for abstract matcher when ' \
'first argument is element with sub matcher' do
expect_no_offenses(<<-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')
RUBY
end

it 'does not register an offense for abstract matcher when ' \
'first argument is dstr' do
expect_no_offenses(<<-'RUBY')
Expand Down

0 comments on commit 0b7f05a

Please # to comment.