class RuboCop::Cop::RSpec::BeNil
Ensures a consistent style is used when matching ‘nil`.
You can either use the more specific ‘be_nil` matcher, or the more generic `be` matcher with a `nil` argument.
This cop can be configured using the ‘EnforcedStyle` option
@example ‘EnforcedStyle: be_nil` (default)
# bad expect(foo).to be(nil) # good expect(foo).to be_nil
@example ‘EnforcedStyle: be`
# bad expect(foo).to be_nil # good expect(foo).to be(nil)
Constants
- BE_MSG
- BE_NIL_MSG
- RESTRICT_ON_SEND
Public Instance Methods
Source
# File lib/rubocop/cop/rspec/be_nil.rb, line 45 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
Private Instance Methods
Source
# File lib/rubocop/cop/rspec/be_nil.rb, line 68 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
Source
# File lib/rubocop/cop/rspec/be_nil.rb, line 60 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