GithubHelp home page GithubHelp logo

mcountis / rspec-json_expectations Goto Github PK

View Code? Open in Web Editor NEW

This project forked from waterlink/rspec-json_expectations

0.0 0.0 0.0 63 KB

Set of matchers and helpers to allow you test your APIs responses like a pro.

Home Page: https://www.relishapp.com/waterlink/rspec-json-expectations/docs

License: MIT License

Ruby 28.37% Shell 0.31% Gherkin 71.32%

rspec-json_expectations's Introduction

RSpec::JsonExpectations

Build Status

Set of matchers and helpers for RSpec 3 to allow you test your JSON API responses like a pro.

Installation

Add this line to your application's Gemfile:

gem 'rspec-json_expectations'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rspec-json_expectations

Setup

Simply add this line at the top of your spec helper:

require "rspec/json_expectations"

Usage

Simple example:

require "spec_helper"

RSpec.describe "User API" do
  subject { api_get :user }

  it "has basic info about user" do
    expect(subject).to include_json(
      id: 25,
      email: "[email protected]",
      name: "John"
    )
  end

  it "has some additional info about user" do
    expect(subject).to include_json(
      premium: "gold",
      gamification_score: 79
    )
  end
end

And the output when I run it is:

FF

Failures:

  1) User API has basic info about user
     Failure/Error: expect(subject).to include_json(

                 json atom at path "id" is not equal to expected value:

                   expected: 25
                        got: 37

                 json atom at path "name" is not equal to expected value:

                   expected: "John"
                        got: "Smith J."

     # ./spec/user_api_spec.rb:18:in `block (2 levels) in <top (required)>'

  2) User API has some additional info about user
     Failure/Error: expect(subject).to include_json(

                 json atom at path "premium" is not equal to expected value:

                   expected: "gold"
                        got: "silver"

     # ./spec/user_api_spec.rb:26:in `block (2 levels) in <top (required)>'

Finished in 0.00102 seconds (files took 0.0853 seconds to load)
2 examples, 2 failures

Failed examples:

rspec ./spec/user_api_spec.rb:17 # User API has basic info about user
rspec ./spec/user_api_spec.rb:25 # User API has some additional info about user

For other features look into documentation: https://www.relishapp.com/waterlink/rspec-json-expectations/docs/json-expectations

Development

  • bundle install to install all dependencies.
  • bin/build to run the test suite

Contributing

  1. Fork it ( https://github.com/waterlink/rspec-json_expectations/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

rspec-json_expectations's People

Contributors

waterlink avatar jeroenj avatar esjee avatar ecbrodie avatar graemeboyd avatar graaff avatar janstevens avatar mothonmars avatar shamil614 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.