Sha256: 620d910eb0a439b0e3f28e69563bd745bf9175cb96a5fed9cb5ee194c1b28815

Contents?: true

Size: 1.1 KB

Versions: 13

Compression:

Stored size: 1.1 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 { |group| example_group?(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

13 entries across 13 versions & 4 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-3.0.3/lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-3.3.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-3.2.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-3.1.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-3.0.5 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-3.0.4 lib/rubocop/cop/rspec/multiple_describes.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-3.0.3 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-3.0.2 lib/rubocop/cop/rspec/multiple_describes.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-3.0.1 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-3.0.0 lib/rubocop/cop/rspec/multiple_describes.rb
rubocop-rspec-3.0.0.pre lib/rubocop/cop/rspec/multiple_describes.rb