Sha256: 2dd24e0beab4252bf0e8bf564c6cf980162d6ceb755f6e53fb6a2691b66c341c

Contents?: true

Size: 968 Bytes

Versions: 9

Compression:

Stored size: 968 Bytes

Contents

# encoding: utf-8

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

        MESSAGE = 'Do not use multiple top level describes - try to nest them.'

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

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rubocop-rspec-1.3.1 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.3.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.2.2 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.2.1 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.2.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.1.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.0.1 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.0.rc3 lib/rubocop/cop/rspec/multiple_describes.rb