Sha256: 03c07f0e31548a32f86aa50b10615d2973c74338ae274546613ce794b8ffd530

Contents?: true

Size: 998 Bytes

Versions: 3

Compression:

Stored size: 998 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # Checks for multiple top level describes. They should be nested if it is
      # for the same class or module or seperated into different files.
      #
      # @example
      #   # bad
      #   describe MyClass, '.do_someting' do
      #   end
      #   describe MyClass, '.do_someting_else' do
      #   end
      #
      #   #good
      #   describe MyClass
      #     describe '.do_someting' do
      #     end
      #     describe '.do_someting_else' do
      #     end
      #   end
      class MultipleDescribes < Cop
        include RuboCop::RSpec::TopLevelDescribe

        MSG = 'Do not use multiple top level describes - ' \
              'try to nest them.'.freeze

        def on_top_level_describe(node, _args)
          return if single_top_level_describe?
          return unless top_level_nodes.first.equal?(node)

          add_offense(node, :expression)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubocop-rspec-1.6.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.5.3 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.5.2 lib/rubocop/cop/rspec/multiple_describes.rb