Sha256: 57f54599b17b46405e7ecb1b767e84738b183d8c1022a975622f42d61de2e8c8

Contents?: true

Size: 1.08 KB

Versions: 16

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Minitest
      # Enforces the test to use `assert_instance_of(Class, object)`
      # over `assert(object.instance_of?(Class))`.
      #
      # @example
      #   # bad
      #   assert(object.instance_of?(Class))
      #   assert(object.instance_of?(Class), 'message')
      #
      #   # bad
      #   assert_equal(Class, object.class)
      #   assert_equal(Class, object.class, 'message')
      #
      #   # good
      #   assert_instance_of(Class, object)
      #   assert_instance_of(Class, object, 'message')
      #
      class AssertInstanceOf < Base
        include InstanceOfAssertionHandleable
        extend AutoCorrector

        RESTRICT_ON_SEND = %i[assert assert_equal].freeze

        def_node_matcher :instance_of_assertion?, <<~PATTERN
          {
            (send nil? :assert (send $_ :instance_of? $const) $_?)
            (send nil? :assert_equal $const (send $_ :class) $_?)
          }
        PATTERN

        def on_send(node)
          investigate(node, :assert)
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
rubocop-minitest-0.36.0 lib/rubocop/cop/minitest/assert_instance_of.rb
rubocop-minitest-0.35.1 lib/rubocop/cop/minitest/assert_instance_of.rb
rubocop-minitest-0.35.0 lib/rubocop/cop/minitest/assert_instance_of.rb
rubocop-minitest-0.34.5 lib/rubocop/cop/minitest/assert_instance_of.rb
rubocop-minitest-0.34.4 lib/rubocop/cop/minitest/assert_instance_of.rb
rubocop-minitest-0.34.3 lib/rubocop/cop/minitest/assert_instance_of.rb
rubocop-minitest-0.34.2 lib/rubocop/cop/minitest/assert_instance_of.rb
rubocop-minitest-0.34.1 lib/rubocop/cop/minitest/assert_instance_of.rb
rubocop-minitest-0.34.0 lib/rubocop/cop/minitest/assert_instance_of.rb
rubocop-minitest-0.33.0 lib/rubocop/cop/minitest/assert_instance_of.rb
rubocop-minitest-0.32.2 lib/rubocop/cop/minitest/assert_instance_of.rb
rubocop-minitest-0.32.1 lib/rubocop/cop/minitest/assert_instance_of.rb
rubocop-minitest-0.32.0 lib/rubocop/cop/minitest/assert_instance_of.rb
rubocop-minitest-0.31.1 lib/rubocop/cop/minitest/assert_instance_of.rb
rubocop-minitest-0.31.0 lib/rubocop/cop/minitest/assert_instance_of.rb
rubocop-minitest-0.30.0 lib/rubocop/cop/minitest/assert_instance_of.rb