Class: LookLike::NestedArrayMatcher

Inherits:
ArrayMatcher show all
Defined in:
lib/look_like/nested-array-matcher.rb

Instance Attribute Summary

Attributes inherited from Matcher

#desc, #name

Instance Method Summary collapse

Methods inherited from ArrayMatcher

#element_error, #initialize, #match_array, #match_element, #negate_error

Methods inherited from Matcher

#initialize, #negate_error

Constructor Details

This class inherits a constructor from LookLike::ArrayMatcher

Instance Method Details

#error(actual, expected) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/look_like/nested-array-matcher.rb', line 16

def error(actual, expected)
  message = []
  expected_array = expected[0]
  actual.each { |actual_array|
    message.push(match_array(actual_array, expected_array) ? "" : "x [#{super(actual_array, expected_array)}]")
  }
  "[#{message.join(", ")}]"
end

#match(actual, expected) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/look_like/nested-array-matcher.rb', line 3

def match(actual, expected)
  matches = true
  expected_array = expected[0]
  actual.each { |actual_array|
    matches &&= match_array(actual_array, expected_array)
  }
  matches
end

#select(expected) ⇒ Object



12
13
14
# File 'lib/look_like/nested-array-matcher.rb', line 12

def select(expected)
  expected.is_a?(Array) && expected.length > 0 && expected[0].is_a?(Array)
end