Sha256: 11e4a8a03131ec46fead9b88397b0f4c7fcbf7d677c49d02a28b205084e154f0

Contents?: true

Size: 1.03 KB

Versions: 16

Compression:

Stored size: 1.03 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 do
      #     describe '.do_something' do
      #     end
      #     describe '.do_something_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, location: :expression)
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
rubocop-rspec-1.32.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.31.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.30.1 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.30.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.29.1 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.29.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.28.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.27.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.26.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.25.1 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.25.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.24.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.23.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.22.2 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.22.1 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-1.22.0 lib/rubocop/cop/rspec/multiple_describes.rb