Socket
Book a DemoInstallSign in
Socket

shoulda_render_json

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shoulda_render_json

bundlerRubygems
Version
0.0.3
Version published
Maintainers
1
Created
Source

Shoulda RenderJson Code Climate

Shoulda macros for making very basic assertions about JSON responses

Installation

Add this line to your application's Gemfile:

gem 'shoulda_render_json', group: :test

And then execute:

$ bundle

Or install it yourself as:

$ gem install shoulda_render_json

Usage

I'm going to presume you're already familiar with using Shoulda macros. The most basic assertion for render_json will be that your response's content-type is 'application/json' (Rails' default JSON content-type) and that there is a root-level node named "foo" in the JSON.

should render_json('foo')

Voilà! That's probably not too useful on its own though. Let's add some child node checks!

should render_json('foo', required: 'bar', forbidden: 'baz')

Predictably this adds two additional assertions to that base assertion. First, that the node for "foo" is required to have a child node named "bar". Second, that the node for "foo" is prohibited from having a child node named "baz". Both of these values can be arrays as well as strings as seen below.

should render_json('foo', required: %w{bar baz})

Sometimes, you may need to make assertions on Arrays inside JSON responses and not just Hash/Objects. I've got you covered there too.

should render_json('foo', type: Array)

If you need to make assertions on the members of that Array, you can use the same required and forbidden options but be aware these assertions will be expected to be true for every member of the Array. If you've got members that violate this, you'll probably be better off writing custom assertions anyhow.

That's it!

TODO

  • Test coverage. I've extracted this from one of my own test suites so there's no tests.

Contributing

FAQs

Package last updated on 06 Jun 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.