Sha256: c97f22d8789660700f3cf8163b0de3c2c0e786e997d9b9fbb9bf9ed88484803d

Contents?: true

Size: 1.12 KB

Versions: 16

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # `context` should not be used for specifying methods.
      #
      # @example
      #   # bad
      #   context '#foo_bar' do
      #     # ...
      #   end
      #
      #   context '.foo_bar' do
      #     # ...
      #   end
      #
      #   # good
      #   describe '#foo_bar' do
      #     # ...
      #   end
      #
      #   describe '.foo_bar' do
      #     # ...
      #   end
      class ContextMethod < Base
        extend AutoCorrector

        MSG = 'Use `describe` for testing methods.'

        # @!method context_method(node)
        def_node_matcher :context_method, <<-PATTERN
          (block (send #rspec? :context $(str #method_name?) ...) ...)
        PATTERN

        def on_block(node)
          context_method(node) do |context|
            add_offense(context) do |corrector|
              corrector.replace(node.send_node.loc.selector, 'describe')
            end
          end
        end

        private

        def method_name?(description)
          description.start_with?('.', '#')
        end
      end
    end
  end
end

Version data entries

16 entries across 14 versions & 2 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.12.1/lib/rubocop/cop/rspec/context_method.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.9.0/lib/rubocop/cop/rspec/context_method.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.12.1/lib/rubocop/cop/rspec/context_method.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.9.0/lib/rubocop/cop/rspec/context_method.rb
rubocop-rspec-2.12.1 lib/rubocop/cop/rspec/context_method.rb
rubocop-rspec-2.12.0 lib/rubocop/cop/rspec/context_method.rb
rubocop-rspec-2.11.1 lib/rubocop/cop/rspec/context_method.rb
rubocop-rspec-2.11.0 lib/rubocop/cop/rspec/context_method.rb
rubocop-rspec-2.10.0 lib/rubocop/cop/rspec/context_method.rb
rubocop-rspec-2.9.0 lib/rubocop/cop/rspec/context_method.rb
rubocop-rspec-2.8.0 lib/rubocop/cop/rspec/context_method.rb
rubocop-rspec-2.7.0 lib/rubocop/cop/rspec/context_method.rb
rubocop-rspec-2.6.0 lib/rubocop/cop/rspec/context_method.rb
rubocop-rspec-2.5.0 lib/rubocop/cop/rspec/context_method.rb
rubocop-rspec-2.4.0 lib/rubocop/cop/rspec/context_method.rb
rubocop-rspec-2.3.0 lib/rubocop/cop/rspec/context_method.rb