No commit activity in last 3 years
No release in over 3 years
JSON assertions that help you find exactly what has changed with your JSON API without having to manually diff large objects
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
~> 2.1
~> 12.3
~> 3.5

Runtime

~> 1.0
 Project Readme


JSONSpectacular

Gem Build Status GitHub license

JSON assertions with noise-free reports on complex nested structures.

Installation

Add this line to your application's Gemfile:

group :test do
  gem 'json_spectacular', require: false
end

Add json_spectacular to your spec/rails_helper.rb

require 'json_spectacular'

# ...

RSpec.configure do |config|
  # ...

  %i[request controller].each do |spec_type|
    config.include JSONSpectacular::RSpec, type: spec_type
  end
end

And then execute:

bundle install

Usage

Asserting JSON responses

RSpec.describe 'making some valid request', type: :request do
  context 'some important context' do
    it 'should return some complicated JSON' do
      perform_request

      expect(json_response).to eql_json([
        {
            "a" => [
                1, 2, 3
           ],
           "c" => { "d" => "d'"}
        },
        {
            "b" => [
                1, 2, 3
           ],
           "c" => { "d" => "d'"}
        }
      ])
    end
  end
end

The json_response helper automatically parses the last response object as json, and the assertion eql_json reports failures in a format that is much clearer than anything provided by RSpec.

The full expected and actual values are still reported, but below is a separate report that only includes the paths to the failed nested values and their differences, removing the need to manually compare the two complete objects to find the difference.

Test suite

json_spectacular comes with close-to-complete test coverage. You can run the test suite as follows:

rspec

Contributing

  1. Fork it ( https://github.com/greena13/json_spectacular/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request