GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - splitwise/super_diff: A more helpful way to view differences between complex data structures in RSpec.

BranchesTags
Open more actions menu

Latest commit

 

History

379 Commits
379 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
.husky
.husky
 
 
.yarn/releases
.yarn/releases
 
 
bin
bin
 
 
config
config
 
 
docs-support
docs-support
 
 
docs
docs
 
 
gemfiles
gemfiles
 
 
lib
lib
 
 
scripts
scripts
 
 
spec
spec
 
 
support
support
 
 
.editorconfig
.editorconfig
 
 
.git-blame-ignore-revs
.git-blame-ignore-revs
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.nvmrc
.nvmrc
 
 
.python-version
.python-version
 
 
.rubocop.yml
.rubocop.yml
 
 
.rubocop_todo.yml
.rubocop_todo.yml
 
 
.ruby-version
.ruby-version
 
 
.yarnrc.yml
.yarnrc.yml
 
 
Appraisals
Appraisals
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
Gemfile
Gemfile
 
 
Gemfile.lock
Gemfile.lock
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
Rakefile
Rakefile
 
 
SECURITY.md
SECURITY.md
 
 
mkdocs.yml
mkdocs.yml
 
 
package.json
package.json
 
 
pyproject.toml
pyproject.toml
 
 
super_diff.gemspec
super_diff.gemspec
 
 
yarn.lock
yarn.lock
 
 

Repository files navigation

SuperDiff Gem Version Build Status Downloads

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.

Optional Extensions

If you need diffs for binary strings (Encoding::ASCII_8BIT), require the binary string integration:

require "super_diff/binary_string"

This enables hex-dump diffs and keeps binary data out of the expectation text.

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.

Compatibility

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

Inspiration/Thanks

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

  • Diff::LCS, the library I started with in the original version of this gem (made in 2011!)
  • The pretty-printing algorithms and API within PrettyPrinter and AwesomePrint, from which I borrowed ideas to develop the inspectors.

Thank you to the authors of these libraries!

Author/License

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

About

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

splitwise.github.io/super_diff/

Topics

rspecrubytesting

Resources

Readme
MIT license

Code of conduct

Code of conduct

Security policy

Security policy
Activity
Custom properties

Stars

1.0k stars

Watchers

10 watching

Forks

66 forks
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.