Better diff output for Hash #60

Merged
merged 1 commit into from Dec 28, 2011

Projects

None yet

8 participants

@pcreux

Hello,

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",
+{"name"=>nil,
+ "reference"=>"Account No. 324",
  "token"=>"ABCD1234",
  "type"=>"authorization",
  "created_by_account"=>"Quatchi Sasquatch",
- "created_by_user"=>"Quatchi Sasquatch",
+ "created_by_user"=>"1234567890",
  "message"=>"Your magazine subscription.",
  "email"=>"not-a-user@example.com",
  "state"=>"pending"}

Patched output:

  @@ -1,7 +1,8 @@
   "created_by_account" => "Quatchi Sasquatch",
  -"created_by_user" => "Quatchi Sasquatch",
  +"created_by_user" => "1234567890",
   "email" => "not-a-user@example.com",
   "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.

Cheers,

Philippe

@superplussed

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

http://stackoverflow.com/questions/5944301/how-do-i-format-the-diff-output-in-cucumber

@britto

👍

@mohawkjohn

This is just what I was looking for.

@timcharper

👍 👍 👍

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