Sha256: bb7d6d10d899367fd9f5664667c88ff3fe785c8b9cafe9ecd546080a8901568b

Contents?: true

Size: 921 Bytes

Versions: 1

Compression:

Stored size: 921 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # Avoid opening modules and defining specs within them.
      #
      # @example
      #   # bad
      #   module MyModule
      #     RSpec.describe MyClass do
      #       # ...
      #     end
      #   end
      #
      #   # good
      #   RSpec.describe MyModule::MyClass do
      #     # ...
      #   end
      #
      # @see https://github.com/rubocop/rubocop-rspec/issues/735
      class DescribedClassModuleWrapping < Base
        MSG = 'Avoid opening modules and defining specs within them.'

        # @!method find_rspec_blocks(node)
        def_node_search :find_rspec_blocks, <<~PATTERN
          (block (send #explicit_rspec? #ExampleGroups.all ...) ...)
        PATTERN

        def on_module(node)
          find_rspec_blocks(node) do
            add_offense(node)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-rspec-2.19.0 lib/rubocop/cop/rspec/described_class_module_wrapping.rb