
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Shoulda macros for making very basic assertions about JSON responses
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
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!
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that shoulda_render_json demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.