Sha256: 70ffe0f5fc5c2e4f63239a7dc1b92b9b4eccdc6c76ca493d32af55ebd9472df5

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # Checks for multiple top level describes.
      #
      # Multiple descriptions for the same class or module should either
      # be nested or separated into different test files.
      #
      # @example
      #   # bad
      #   describe MyClass, '.do_something' do
      #   end
      #   describe MyClass, '.do_something_else' do
      #   end
      #
      #   #good
      #   describe MyClass
      #     describe '.do_something' do
      #     end
      #     describe '.do_something_else' do
      #     end
      #   end
      class MultipleDescribes < Cop
        include RuboCop::RSpec::SpecOnly,
                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

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-rspec-1.8.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.7.0 lib/rubocop/cop/rspec/multiple_describes.rb