Class: RSpec::JsonMatchers::Expectations::Mixins::BuiltIn::ArrayOf

Inherits:
Core::SingleValueCallableExpectation show all
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

Methods inherited from Core::SingleValueCallableExpectation

[]

Methods inherited from Core::CallableExpectation

[]

Methods inherited from RSpec::JsonMatchers::Expectation

build, build_many

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

Parameters:

  • allow (Boolean) (defaults to: true)

    optional Should empty collection be “expected”

Returns:



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_emptyArrayOf

A more verbose alias for ‘allow_empty(false)`

Returns:



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

Returns:

  • (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