Sha256: 743734d2538097f2d0f90d7df31802a914857dc658e2a384e6a8585ad1b90d20

Contents?: true

Size: 1.05 KB

Versions: 6

Compression:

Stored size: 1.05 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 RuboCop::RSpec::TopLevelGroup

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

        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

6 entries across 6 versions & 1 rubygems

Version Path
rubocop-rspec-2.0.0.pre lib/rubocop/cop/rspec/describe_method.rb
rubocop-rspec-1.44.1 lib/rubocop/cop/rspec/describe_method.rb
rubocop-rspec-1.44.0 lib/rubocop/cop/rspec/describe_method.rb
rubocop-rspec-1.43.2 lib/rubocop/cop/rspec/describe_method.rb
rubocop-rspec-1.43.1 lib/rubocop/cop/rspec/describe_method.rb
rubocop-rspec-1.43.0 lib/rubocop/cop/rspec/describe_method.rb