Class: Servactory::TestKit::Rspec::Matchers::Base::Submatcher
- Inherits:
-
Object
- Object
- Servactory::TestKit::Rspec::Matchers::Base::Submatcher
- Includes:
- RSpec::Matchers::Composable, Concerns::AttributeDataAccess, Concerns::ErrorMessageBuilder, Concerns::ValueComparison
- Defined in:
- lib/servactory/test_kit/rspec/matchers/base/submatcher.rb
Overview
Abstract base class for individual validation rules in attribute matchers.
## Purpose
Submatcher provides the foundation for specific validation checks like type validation, required/optional status, default values, etc. Each submatcher validates one aspect of a service attribute definition.
## Usage
Create a subclass and implement required abstract methods:
“‘ruby class RequiredSubmatcher < Base::Submatcher
def description
"required"
end
protected
def passes?
fetch_option(:required) == true
end
def
"expected input to be required, but it was optional"
end
end “‘
## Abstract Methods
Subclasses must implement:
-
‘description` - human-readable description for test output
-
‘passes?` - validation logic returning boolean
-
‘build_failure_message` - explanation when validation fails
## Architecture
Works with:
-
SubmatcherContext - provides attribute data and metadata
-
AttributeMatcher - manages collection of submatchers
-
Concerns - provides helper methods for data access and comparison
Direct Known Subclasses
Submatchers::Input::DefaultSubmatcher, Submatchers::Input::OptionalSubmatcher, Submatchers::Input::RequiredSubmatcher, Submatchers::Input::ValidWithSubmatcher, Submatchers::Shared::ConsistsOfSubmatcher, Submatchers::Shared::InclusionSubmatcher, Submatchers::Shared::MessageSubmatcher, Submatchers::Shared::MustSubmatcher, Submatchers::Shared::SchemaSubmatcher, Submatchers::Shared::TargetSubmatcher, Submatchers::Shared::TypesSubmatcher
Instance Attribute Summary collapse
-
#missing_option ⇒ String
readonly
Failure message when validation does not pass.
Instance Method Summary collapse
-
#description ⇒ String
abstract
Returns a human-readable description of what this submatcher validates.
-
#failure_message ⇒ String
Returns the failure message for RSpec output.
-
#failure_message_when_negated ⇒ String
Returns the failure message for negated expectations.
-
#initialize(context) ⇒ Submatcher
constructor
Creates a new submatcher instance.
-
#matches?(_subject) ⇒ Boolean
Checks if this submatcher’s validation passes.
Methods included from Concerns::ValueComparison
Methods included from Concerns::ErrorMessageBuilder
Methods included from Concerns::AttributeDataAccess
Constructor Details
#initialize(context) ⇒ Submatcher
Creates a new submatcher instance.
63 64 65 66 |
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher.rb', line 63 def initialize(context) @context = context @missing_option = "" end |
Instance Attribute Details
#missing_option ⇒ String (readonly)
Returns Failure message when validation does not pass.
58 59 60 |
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher.rb', line 58 def missing_option @missing_option end |
Instance Method Details
#description ⇒ String
Subclasses must implement this method
Returns a human-readable description of what this submatcher validates.
100 101 102 |
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher.rb', line 100 def description raise NotImplementedError, "#{self.class} must implement #description" end |
#failure_message ⇒ String
Returns the failure message for RSpec output.
84 85 86 |
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher.rb', line 84 def @missing_option end |
#failure_message_when_negated ⇒ String
Returns the failure message for negated expectations.
91 92 93 |
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher.rb', line 91 def "expected not to #{description}" end |
#matches?(_subject) ⇒ Boolean
Checks if this submatcher’s validation passes.
72 73 74 75 76 77 78 79 |
# File 'lib/servactory/test_kit/rspec/matchers/base/submatcher.rb', line 72 def matches?(_subject) if passes? true else @missing_option = false end end |