Class: RuboCop::Cop::Minitest::RefuteNil

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
ArgumentRangeHelper, NilAssertionHandleable
Defined in:
lib/rubocop/cop/minitest/refute_nil.rb

Overview

Enforces the test to use ‘refute_nil` instead of using `refute_equal(nil, something)`, `refute(something.nil?)`, or `refute_predicate(something, :nil?)`.

Examples:

# bad
refute_equal(nil, actual)
refute_equal(nil, actual, 'message')
refute(actual.nil?)
refute(actual.nil?, 'message')
refute_predicate(object, :nil?)
refute_predicate(object, :nil?, 'message')

# good
refute_nil(actual)
refute_nil(actual, 'message')

Constant Summary collapse

ASSERTION_TYPE =
'refute'
RESTRICT_ON_SEND =
%i[refute refute_equal refute_predicate].freeze

Constants included from NilAssertionHandleable

NilAssertionHandleable::MSG

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



38
39
40
41
42
# File 'lib/rubocop/cop/minitest/refute_nil.rb', line 38

def on_send(node)
  nil_refutation(node) do |actual, message|
    register_offense(node, actual, message)
  end
end