Sha256: a4584746b0ab0f7d1c3c1f9689cdc6b1a2256c7df060895f361353a92a72d839

Contents?: true

Size: 949 Bytes

Versions: 4

Compression:

Stored size: 949 Bytes

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 < Cop
        include RuboCop::RSpec::TopLevelDescribe
        include RuboCop::RSpec::Util

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

        def on_top_level_describe(_node, (_, second_arg))
          return unless second_arg && second_arg.str_type?
          return if second_arg.str_content.start_with?('#', '.')

          add_offense(second_arg, location: :expression)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-rspec-1.32.0 lib/rubocop/cop/rspec/describe_method.rb
rubocop-rspec-1.31.0 lib/rubocop/cop/rspec/describe_method.rb
rubocop-rspec-1.30.1 lib/rubocop/cop/rspec/describe_method.rb
rubocop-rspec-1.30.0 lib/rubocop/cop/rspec/describe_method.rb