Skip to content

Instantly share code, notes, and snippets.

View fabriciofreitag's full-sized avatar
🇧🇷

fabriciofreitag

🇧🇷
View GitHub Profile
@fabriciofreitag
fabriciofreitag / detailed_hash_diff.rb
Last active December 21, 2021 03:13
Custom RSPec matcher for detailed hash compasion and diff
RSpec::Matchers.define :be_a_hash_like do |expected_hash|
match do |actual_hash|
matching_results = actual_hash == expected_hash
unless matching_results
system(
"git --no-pager diff $(echo '#{JSON.pretty_generate(expected_hash)}' | git hash-object -w --stdin) " +
"$(echo '#{JSON.pretty_generate(actual_hash)}' | git hash-object -w --stdin) --word-diff",
out: $stdout,
err: :out
)