Sha256: 69807391474c511db0a94f4bf1de067e8c4580249e9eea8580640df55b6cb04f

Contents?: true

Size: 990 Bytes

Versions: 5

Compression:

Stored size: 990 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

        METHOD_STRING_MATCHER = /\A[\#\.].+/

        def on_top_level_describe(_node, (_, second_arg))
          return unless second_arg && second_arg.str_type?
          return if METHOD_STRING_MATCHER =~ one(second_arg.children)

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubocop-rspec-1.18.0 lib/rubocop/cop/rspec/describe_method.rb
rubocop-rspec-1.17.1 lib/rubocop/cop/rspec/describe_method.rb
rubocop-rspec-1.17.0 lib/rubocop/cop/rspec/describe_method.rb
rubocop-rspec-1.16.0 lib/rubocop/cop/rspec/describe_method.rb
rubocop-rspec-1.15.1 lib/rubocop/cop/rspec/describe_method.rb