class RuboCop::Cop::Minitest::UselessAssertion
assert false, “My message”
assert_nil foo
assert_equal foo, bar
assert something
# good
assert_nil [foo, bar]
assert_equal @foo, @foo
assert true
# bad
@example
Detects useless assertions (assertions that either always pass or always fail).
def empty_composite?(node)
def empty_composite?(node) return true if node.str_type? && node.value.empty? (node.array_type? || node.hash_type?) && node.children.empty? end
def offense?(node)
def offense?(node) expected, actual, = node.arguments case node.method_name when *SINGLE_ASSERTION_ARGUMENT_METHODS actual.nil? && expected&.literal? && !expected.xstr_type? when *TWO_ASSERTION_ARGUMENTS_METHODS return false unless expected && actual return false if expected.source != actual.source (expected.variable? && actual.variable?) || (empty_composite?(expected) && empty_composite?(actual)) when :assert_includes, :refute_includes expected && empty_composite?(expected) when :assert_silent block_node = node.parent block_node&.body.nil? else false end end
def on_send(node)
def on_send(node) return if node.receiver add_offense(node) if offense?(node) end