Class: Servactory::TestKit::Rspec::Helpers::InputValidator
- Inherits:
-
Object
- Object
- Servactory::TestKit::Rspec::Helpers::InputValidator
- Includes:
- Concerns::ErrorMessages
- Defined in:
- lib/servactory/test_kit/rspec/helpers/input_validator.rb
Overview
Validates mock input values against service definitions.
## Purpose
Ensures that mocked input arguments match the service’s input definitions in terms of names. Called automatically when using ‘.with()` on the fluent builder.
## Usage
Called automatically from ServiceMockBuilder:
“‘ruby allow_service(MyService)
.with(user_id: 123)
.succeeds(result: "ok")
“‘
Can also be called directly:
“‘ruby InputValidator.validate!(
service_class: MyService,
inputs_matcher: { user_id: 123 }
) “‘
## Supported Matcher Types
-
Hash - validates all keys against service inputs
-
‘including(hash)` - validates specified keys only
-
‘any_inputs` - skips validation (accepts anything)
-
‘no_inputs` - validates service has no required inputs
-
‘excluding(hash)` - skips validation (cannot validate exclusion)
Defined Under Namespace
Classes: ValidationError
Class Method Summary collapse
-
.validate!(service_class:, inputs_matcher:) ⇒ void
Validates inputs and raises on failure.
Instance Method Summary collapse
-
#initialize(service_class:, inputs_matcher:) ⇒ InputValidator
constructor
Creates a new validator instance.
-
#validate! ⇒ void
Runs validation based on matcher type.
Constructor Details
#initialize(service_class:, inputs_matcher:) ⇒ InputValidator
Creates a new validator instance.
64 65 66 67 |
# File 'lib/servactory/test_kit/rspec/helpers/input_validator.rb', line 64 def initialize(service_class:, inputs_matcher:) @service_class = service_class @inputs_matcher = inputs_matcher end |
Class Method Details
.validate!(service_class:, inputs_matcher:) ⇒ void
This method returns an undefined value.
Validates inputs and raises on failure.
54 55 56 |
# File 'lib/servactory/test_kit/rspec/helpers/input_validator.rb', line 54 def validate!(service_class:, inputs_matcher:) new(service_class:, inputs_matcher:).validate! end |
Instance Method Details
#validate! ⇒ void
This method returns an undefined value.
Runs validation based on matcher type.
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/servactory/test_kit/rspec/helpers/input_validator.rb', line 73 def validate! keys_to_validate = extract_keys_for_validation return if keys_to_validate.nil? if keys_to_validate == :no_args validate_service_has_no_required_inputs! else validate_input_names!(keys_to_validate) end end |