class RuboCop::Cop::RSpec::BeNil
expect(foo).to be(nil)
# good
expect(foo).to be_nil
# bad
@example ‘EnforcedStyle: be`
expect(foo).to be_nil
# good
expect(foo).to be(nil)
# bad
@example `EnforcedStyle: be_nil` (default)
This cop can be configured using the `EnforcedStyle` option
generic `be` matcher with a `nil` argument.
You can either use the more specific `be_nil` matcher, or the more
Ensures a consistent style is used when matching `nil`.
def check_be_nil_style(node)
def check_be_nil_style(node) return unless nil_value_expectation?(node) add_offense(node, message: BE_NIL_MSG) do |corrector| corrector.replace(node, 'be_nil') end end
def check_be_style(node)
def check_be_style(node) return unless be_nil_matcher?(node) add_offense(node, message: BE_MSG) do |corrector| corrector.replace(node, 'be(nil)') end end
def on_send(node)
def on_send(node) case style when :be check_be_style(node) when :be_nil check_be_nil_style(node) else # :nocov: :noop # :nocov: end end