Sha256: 74bb6bf271d5eb5899e8a8cba26cfbf4d0aa00e3cf93305eb650c839d024d894

Contents?: true

Size: 1.34 KB

Versions: 17

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # Helper methods to find RSpec metadata.
      module Metadata
        extend RuboCop::NodePattern::Macros

        include RuboCop::RSpec::Language

        # @!method rspec_metadata(node)
        def_node_matcher :rspec_metadata, <<~PATTERN
          (block
            (send
              #rspec? {#Examples.all #ExampleGroups.all #SharedGroups.all #Hooks.all} _ ${send str sym}* (hash $...)?)
            ...)
        PATTERN

        # @!method rspec_configure(node)
        def_node_matcher :rspec_configure, <<~PATTERN
          (block (send #rspec? :configure) (args (arg $_)) ...)
        PATTERN

        # @!method metadata_in_block(node)
        def_node_search :metadata_in_block, <<~PATTERN
          (send (lvar %) #Hooks.all _ ${send str sym}* (hash $...)?)
        PATTERN

        def on_block(node)
          rspec_configure(node) do |block_var|
            metadata_in_block(node, block_var) do |symbols, pairs|
              on_metadata(symbols, pairs.flatten)
            end
          end

          rspec_metadata(node) do |symbols, pairs|
            on_metadata(symbols, pairs.flatten)
          end
        end
        alias on_numblock on_block

        def on_metadata(_symbols, _pairs)
          raise ::NotImplementedError
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 4 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/mixin/metadata.rb
rubocop-rspec-2.23.2 lib/rubocop/cop/rspec/mixin/metadata.rb
rubocop-rspec-2.23.1 lib/rubocop/cop/rspec/mixin/metadata.rb
rubocop-rspec-2.23.0 lib/rubocop/cop/rspec/mixin/metadata.rb
mlh-rubocop-config-1.0.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/mixin/metadata.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/mixin/metadata.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/mixin/metadata.rb
fablicop-1.10.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/mixin/metadata.rb
rubocop-rspec-2.22.0 lib/rubocop/cop/rspec/mixin/metadata.rb
rubocop-rspec-2.21.0 lib/rubocop/cop/rspec/mixin/metadata.rb
rubocop-rspec-2.20.0 lib/rubocop/cop/rspec/mixin/metadata.rb
rubocop-rspec-2.19.0 lib/rubocop/cop/rspec/mixin/metadata.rb
rubocop-rspec-2.18.1 lib/rubocop/cop/rspec/mixin/metadata.rb
rubocop-rspec-2.18.0 lib/rubocop/cop/rspec/mixin/metadata.rb
rubocop-rspec-2.17.1 lib/rubocop/cop/rspec/mixin/metadata.rb
rubocop-rspec-2.17.0 lib/rubocop/cop/rspec/mixin/metadata.rb
rubocop-rspec-2.16.0 lib/rubocop/cop/rspec/mixin/metadata.rb