Skip to content

Files

Latest commit

 

History

History
32 lines (22 loc) · 940 Bytes

Capybara-RSpec-PredicateMatcher.md

File metadata and controls

32 lines (22 loc) · 940 Bytes

Pattern: Missing use of predicate matcher

Issue: -

Description

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

# 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)

Further Reading