Class: Servactory::TestKit::Rspec::Matchers::Submatchers::Shared::MessageSubmatcher
- Inherits:
-
Base::Submatcher
- Object
- Base::Submatcher
- Servactory::TestKit::Rspec::Matchers::Submatchers::Shared::MessageSubmatcher
- 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
Instance Method Summary collapse
-
#description ⇒ String
Returns description for RSpec output.
-
#initialize(context, custom_message) ⇒ MessageSubmatcher
constructor
Creates a new message submatcher.
Methods inherited from Base::Submatcher
#failure_message, #failure_message_when_negated, #matches?
Methods included from Concerns::ValueComparison
Methods included from Concerns::ErrorMessageBuilder
Methods included from Concerns::AttributeDataAccess
Constructor Details
#initialize(context, custom_message) ⇒ MessageSubmatcher
Creates a new message submatcher.
40 41 42 43 |
# File 'lib/servactory/test_kit/rspec/matchers/submatchers/shared/message_submatcher.rb', line 40 def initialize(context, ) super(context) @custom_message = end |
Instance Method Details
#description ⇒ String
Returns description for RSpec output.
48 49 50 |
# File 'lib/servactory/test_kit/rspec/matchers/submatchers/shared/message_submatcher.rb', line 48 def description "message: #{@attribute_schema_message}" end |