Class: NormalizedHash::Matchers::ArrayValues
- Inherits:
-
HashMatchers
- Object
- HashMatchers
- NormalizedHash::Matchers::ArrayValues
- Defined in:
- lib/normalized_hash/array_values.rb
Overview
RSpec::Matchers class for testing hierarchically arrays, that are elements of deep hash.
ArrayValues class ensures that all values of the tested Array belong to expected classes.
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message_for_should ⇒ Object
- #failure_message_for_should_not ⇒ Object
-
#matches?(target) ⇒ Boolean
Test that all values of the tested Array belong to expecetd class(es).
Methods inherited from HashMatchers
Constructor Details
This class inherits a constructor from NormalizedHash::Matchers::HashMatchers
Instance Method Details
#description ⇒ Object
86 87 88 |
# File 'lib/normalized_hash/array_values.rb', line 86 def description "have every value one of class: #{@expectation.join ','}" end |
#failure_message_for_should ⇒ Object
114 115 116 |
# File 'lib/normalized_hash/array_values.rb', line 114 def "expected #{@target.inspect} to have values of classes #{@expectation.inspect}" end |
#failure_message_for_should_not ⇒ Object
118 119 120 |
# File 'lib/normalized_hash/array_values.rb', line 118 def "expected #{@target.inspect} differ from #{@expectation.inspect}" end |
#matches?(target) ⇒ Boolean
Test that all values of the tested Array belong to expecetd class(es).
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/normalized_hash/array_values.rb', line 96 def matches?(target) result = true @target, @actual = target, target.map(&:class).uniq case @target when Array result &&= (@actual - @expectation).empty? when Hash @target.each_value do |val| result &&= ArrayValues.new(@expectation).matches?(val) if [Hash, Array].include? val.class @target = val unless result end end result end |