Better diff output for Hash #60

merged 1 commit into from Dec 28, 2011


None yet

8 participants



I made a better diff output when comparing two hashes.

The diff was previously comparing the hashes' pretty prints. It was actually quite hard to read: the keys were not ordered and their were curly brackets surrounding the first and last line.

This patch outputs the Hash without surrounding brackets with lines sorted by keys.

Previous output:

@@ -1,8 +1,9 @@
-{"reference"=>"Account No. 324",
+ "reference"=>"Account No. 324",
  "created_by_account"=>"Quatchi Sasquatch",
- "created_by_user"=>"Quatchi Sasquatch",
+ "created_by_user"=>"1234567890",
  "message"=>"Your magazine subscription.",

Patched output:

  @@ -1,7 +1,8 @@
   "created_by_account" => "Quatchi Sasquatch",
  -"created_by_user" => "Quatchi Sasquatch",
  +"created_by_user" => "1234567890",
   "email" => "",
   "message" => "Your magazine subscription.",
  +"name" => nil,
   "reference" => "Account No. 324",
   "state" => "pending",
   "token" => "ABCD1234",

Any questions? Just ask! :)

I hope you'll find this patch usefull.




This is great, I think improvements to the array diff should be added as well. Something along these lines:




This is just what I was looking for.


👍 👍 👍

Bummer that this (or something like it) still isn't merged. The current diff output for hashes is worse than no diff at all.

@spicycode spicycode merged commit 2447ef6 into rspec:master Dec 28, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment