Sha256: fd15896aa51e85eb07dde2fc814d186ea0f36311857016d0e7c09606e61efb63

Contents?: true

Size: 1.09 KB

Versions: 40

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # Checks for multiple top-level example groups.
      #
      # 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 < Base
        include TopLevelGroup

        MSG = 'Do not use multiple top-level example groups - try to nest them.'

        def on_top_level_group(node)
          top_level_example_groups =
            top_level_groups.select(&method(:example_group?))

          return if top_level_example_groups.one?
          return unless top_level_example_groups.first.equal?(node)

          add_offense(node.send_node)
        end
      end
    end
  end
end

Version data entries

40 entries across 38 versions & 4 rubygems

Version Path
rubocop-rspec-2.31.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.30.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.29.2 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.29.1 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.29.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.28.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.27.1 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.27.0 lib/rubocop/cop/rspec/multiple_describes.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.26.1/lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.26.1 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.26.0 lib/rubocop/cop/rspec/multiple_describes.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/multiple_describes.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.13.1/lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.25.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.24.1 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.24.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.23.2 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.23.1 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.23.0 lib/rubocop/cop/rspec/multiple_describes.rb
mlh-rubocop-config-1.0.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/multiple_describes.rb