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

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

Overview

Submatcher for validating custom error messages.

## Purpose

Validates that the previous submatcher’s option has the expected custom error message. Must be used after another submatcher that defines an option with a message field.

## Usage

“‘ruby it { is_expected.to have_service_input(:email).inclusion(%w[a b]).message(“Invalid email”) } it { is_expected.to have_service_input(:data).schema({ key: String }).message(“Invalid schema”) } “`

## Note

Requires ‘requires_last_submatcher: true` - must follow another submatcher. Uses the previous submatcher’s OPTION_NAME constant to find the message field.

Constant Summary collapse

OPTION_NAME =

Option name in attribute data (unused - uses last submatcher’s)

:message
OPTION_BODY_KEY =

Key for the message within the option

:message

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, custom_message) ⇒ MessageSubmatcher

Creates a new message submatcher.

Parameters:



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

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

Instance Method Details

#descriptionString

Returns description for RSpec output.

Returns:

  • (String)

    Human-readable description with message



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

def description
  "message: #{@attribute_schema_message}"
end