Class: RuboCop::Cop::RSpec::AvoidBeFalsy

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/rspec/avoid_be_falsy.rb

Overview

Examples:

# bad
expect(subject).to be_falsy

# good
expect(subject).to be false

# good
expect(subject.nil?).to be true

Constant Summary collapse

MSG =
"Use `#be false` instead of `#be_falsy`."
RESTRICT_ON_SEND =
i[be_falsy].freeze

Instance Method Summary collapse

Instance Method Details

#be_falsy?(node) ⇒ Object



25
26
27
# File 'lib/rubocop/cop/rspec/avoid_be_falsy.rb', line 25

def_node_matcher :be_falsy?, "(send nil? :be_falsy ...)\n"

#on_send(node) ⇒ Object Also known as: on_csend

Called on every send node (method call) while walking the AST. TODO: remove this method if inspecting send nodes is unneeded for your cop. By default, this is aliased to on_csend as well to handle method calls with safe navigation, remove the alias if this is unnecessary. If kept, ensure your tests cover safe navigation as well!



34
35
36
37
38
# File 'lib/rubocop/cop/rspec/avoid_be_falsy.rb', line 34

def on_send(node)
  return unless be_falsy?(node)

  add_offense(node)
end