Sha256: 8b3d1db20bcf60f7d291aeb69adb911cdc305dc40531d5dc643ad4d58f2dba62

Contents?: true

Size: 1.08 KB

Versions: 19

Compression:

Stored size: 1.08 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

19 entries across 17 versions & 2 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.12.1/lib/rubocop/cop/rspec/multiple_describes.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.9.0/lib/rubocop/cop/rspec/multiple_describes.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.12.1/lib/rubocop/cop/rspec/multiple_describes.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.9.0/lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.12.1 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.12.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.11.1 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.11.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.10.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.9.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.8.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.7.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.6.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.5.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.4.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.3.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.2.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.1.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-2.0.1 lib/rubocop/cop/rspec/multiple_describes.rb