module RSpecApi::Matchers::Json
Public Instance Methods
be_valid_json()
click to toggle source
Passes if the object has valid JSON or JSONP in the body
@example Passes if the body is valid JSON
require 'rspec-api-matchers' body = '[{"id": 1}]' obj = OpenStruct.new body: body describe 'be_valid_json' do include RSpecApi::Matchers::Json it { expect(obj).to be_valid_json } end # => (rspec) 1 example, 0 failures
@note The JSONP option is debatable, since an API that returns a JSONP
should probably set the content-type to application/javascript.
@see git.io/Rq3lVg be_valid_json_spec.rb for more examples
# File lib/rspec-api/matchers/json/be_valid_json.rb, line 25 def be_valid_json RSpecApi::Matchers::Json::Matcher.new end