minitest-hashdiff
When a Minitest assertion fails on two hashes, the default output is two nearly identical walls of inspect text, and the one value that changed is somewhere in there. This gem replaces that with a report of exactly what changed.
Before:
Expected: {"uid"=>"user@example.test", "active"=>true, "role"=>"admin", "last_login"=>nil}
Actual: {"uid"=>"user@example.test", "active"=>true, "role"=>"editor", "last_login"=>"2026-07-10"}
After:
Hash diff (expected => actual):
changed "last_login": nil => "2026-07-10" (nil -> String)
changed "role": "admin" => "editor"
Type changes are flagged explicitly because they are the differences most likely to cause a downstream bug and the easiest to miss: nil to String, Integer to Float, and symbol keys versus string keys (which are different keys in Ruby, even though they look almost the same).
Install
# Gemfile
group :test do
gem "minitest-hashdiff"
end
That's it. Minitest discovers the plugin automatically, so there is nothing to require and nothing to configure. Only assert_equal failures where both sides are hashes are affected; every other assertion behaves exactly as before.
What the report covers
- Changed values, with before and after
- Added and removed keys
- Explicit type changes
- Nested hashes and arrays, with the path to each difference
- Keys sorted, so ordering noise never masquerades as a real change
Prefer a visual diff?
This gem's output is built for terminals. For a side-by-side visual comparison of two large hashes, paste your failing test output into rubyhash.dev, which does the same parsing and type detection in your browser, with nothing uploaded.
License
MIT.