Sha256: 2e052480c6078142261811e7bbca5668e404e15b9ad4678a6c576c869103c371

Contents?: true

Size: 892 Bytes

Versions: 2

Compression:

Stored size: 892 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    # Checks that the second argument to the top level describe is the tested
    # method name.
    #
    # @example
    #   # bad
    #   describe MyClass, 'do something' do
    #   end
    #
    #   # good
    #   describe MyClass, '#my_instance_method' do
    #   end
    #
    #   describe MyClass, '.my_class_method' do
    #   end
    class RSpecDescribeMethod < Cop
      include RSpec::TopLevelDescribe

      MESSAGE = 'The second argument to describe should be the method being ' \
                "tested. '#instance' or '.class'"
      METHOD_STRING_MATCHER = /^[\#\.].+/

      def on_top_level_describe(_node, args)
        second_arg = args[1]
        return unless second_arg
        return if METHOD_STRING_MATCHER =~ second_arg.children.first

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-rspec-1.0.rc2 lib/rubocop/cop/rspec_describe_method.rb
rubocop-rspec-1.0.rc1 lib/rubocop/cop/rspec_describe_method.rb