Module: Servus::Testing::ExampleBuilders
- Defined in:
- lib/servus/testing/example_builders.rb
Overview
Provides helper methods for extracting example values from service schemas.
This module is designed to be included in test files (RSpec, Minitest, etc.) to provide convenient access to schema example values. It's particularly useful for generating test fixtures without manually maintaining separate factory files.
The servus_ prefix on method names prevents naming collisions with other
testing libraries and makes it clear these are Servus-specific helpers.
Instance Method Summary collapse
-
#servus_arguments_example(service_class, overrides = {}) ⇒ Hash<Symbol, Object>
Extracts example argument values from a service's schema.
-
#servus_result_example(service_class, overrides = {}) ⇒ Servus::Support::Response
Extracts example result values from a service's schema.
Instance Method Details
#servus_arguments_example(service_class, overrides = {}) ⇒ Hash<Symbol, Object>
Override keys can be strings or symbols; they'll be converted to symbols
Returns empty hash if service has no arguments schema defined
Extracts example argument values from a service's schema.
Looks for example or examples keywords in the service's arguments schema
and returns them as a hash ready to be passed to the service's .call method.
75 76 77 |
# File 'lib/servus/testing/example_builders.rb', line 75 def servus_arguments_example(service_class, overrides = {}) extract_example_from(service_class, :arguments, overrides) end |
#servus_result_example(service_class, overrides = {}) ⇒ Servus::Support::Response
Override keys can be strings or symbols; they'll be converted to symbols
Returns empty hash if service has no result schema defined
Extracts example result values from a service's schema.
Looks for example or examples keywords in the service's result schema
and returns them as a hash. Useful for validating service response structure
and expected data shapes in tests.
113 114 115 116 117 |
# File 'lib/servus/testing/example_builders.rb', line 113 def servus_result_example(service_class, overrides = {}) example = extract_example_from(service_class, :result, overrides) # Wrap in a successful Response object Servus::Support::Response.new(true, example, nil) end |