Better RSpec diffs with super_diff

Every now and then I need to build up some complex hash/JSON data in Ruby to feed over to a JS frontend. I tend to work slowly and iteratively as I push the nesting deeper, which helps me find mistakes before it gets too complicated… but sometimes that doesn’t work.

The problem is, that when you’ve got gnarly nested data, the RSpec result message is really not easy to read:

Diff:
@@ -1,4 +1,4 @@
-:domain_models => [{:domain_model_name=>"group_b", :domain_model_slug=>"organization-experienced-hires-domain_model", :second_domain_model_definitions=>[{:sections=>[{:questions=>[{:stats_tag=>"experience_overall", :type=>"RangeSelectQuestion"}, {:stats_tag=>"experience_average", :type=>"RangeSelectQuestion"}, {:stats_tag=>"recommendation_nps", :type=>"ScoreQuestion"}, {:stats_tag=>"big_choice_suggestions", :type=>"FreeTextQuestion"}, {:allow_multiple=>false, :stats_tag=>"ethnicity", :type=>"MultiChoiceQuestion"}, {:allow_multiple=>true, :stats_tag=>"big_choice_decision_influences", :type=>"MultiChoiceQuestion"}], :section_number=>11}, {:section_number=>112}], :second_domain_model_name=>"Application"}, {:sections=>[{:questions=>[], :section_number=>12}], :second_domain_model_name=>"Outcome"}]}, {:domain_model_name=>"group_a", :domain_model_slug=>"organization-group_a-domain_model", :second_domain_model_definitions=>[]}],
+:domain_models => [{:domain_model_name=>"group_b", :domain_model_slug=>"organization-experienced-hires-domain_model", :second_domain_model_definitions=>[{:sections=>[{:questions=>[{:stats_tag=>"experience_overall", :type=>"RangeSelectQuestion"}, {:stats_tag=>"experience_average", :type=>"RangeSelectQuestion"}, {:stats_tag=>"recommendation_nps", :type=>"ScoreQuestion"}, {:stats_tag=>"big_choice_suggestions", :type=>"FreeTextQuestion"}, {:allow_multiple=>false, :stats_tag=>"ethnicity", :type=>"MultiChoiceQuestion"}, {:allow_multiple=>true, :stats_tag=>"big_choice_decision_influences", :type=>"MultiChoiceQuestion"}], :section_number=>11}, {:questions=>[], :section_number=>112}], :second_domain_model_name=>"Application"}, {:sections=>[{:questions=>[], :section_number=>12}], :second_domain_model_name=>"Outcome"}]}, {:domain_model_name=>"group_a", :domain_model_slug=>"organization-group_a-domain_model", :second_domain_model_definitions=>[]}],

And look. I have a hard time spotting the difference between these…

Installing super_diff makes it a heck of a lot easier. In addition to the full diff (as above), it also gives you:

  {
    section_number: 112,
+   questions: []
  }

in a normalized hash structure. Which makes it wicked easy to find the issue.

super_diff is the kind of thing I’d install just when needed, and not track permanently into my dependencies.