Class: RuboCop::Cop::Minitest::AssertNil

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

Overview

Enforces the test to use ‘assert_nil` instead of using `assert_equal(nil, something)`, `assert(something.nil?)`, or `assert_predicate(something, :nil?)`.

Examples:

# bad
assert_equal(nil, actual)
assert_equal(nil, actual, 'message')
assert(object.nil?)
assert(object.nil?, 'message')
assert_predicate(object, :nil?)
assert_predicate(object, :nil?, 'message')

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

Constant Summary collapse

ASSERTION_TYPE =
'assert'
RESTRICT_ON_SEND =
%i[assert assert_equal assert_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/assert_nil.rb', line 38

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