Skip to content

Latest commit

 

History

History
64 lines (45 loc) · 1.52 KB

RSpec-PredicateMatcher.md

File metadata and controls

64 lines (45 loc) · 1.52 KB

Pattern: Missing use of predicate matcher

Issue: -

Description

Prefer using predicate matcher over using predicate method directly.

RSpec defines magic matchers for predicate methods. This rule recommends to use the predicate matcher instead of using predicate method directly.

Examples

Strict: true, EnforcedStyle: inflected (default)

# bad
expect(foo.something?).to be_truthy

# good
expect(foo).to be_something

# also good - It checks "true" strictly.
expect(foo).to be(true)

Strict: false, EnforcedStyle: inflected

# bad
expect(foo.something?).to be_truthy
expect(foo).to be(true)

# good
expect(foo).to be_something

Strict: true, EnforcedStyle: explicit

# bad
expect(foo).to be_something

# good - the above code is rewritten to it by this cop
expect(foo.something?).to be(true)

Strict: false, EnforcedStyle: explicit

# bad
expect(foo).to be_something

# good - the above code is rewritten to it by this cop
expect(foo.something?).to be_truthy

Configurable attributes

Name Default value Configurable values
Strict true Boolean
EnforcedStyle inflected inflected, explicit

Further Reading