class RuboCop::Cop::RSpec::PredicateMatcher
expect(foo.something?).to be_truthy
# good - the above code is rewritten to it by this cop
expect(foo).to be_something
# bad
@example Strict: false, EnforcedStyle: explicit
expect(foo.something?).to be(true)
# good - the above code is rewritten to it by this cop
expect(foo).to be_something
# bad
@example Strict: true, EnforcedStyle: explicit
expect(foo).to be_something
# good
expect(foo.something?).to be(true)
expect(foo.something?).to be_truthy
# bad
@example Strict: false, EnforcedStyle: inflected
expect(foo.something?).to be(true)
# also good - It checks “true” strictly.
expect(foo).to be_something
# good
expect(foo.something?).to be_truthy
# bad
@example Strict: true, EnforcedStyle: inflected (default)
predicate method directly.
This cop recommends to use the predicate matcher instead of using
RSpec defines magic matchers for predicate methods.
Prefer using predicate matcher over using predicate method directly.
def args_loc(send_node)
foo 1, 2
@example
returns args location with whitespace
def args_loc(send_node) send_node.loc.selector.end.with( end_pos: send_node.loc.expression.end_pos ) end
def block_loc(send_node)
foo { bar }
@example
returns block location with whitespace
def block_loc(send_node) parent = send_node.parent return unless parent.block_type? send_node.loc.expression.end.with( end_pos: parent.loc.expression.end_pos ) end
def on_block(node)
def on_block(node) check_explicit(node) if style == :explicit end
def on_send(node)
def on_send(node) case style when :inflected check_inflected(node) when :explicit check_explicit(node) end end