Sha256: ceda3944e16045f3bd9e3bd2a06100a7be50b84150e507fe2dd2b5066cec2e11

Contents?: true

Size: 1.07 KB

Versions: 16

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # Checks that the second argument to `describe` specifies a method.
      #
      # @example
      #   # bad
      #   describe MyClass, 'do something' do
      #   end
      #
      #   # good
      #   describe MyClass, '#my_instance_method' do
      #   end
      #
      #   describe MyClass, '.my_class_method' do
      #   end
      class DescribeMethod < Base
        include TopLevelGroup

        MSG = 'The second argument to describe should be the method ' \
              "being tested. '#instance' or '.class'."

        # @!method second_argument(node)
        def_node_matcher :second_argument, <<~PATTERN
          (block
            (send #rspec? :describe _first_argument $(str _) ...) ...
          )
        PATTERN

        def on_top_level_group(node)
          second_argument = second_argument(node)

          return unless second_argument
          return if second_argument.str_content.start_with?('#', '.')

          add_offense(second_argument)
        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/describe_method.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.9.0/lib/rubocop/cop/rspec/describe_method.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.12.1/lib/rubocop/cop/rspec/describe_method.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.9.0/lib/rubocop/cop/rspec/describe_method.rb
rubocop-rspec-2.12.1 lib/rubocop/cop/rspec/describe_method.rb
rubocop-rspec-2.12.0 lib/rubocop/cop/rspec/describe_method.rb
rubocop-rspec-2.11.1 lib/rubocop/cop/rspec/describe_method.rb
rubocop-rspec-2.11.0 lib/rubocop/cop/rspec/describe_method.rb
rubocop-rspec-2.10.0 lib/rubocop/cop/rspec/describe_method.rb
rubocop-rspec-2.9.0 lib/rubocop/cop/rspec/describe_method.rb
rubocop-rspec-2.8.0 lib/rubocop/cop/rspec/describe_method.rb
rubocop-rspec-2.7.0 lib/rubocop/cop/rspec/describe_method.rb
rubocop-rspec-2.6.0 lib/rubocop/cop/rspec/describe_method.rb
rubocop-rspec-2.5.0 lib/rubocop/cop/rspec/describe_method.rb
rubocop-rspec-2.4.0 lib/rubocop/cop/rspec/describe_method.rb
rubocop-rspec-2.3.0 lib/rubocop/cop/rspec/describe_method.rb