Class: NormalizedHash::Matchers::SameArrayValues
- Inherits:
-
HashMatchers
- Object
- HashMatchers
- NormalizedHash::Matchers::SameArrayValues
- Defined in:
- lib/normalized_hash/array_values.rb
Overview
RSpec::Matchers class for testing hierarchically arrays, that are elements of deep hash.
SameArrayValues class tests that all values of the Array are on the same class.
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 are of the same class.
Methods inherited from HashMatchers
Constructor Details
This class inherits a constructor from NormalizedHash::Matchers::HashMatchers
Instance Method Details
#description ⇒ Object
40 41 42 |
# File 'lib/normalized_hash/array_values.rb', line 40 def description "have all values of the same class" end |
#failure_message_for_should ⇒ Object
68 69 70 |
# File 'lib/normalized_hash/array_values.rb', line 68 def "expected #{@actual.inspect} to be one class" end |
#failure_message_for_should_not ⇒ Object
72 73 74 |
# File 'lib/normalized_hash/array_values.rb', line 72 def "expected #{@actual.inspect} be at least 2 different classes" end |
#matches?(target) ⇒ Boolean
Test that all values of the tested Array are of the same class
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/normalized_hash/array_values.rb', line 49 def matches? target result = true case target when Array @actual = target.map(&:class).uniq result = !(@actual.count > 1) when Hash target.each_value do |val| if val.is_a? Array result &&= SameArrayValues.new(Object).matches? val @actual = val.map(&:class).uniq unless result end end end result end |