Class: Servactory::TestKit::Rspec::Matchers::Submatchers::Shared::TargetSubmatcher

Inherits:
Base::Submatcher
  • Object
show all
Defined in:
lib/servactory/test_kit/rspec/matchers/submatchers/shared/target_submatcher.rb

Overview

Submatcher for validating target constraints.

## Purpose

Validates that an attribute has the expected target values defined. Targets are similar to inclusions but can be named differently (e.g., :target, :category, :group).

## Usage

“‘ruby it { is_expected.to have_service_input(:category).target([Category::A, Category::B], name: :category) } it { is_expected.to have_service_input(:type).target(%i[user admin], name: :type) } “`

## Comparison

Uses set difference to compare values - order doesn’t matter. Supports both single values and arrays.

Constant Summary collapse

OPTION_BODY_KEY =

Key for the target values within the option

:in

Instance Attribute Summary

Attributes inherited from Base::Submatcher

#missing_option

Instance Method Summary collapse

Methods inherited from Base::Submatcher

#failure_message, #failure_message_when_negated, #matches?

Methods included from Concerns::ValueComparison

included

Methods included from Concerns::ErrorMessageBuilder

included

Methods included from Concerns::AttributeDataAccess

included

Constructor Details

#initialize(context, option_name, values) ⇒ TargetSubmatcher

Creates a new target submatcher.

Parameters:

  • context (Base::SubmatcherContext)

    The submatcher context

  • option_name (Symbol)

    The name of the target option

  • values (Array)

    Expected target values



38
39
40
41
42
# File 'lib/servactory/test_kit/rspec/matchers/submatchers/shared/target_submatcher.rb', line 38

def initialize(context, option_name, values)
  super(context)
  @option_name = option_name
  @values = values
end

Instance Method Details

#descriptionString

Returns description for RSpec output.

Returns:

  • (String)

    Human-readable description with target values



47
48
49
# File 'lib/servactory/test_kit/rspec/matchers/submatchers/shared/target_submatcher.rb', line 47

def description
  "#{option_name}: #{formatted_values}"
end