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

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

Overview

Submatcher for validating custom ‘must` validation rules.

## Purpose

Validates that an attribute has the expected custom validation rules defined via the ‘must` option. Excludes dynamic options that are tested separately (consists_of, schema, be_inclusion, be_target).

## Usage

“‘ruby it { is_expected.to have_service_input(:email).must() } it { is_expected.to have_service_input(:age).must([:be_positive, :be_adult]) } “`

## Comparison

Uses set difference to compare validation names - order doesn’t matter.

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, must_names) ⇒ MustSubmatcher

Creates a new must submatcher.

Parameters:

  • context (Base::SubmatcherContext)

    The submatcher context

  • must_names (Array<Symbol>)

    Expected validation rule names



33
34
35
36
# File 'lib/servactory/test_kit/rspec/matchers/submatchers/shared/must_submatcher.rb', line 33

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

Instance Method Details

#descriptionString

Returns description for RSpec output.

Returns:

  • (String)

    Human-readable description with rule names



41
42
43
# File 'lib/servactory/test_kit/rspec/matchers/submatchers/shared/must_submatcher.rb', line 41

def description
  "must: #{must_names.join(', ')}"
end