class Minitest::ExtendedAssertions::DeepComparator
Public Class Methods
compare(expected, actual, path=nil)
click to toggle source
# File lib/minitest/extended_assertions/deep_comparator.rb, line 31 def compare(expected, actual, path=nil) if expected.class != actual.class [Difference.new(path, expected, actual)] else if expected.is_a? Hash compare_hash expected, actual, path elsif expected.is_a? Array compare_array expected, actual, path elsif expected != actual [Difference.new(path, expected, actual)] else [] end end end
Private Class Methods
compare_array(expected, actual, path)
click to toggle source
# File lib/minitest/extended_assertions/deep_comparator.rb, line 59 def compare_array(expected, actual, path) if expected.count != actual.count [Difference.new("#{path}.count", expected.count, actual.count)] else expected.flat_map.with_index do |v, i| compare v, actual[i], "#{path}[#{i}]" end end end
compare_hash(expected, actual, path)
click to toggle source
# File lib/minitest/extended_assertions/deep_comparator.rb, line 49 def compare_hash(expected, actual, path) if expected.keys.sort != actual.keys.sort [Difference.new("#{path}.keys", expected.keys.sort, actual.keys.sort)] else expected.flat_map do |k, v| compare v, actual[k], "#{path}[#{k.inspect}]" end end end