Class: Servactory::TestKit::Rspec::Matchers::Submatchers::Shared::InclusionSubmatcher
- Inherits:
-
Base::Submatcher
- Object
- Base::Submatcher
- Servactory::TestKit::Rspec::Matchers::Submatchers::Shared::InclusionSubmatcher
- Defined in:
- lib/servactory/test_kit/rspec/matchers/submatchers/shared/inclusion_submatcher.rb
Overview
Submatcher for validating inclusion constraints.
## Purpose
Validates that an attribute has the expected inclusion values. Inclusion restricts attribute values to a specific set of allowed values.
## Usage
“‘ruby it { is_expected.to have_service_input(:status).inclusion(%w[active inactive pending]) } it { is_expected.to have_service_input(:priority).inclusion([1, 2, 3]) } “`
## Comparison
Uses set difference to compare values - order doesn’t matter, only the set of allowed values must match exactly.
Constant Summary collapse
- OPTION_NAME =
Option name in attribute data
:inclusion- OPTION_BODY_KEY =
Key for the inclusion values within the option
:in
Instance Attribute Summary
Attributes inherited from Base::Submatcher
Instance Method Summary collapse
-
#description ⇒ String
Returns description for RSpec output.
-
#initialize(context, values) ⇒ InclusionSubmatcher
constructor
Creates a new inclusion 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, values) ⇒ InclusionSubmatcher
Creates a new inclusion submatcher.
38 39 40 41 |
# File 'lib/servactory/test_kit/rspec/matchers/submatchers/shared/inclusion_submatcher.rb', line 38 def initialize(context, values) super(context) @values = values end |
Instance Method Details
#description ⇒ String
Returns description for RSpec output.
46 47 48 49 50 51 52 |
# File 'lib/servactory/test_kit/rspec/matchers/submatchers/shared/inclusion_submatcher.rb', line 46 def description formatted = case values when Range then values.inspect else values.join(", ") end "inclusion: #{formatted}" end |