#compare two arrays, fail if they don't match
#report the unmatched elements in a readable format
def verify_array(expected_array, actual_array, message = '')
#array1 - array2 gives an array containing only the differences
#(elements in array1 not found in array2)
differences = (expected_array - actual_array)
#for each difference, find the index of the value that doesn't match,
#so you can show both expected and actual
differences.each do |difference|
difference_index = expected_array.index(difference)
failure = "\n#{"="*30}\nDifference at index #{difference_index.to_s}.\n\#line continues
Expected array value: #{difference.to_s}\nActual array value: #{actual_array[difference_index].to_s}"
message = message + "\n#{failure}"
end
verify(expected_array == actual_array, message)
end
This isn't specifically to do with Watir.