Sha256: 8e1dabda8211c65454f0763ff9d5ba1e10904d54b277b0e13ac0c927dc9f8680

Contents?: true

Size: 929 Bytes

Versions: 1

Compression:

Stored size: 929 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'."

        def on_top_level_describe(_node, (_, second_arg))
          return unless 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

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-rspec-1.33.0 lib/rubocop/cop/rspec/describe_method.rb