This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In reply to http://www.ultrasaurus.com/sarahblog/2009/08/ruby-unit-test-frameworks/ | |
# Put this in test_helper.rb to compare two arbitrarily nested structures. | |
# Usage: compare_objects(o1, o2). Raises an exception if it finds any differences. | |
# recursivly compare two objects. raise if a difference was found, return if not. | |
def compare_objects(wanted, actual, path=[]) | |
if wanted.kind_of?(Hash) | |
raise "Objects differ at #{path.join(".")}: extra keys in wanted: #{(wanted.keys - actual.keys).inspect}" if (wanted.keys - actual.keys).length > 0 | |
raise "Objects differ at #{path.join(".")}: extra keys in actual: #{(actual.keys - wanted.keys).inspect}" if (actual.keys - wanted.keys).length > 0 | |
wanted.keys.sort.each do |key| |
NewerOlder