In my automated testing, I often want to test a pair of hashes for equality. If the pair is equal, well enough.
But if they're not equal, the simple way to record that is to log the failure, along with the two hashes. If the hashes are very small: I can visually compare them to determine the differences.
But for larger hashes, I can't easily determine the differences visually. That's where my class HashHelpler
comes in.
It has method HashHelper.compare(expected, actual)
that accepts the expected and actual hashes, and returns a hash having four keys and their corresponding values:
-
:ok
: value is a hash containing the key/value pairs that are in bothexpected
andactual
. -
:missing
: value is a hash containing the key/value pairs that are inexpected
, but not inactual
. -
:unexpected
: value is a hash containing the key/value pairs that are inactual
, but not inexpected
. -
:changed
: value is a hash detailing the keys that are in bothexpected
andactual
, but whose values differ.
So: in my method Log#verdict_assert_equal?
, a failed hash comparison gets and logs the detailed differences, making it easy to see what's what.
Links:
- Class HashHelper.
- Class HashHelperTest. (We're all testers here, right?).
- Module VerdictAssertion. See method
_verdict_equal?
Top comments (0)