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

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

Overview

Submatcher for validating inclusion constraints.

## Purpose

Validates that an attribute has the expected inclusion values. Inclusion restricts attribute values to a specific set of allowed values.

## Usage

“‘ruby it { is_expected.to have_service_input(:status).inclusion(%w[active inactive pending]) } it { is_expected.to have_service_input(:priority).inclusion([1, 2, 3]) } “`

## Comparison

Uses set difference to compare values - order doesn’t matter, only the set of allowed values must match exactly.

Constant Summary collapse

OPTION_NAME =

Option name in attribute data

:inclusion
OPTION_BODY_KEY =

Key for the inclusion 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, values) ⇒ InclusionSubmatcher

Creates a new inclusion submatcher.

Parameters:



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

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

Instance Method Details

#descriptionString

Returns description for RSpec output.

Returns:

  • (String)

    Human-readable description with values



46
47
48
49
50
51
52
# File 'lib/servactory/test_kit/rspec/matchers/submatchers/shared/inclusion_submatcher.rb', line 46

def description
  formatted = case values
              when Range then values.inspect
              else values.join(", ")
              end
  "inclusion: #{formatted}"
end