0.0
No commit activity in last 3 years
No release in over 3 years
RSpec deep_eq matcher
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 2.0.0
 Project Readme

RSpec Deep Eq Matches

This gem adds an RSpec deep_eq matcher that recursively compares contents of Hash and Array data.

Installation

Add gem to your Gemfile:

gem 'rspec_deep_eq'

And run

bundle install

Or install it manually:

gem install rspec_deep_eq

Getting started

In rails_helper file, configure deep_eq matcher for RSpec:

# rails_helper.rb

require 'deep_eq'

RSpec.configure do |config|
  config.include DeepEq
end

Usage

You can compare everything with deep_eq matcher, but it's created to compare complex structures like nested hashes and arrays.

describe 'Deep Equal' do
  it 'compares' do
    data = prepare_data

    expect(data).to deep_eq(
      id: 1,
      items: [
        id: 3,
        images: [
          {
            url: 'https://example.com/bass_guitar.png'
          },
          {
            url: 'https://example.com/naked_lady.png'
          }
        ]
      ],
      author: {
        name: 'John Doe'
      }
    )
  end
end

Motivation

Comparing complex data structures can be easily done using built-in RSpec matchers like eq, match_array or hash_including. But when something goes wrong, it displays hard-to-read error output. This matcher is created to make fixing such tests easier.

Read more here.

License

Published under MIT license.