Sha256: 8b00fce52b0e5fd6537c20d0aa6e846b9771ff89b4193b685a837b8a3caef929

Contents?: true

Size: 940 Bytes

Versions: 38

Compression:

Stored size: 940 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 include_rspec_blocks?(node)
        def_node_search :include_rspec_blocks?, <<~PATTERN
          ({block numblock} (send #explicit_rspec? #ExampleGroups.all ...) ...)
        PATTERN

        def on_module(node)
          return unless include_rspec_blocks?(node)

          add_offense(node)
        end
      end
    end
  end
end

Version data entries

38 entries across 38 versions & 7 rubygems

Version Path
rubocop-rspec-2.27.0 lib/rubocop/cop/rspec/described_class_module_wrapping.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.26.1/lib/rubocop/cop/rspec/described_class_module_wrapping.rb
rubocop-rspec-2.26.1 lib/rubocop/cop/rspec/described_class_module_wrapping.rb
rubocop-rspec-2.26.0 lib/rubocop/cop/rspec/described_class_module_wrapping.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/described_class_module_wrapping.rb
rubocop-rspec-2.25.0 lib/rubocop/cop/rspec/described_class_module_wrapping.rb
rubocop-rspec-2.24.1 lib/rubocop/cop/rspec/described_class_module_wrapping.rb
rubocop-rspec-2.24.0 lib/rubocop/cop/rspec/described_class_module_wrapping.rb
rubocop-rspec-2.23.2 lib/rubocop/cop/rspec/described_class_module_wrapping.rb
rubocop-rspec-2.23.1 lib/rubocop/cop/rspec/described_class_module_wrapping.rb
rubocop-rspec-2.23.0 lib/rubocop/cop/rspec/described_class_module_wrapping.rb
mlh-rubocop-config-1.0.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/described_class_module_wrapping.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/described_class_module_wrapping.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/described_class_module_wrapping.rb
fablicop-1.10.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/described_class_module_wrapping.rb
rubocop-rspec-2.22.0 lib/rubocop/cop/rspec/described_class_module_wrapping.rb
rubocop-rspec-2.21.0 lib/rubocop/cop/rspec/described_class_module_wrapping.rb
rubocop-rspec-2.20.0 lib/rubocop/cop/rspec/described_class_module_wrapping.rb