• Stars
    star
    798
  • Rank 54,791 (Top 2 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 13 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A more helpful way to view differences between complex data structures in RSpec.

SuperDiff Gem Version Build Status Downloads IssueHunt

SuperDiff is a Ruby gem which is designed to display the differences between two objects of any type in a familiar and intelligent fashion.

๐Ÿ“ข See what's changed in recent versions.

Introduction

The primary motivation behind this gem is to vastly improve upon RSpec's built-in diffing capabilities. RSpec has many nice features, and one of them is that whenever you use a matcher such as eq, match, include, or have_attributes, you will get a diff of the two data structures you are trying to match against. This is great if all you want to do is compare multi-line strings. But if you want to compare other, more "real world" kinds of values such as API or database data, then you are out of luck. Since RSpec merely runs your expected and actual values through Ruby's PrettyPrinter library and then performs a diff of these strings, the output it produces leaves much to be desired.

For instance, let's say you wanted to compare these two hashes:

actual = {
  customer: {
    person: SuperDiff::Test::Person.new(name: "Marty McFly, Jr.", age: 17),
    shipping_address: {
      line_1: "456 Ponderosa Ct.",
      city: "Hill Valley",
      state: "CA",
      zip: "90382"
    }
  },
  items: [
    { name: "Fender Stratocaster", cost: 100_000, options: %w[red blue green] },
    { name: "Mattel Hoverboard" }
  ]
}

expected = {
  customer: {
    person: SuperDiff::Test::Person.new(name: "Marty McFly", age: 17),
    shipping_address: {
      line_1: "123 Main St.",
      city: "Hill Valley",
      state: "CA",
      zip: "90382"
    }
  },
  items: [
    { name: "Fender Stratocaster", cost: 100_000, options: %w[red blue green] },
    { name: "Chevy 4x4" }
  ]
}

If, somewhere in a test, you were to say:

expect(actual).to eq(expected)

You would get output that looks like this:

Before super_diff

What this library does is to provide a diff engine that knows how to figure out the differences between any two data structures and display them in a sensible way. So, using the example above, you'd get this instead:

After super_diff

Installation & Usage

๐Ÿ“˜ For more on how to install and use SuperDiff, read the user documentation.

Support

My goal for this library is to improve your development experience. If this is not the case, and you encounter a bug or have a suggestion, feel free to create an issue. I'll try to respond to it as soon as I can!

Contributing

Any code contributions to improve this library are welcome! Please see the contributing document for more on how to do that.

Sponsoring

If there's a change you want implemented, you can choose to sponsor that change! super_diff is set up on IssueHunt, so feel free to search for an existing issue (or make your own) and add a bounty. I'll get notified right away!

Compatibility

super_diff is tested to work with Ruby >= 3.x, RSpec 3.x, and Rails >= 6.x.

Inspiration/Thanks

In developing this gem I made use of or was heavily inspired by these libraries:

Thank you to the authors of these libraries!

Author/License

SuperDiff was created and is maintained by Elliot Winkler. It is released under the MIT license.

More Repositories

1

address_standardization

Quickly standardize a postal address using the Google Geocoding API or MelissaData [ABANDONED]
Ruby
49
star
2

fedex

Fork of Mighty Interactive's fedex plugin (no longer available), updated to support v7 of the Fedex API. NOTE: I am no longer maintaining this library. There is at least one fork that supports v8. If you are interested in taking this over please let me know so I can remove this. Thanks!
Ruby
18
star
3

time_tracker

A command-line tool that helps you stay on top of your tasks. [ABANDONED]
Ruby
10
star
4

moolah

A tiny money management app running on Padrino (a Sinatra-based framework) and Mongoid. [ABANDONED]
JavaScript
8
star
5

htmldoc-rails

Generate PDFs from your Rails views using HTMLDoc [ABANDONED]
Ruby
6
star
6

rpg

Clone of *The Legend of Zelda: Link to the Past* using HTML5 technologiesโ„ข [ABANDONED]
CoffeeScript
6
star
7

dotfiles

My personal dotfiles
Vim Script
5
star
8

sprite_editor

It's a pixel editor, in the browser. [ABANDONED]
CoffeeScript
4
star
9

pull-request-dashboard

View and triage your pull requests
TypeScript
3
star
10

musical-lattice

Interactive 5-limit just intonation lattice
JavaScript
3
star
11

vim-grakn

Vim support for Grakn (specifically Graql files)
Vim Script
3
star
12

sample_jenkins_published_gem

Shell
3
star
13

setup_script_generator

Easily generate setup scripts for your projects.
Shell
3
star
14

ar_attr_lazy

Gem for Rails that lets you specify attributes that will not be loaded when you do a find until you refer to those attributes. Great for speeding up your app if your table has a lot of text/blob columns. [ABANDONED]
Ruby
2
star
15

chromamatic

Color chooser that supports HSLuv
JavaScript
2
star
16

message_div_helpers

Rails plugin that provides a handy way of setting/displaying user messages, such as success, error, and notice
Ruby
2
star
17

hierarchical_page_titles

A gem that provides controller and view methods to make displaying of window/page titles DRYer.
Ruby
2
star
18

react-nuclearjs-boilerplate

A boilerplate for setting up a React + NuclearJS project.
JavaScript
2
star
19

musicology

A collection of Ruby classes for use with generating musically related things. [UNDER DEVELOPMENT โ€”ย ON HIATUS]
Ruby
1
star
20

hash_struct

Ruby
1
star
21

papyrus

A liquid style template engine loosely based on PageTemplate
Ruby
1
star
22

snowglobe

Create temporary Rails applications for use in testing
Ruby
1
star
23

vimfiles

My personal (Neo)Vim configuration
1
star
24

canvas-demos

Playing around with HTML5 Canvas
JavaScript
1
star
25

portal-2-sheet-music

Some of the music from the Portal 2 OST, written in LilyPond
1
star
26

soylent_planner

A project that uses some linear algebra to help me create my own Soylent recipes. [ABANDONED]
Ruby
1
star
27

hardwarepedia

Comparison shopping / knowledge base for DIY computer builders [ABANDONED, use pcpartpicker.com]
Ruby
1
star
28

magic-grapher

Draw and generate hierarchical diagrams with ease. [UNDER DEVELOPMENT]
Elm
1
star
29

fakenstocks

Fakenstocks allows you to play the stock market virtually and keep track of your performance. [ABANDONED]
JavaScript
1
star
30

nextjs-tailwind-starter-kit

Shell
1
star
31

dotfiles-manager

Manage your dotfiles with this one simple tool
Ruby
1
star
32

mysql_column_order

Rails plugin that extends migrations so you can specify an order when you're adding a new column, as well as other options that ALTER TABLE accepts [ABANDONED]
Ruby
1
star
33

ar_after_timestamps

A little gem that provides an AR callback right after timestamps are set and before the record is saved
Ruby
1
star
34

smart_assets

Rails plugin that dynamically includes stylesheet and javascript files based on the current controller, parent controller, action, and layout
Ruby
1
star