Capybara/RSpec
Capybara/RSpec/HaveSelector
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Pending |
Yes |
Yes |
2.19 |
- |
Use have_css
or have_xpath
instead of have_selector
.
Capybara/RSpec/PredicateMatcher
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Pending |
Yes |
Yes |
2.19 |
- |
Prefer using predicate matcher over using predicate method directly.
Capybara defines magic matchers for predicate methods. This cop recommends to use the predicate matcher instead of using predicate method directly.
Examples
Strict: true, EnforcedStyle: inflected (default)
# bad
expect(foo.matches_css?(bar: 'baz')).to be_truthy
expect(foo.matches_selector?(bar: 'baz')).to be_truthy
expect(foo.matches_style?(bar: 'baz')).to be_truthy
expect(foo.matches_xpath?(bar: 'baz')).to be_truthy
# good
expect(foo).to match_css(bar: 'baz')
expect(foo).to match_selector(bar: 'baz')
expect(foo).to match_style(bar: 'baz')
expect(foo).to match_xpath(bar: 'baz')
# also good - It checks "true" strictly.
expect(foo.matches_style?(bar: 'baz')).to be(true)
Strict: false, EnforcedStyle: inflected
# bad
expect(foo.matches_style?(bar: 'baz')).to be_truthy
expect(foo.matches_style?(bar: 'baz')).to be(true)
# good
expect(foo).to match_style(bar: 'baz')