Class: Servactory::TestKit::Rspec::Matchers::Submatchers::Shared::ConsistsOfSubmatcher
- Inherits:
-
Base::Submatcher
- Object
- Base::Submatcher
- Servactory::TestKit::Rspec::Matchers::Submatchers::Shared::ConsistsOfSubmatcher
- Defined in:
- lib/servactory/test_kit/rspec/matchers/submatchers/shared/consists_of_submatcher.rb
Overview
Submatcher for validating Array/Hash element types.
## Purpose
Validates that an Array or Hash attribute specifies the expected element types via the ‘consists_of` option. Used with collection attributes to verify their content type constraints.
## Usage
“‘ruby it { is_expected.to have_service_input(:items).type(Array).consists_of(Item) } it { is_expected.to have_service_input(:users).type(Array).consists_of(User, Admin) } it { is_expected.to have_service_internal(:data).type(Hash).consists_of(String) } “`
## Note
Requires the ‘:types` option to be set first (via `.type` chain).
Constant Summary collapse
- OPTION_NAME =
Option name in attribute data
:consists_of- OPTION_BODY_KEY =
Key for the type value within the option
:type
Instance Attribute Summary
Attributes inherited from Base::Submatcher
Instance Method Summary collapse
-
#description ⇒ String
Returns description for RSpec output.
-
#initialize(context, consists_of_types) ⇒ ConsistsOfSubmatcher
constructor
Creates a new consists_of 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, consists_of_types) ⇒ ConsistsOfSubmatcher
Creates a new consists_of submatcher.
39 40 41 42 |
# File 'lib/servactory/test_kit/rspec/matchers/submatchers/shared/consists_of_submatcher.rb', line 39 def initialize(context, consists_of_types) super(context) @consists_of_types = consists_of_types end |
Instance Method Details
#description ⇒ String
Returns description for RSpec output.
47 48 49 |
# File 'lib/servactory/test_kit/rspec/matchers/submatchers/shared/consists_of_submatcher.rb', line 47 def description "consists_of: #{consists_of_types.map(&:name).join(', ')}" end |