Sha256: 80f5d6f78b84bc9deb1fc66cf449eaf3951bc7fff8c0fc14cb119555f82059ab

Contents?: true

Size: 949 Bytes

Versions: 13

Compression:

Stored size: 949 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

        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

13 entries across 13 versions & 4 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-3.0.3/lib/rubocop/cop/rspec/remove_const.rb
rubocop-rspec-3.3.0 lib/rubocop/cop/rspec/remove_const.rb
rubocop-rspec-3.2.0 lib/rubocop/cop/rspec/remove_const.rb
rubocop-rspec-3.1.0 lib/rubocop/cop/rspec/remove_const.rb
rubocop-rspec-3.0.5 lib/rubocop/cop/rspec/remove_const.rb
rubocop-rspec-3.0.4 lib/rubocop/cop/rspec/remove_const.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/remove_const.rb
rubocop-rspec-3.0.3 lib/rubocop/cop/rspec/remove_const.rb
rubocop-rspec-3.0.2 lib/rubocop/cop/rspec/remove_const.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/remove_const.rb
rubocop-rspec-3.0.1 lib/rubocop/cop/rspec/remove_const.rb
rubocop-rspec-3.0.0 lib/rubocop/cop/rspec/remove_const.rb
rubocop-rspec-3.0.0.pre lib/rubocop/cop/rspec/remove_const.rb