Code Monkey home page Code Monkey logo

rspec-webservice-outputter's Introduction

rspec-webservice-outputter

Build Status

Developing a JSON API in Rails? The rspec-webservice-outputter gem will print the JSON request/response data when running your rspec request specs.

There are some other tools for inspecting HTTP request/response data such as the Chrome DevTools or the Postman Chrome extension. This gem takes a different approach by providing a method to inspect the HTTP request/response from the command-line when running/debugging tests.

Installation

In your Rails Gemfile, add:

group :test do
  gem 'rspec-webservice-outputter'
end

Usage

When running your request spec(s), set an environmental variable call WEBSERVICE:

WEBSERVICE=1 rspec path_to_your_spec.rb

The rspec example's output will look like:

REQUEST:
POST /v1/some_url
{
  "some_field": 5,
  "another_field": "2016-06-08"
}

RESPONSE (201):
{
  "id": 55,
  "some_field": 5,
  "another_field": "2016-06-08"
  "created_at": "2016-06-09T01:35:41.709Z",
  "updated_at": "2016-06-09T01:35:41.709Z"
}

If your response body is empty (e.g. 204 No Content), you'll see:

RESPONSE (204):
[Empty response body]

If your response body's JSON data can't be parsed, you'll see:

RESPONSE (200):
[Non-JSON response body]

Future Possibilities

  • Explore ways of implementing as a rspec custom formatter instead of an after hook
  • Or, toggle output via switch instead of env variable
  • Support XML webservices

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.