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

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

Overview

Submatcher for validating Array/Hash element types.

## Purpose

Validates that an Array or Hash attribute specifies the expected element types via the ‘consists_of` option. Used with collection attributes to verify their content type constraints.

## Usage

“‘ruby it { is_expected.to have_service_input(:items).type(Array).consists_of(Item) } it { is_expected.to have_service_input(:users).type(Array).consists_of(User, Admin) } it { is_expected.to have_service_internal(:data).type(Hash).consists_of(String) } “`

## Note

Requires the ‘:types` option to be set first (via `.type` chain).

Constant Summary collapse

OPTION_NAME =

Option name in attribute data

:consists_of
OPTION_BODY_KEY =

Key for the type value within the option

:type

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, consists_of_types) ⇒ ConsistsOfSubmatcher

Creates a new consists_of submatcher.

Parameters:

  • context (Base::SubmatcherContext)

    The submatcher context

  • consists_of_types (Array<Class>)

    Expected element types



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

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

Instance Method Details

#descriptionString

Returns description for RSpec output.

Returns:

  • (String)

    Human-readable description with element types



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

def description
  "consists_of: #{consists_of_types.map(&:name).join(', ')}"
end