Module: Servactory::TestKit::Rspec::Matchers::Base::SubmatcherRegistry::ClassMethods

Defined in:
lib/servactory/test_kit/rspec/matchers/base/submatcher_registry.rb

Overview

Class methods added to the including class.

Instance Method Summary collapse

Instance Method Details

#inherited(subclass) ⇒ void

This method returns an undefined value.

Copies submatcher definitions to subclasses.

Parameters:

  • subclass (Class)

    The inheriting class



104
105
106
107
108
109
110
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_registry.rb', line 104

def inherited(subclass)
  super
  subclass.instance_variable_set(
    :@submatcher_definitions,
    submatcher_definitions.dup
  )
end

#register_submatcher(name, options = {}) ⇒ SubmatcherDefinition

Registers a new submatcher with configuration options.

## Options

  • ‘:class_name` - Relative class path (e.g., “Input::RequiredSubmatcher”)

  • ‘:chain_method` - Method name for fluent API (defaults to name)

  • ‘:chain_aliases` - Additional method names that call chain_method

  • ‘:transform_args` - Lambda to transform method args before passing to submatcher

  • ‘:requires_option_types` - Pass option_types to submatcher context

  • ‘:requires_last_submatcher` - Pass previous submatcher to context

  • ‘:mutually_exclusive_with` - Array of submatcher names to remove when this is added

  • ‘:stores_option_types` - Store transformed args as option_types

  • ‘:accepts_trailing_options` - Extract trailing hash as keyword arguments

Parameters:

  • name (Symbol)

    Unique identifier for this submatcher

  • options (Hash) (defaults to: {})

    Configuration options

Returns:



85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_registry.rb', line 85

def register_submatcher(name, options = {}) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
  submatcher_definitions[name] = SubmatcherDefinition.new(
    name:,
    class_name: options[:class_name],
    chain_method: options[:chain_method] || name,
    chain_aliases: options[:chain_aliases] || [],
    transform_args: options[:transform_args] || ->(args, _kwargs = {}) { args },
    requires_option_types: options[:requires_option_types] || false,
    requires_last_submatcher: options[:requires_last_submatcher] || false,
    mutually_exclusive_with: options[:mutually_exclusive_with] || [],
    stores_option_types: options[:stores_option_types] || false,
    accepts_trailing_options: options[:accepts_trailing_options] || false
  )
end

#submatcher_definitionsHash{Symbol => SubmatcherDefinition}

Returns the hash of registered submatcher definitions.

Returns:



64
65
66
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher_registry.rb', line 64

def submatcher_definitions
  @submatcher_definitions ||= {}
end