Sha256: 8bbfa60eea005025d8ba4e49010b49e0a75c72ba7bf064be984299172a6cb376

Contents?: true

Size: 1002 Bytes

Versions: 11

Compression:

Stored size: 1002 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # Checks that `remove_const` is not used in specs.
      #
      # @example
      #   # bad
      #   it 'does something' do
      #     Object.send(:remove_const, :SomeConstant)
      #   end
      #
      #   before do
      #     SomeClass.send(:remove_const, :SomeConstant)
      #   end
      #
      class RemoveConst < Base
        include RuboCop::RSpec::Language
        extend RuboCop::RSpec::Language::NodePattern

        MSG = 'Do not use remove_const in specs. ' \
              'Consider using e.g. `stub_const`.'
        RESTRICT_ON_SEND = %i[send __send__].freeze

        # @!method remove_const(node)
        def_node_matcher :remove_const, <<~PATTERN
          (send _ {:send | :__send__} (sym :remove_const) _)
        PATTERN

        # Check for offenses
        def on_send(node)
          remove_const(node) do
            add_offense(node)
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
rubocop-rspec-2.31.0 lib/rubocop/cop/rspec/remove_const.rb
rubocop-rspec-2.30.0 lib/rubocop/cop/rspec/remove_const.rb
rubocop-rspec-2.29.2 lib/rubocop/cop/rspec/remove_const.rb
rubocop-rspec-2.29.1 lib/rubocop/cop/rspec/remove_const.rb
rubocop-rspec-2.29.0 lib/rubocop/cop/rspec/remove_const.rb
rubocop-rspec-2.28.0 lib/rubocop/cop/rspec/remove_const.rb
rubocop-rspec-2.27.1 lib/rubocop/cop/rspec/remove_const.rb
rubocop-rspec-2.27.0 lib/rubocop/cop/rspec/remove_const.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.26.1/lib/rubocop/cop/rspec/remove_const.rb
rubocop-rspec-2.26.1 lib/rubocop/cop/rspec/remove_const.rb
rubocop-rspec-2.26.0 lib/rubocop/cop/rspec/remove_const.rb