Class: RSpec::JsonMatchers::Expectations::Mixins::BuiltIn::ArrayOf
- Inherits:
-
Core::SingleValueCallableExpectation
- Object
- RSpec::JsonMatchers::Expectation
- Core::CallableExpectation
- Core::SingleValueCallableExpectation
- RSpec::JsonMatchers::Expectations::Mixins::BuiltIn::ArrayOf
- Defined in:
- lib/rspec/json_matchers/expectations/mixins/built_in.rb
Overview
Takes exactly one object and converts to an expectation object (if not already) Validates value to be Array And uses stored expectation for checking all elements of value
Instance Method Summary collapse
-
#allow_empty(allow = true) ⇒ ArrayOf
Enumerable#all? returns
truewhen collection is empty So this method can be called to signal the expectation to do or do not expect an empty collection. -
#disallow_empty ⇒ ArrayOf
A more verbose alias for ‘allow_empty(false)`.
- #expect?(value) ⇒ Boolean
Methods inherited from Core::SingleValueCallableExpectation
Methods inherited from Core::CallableExpectation
Methods inherited from RSpec::JsonMatchers::Expectation
Instance Method Details
#allow_empty(allow = true) ⇒ ArrayOf
Enumerable#all? returns true when collection is empty So this method can be called to signal the expectation to do or do not expect an empty collection
87 88 89 90 |
# File 'lib/rspec/json_matchers/expectations/mixins/built_in.rb', line 87 def allow_empty(allow = true) @empty_allowed = allow self end |
#disallow_empty ⇒ ArrayOf
A more verbose alias for ‘allow_empty(false)`
95 96 97 |
# File 'lib/rspec/json_matchers/expectations/mixins/built_in.rb', line 95 def disallow_empty allow_empty(false) end |
#expect?(value) ⇒ Boolean
72 73 74 75 76 |
# File 'lib/rspec/json_matchers/expectations/mixins/built_in.rb', line 72 def expect?(value) value.is_a?(Array) && (empty_allowed? || !value.empty?) && value.all? { |v| children_elements_expectation.expect?(v) } end |