Module: RSpecApi::Matchers::Json

Included in:
RSpecApi::Matchers
Defined in:
lib/rspec-api/matchers/json/matcher.rb,
lib/rspec-api/matchers/json/be_valid_json.rb

Defined Under Namespace

Classes: Matcher

Instance Method Summary collapse

Instance Method Details

#be_valid_jsonObject

Note:

The JSONP option is debatable, since an API that returns a JSONP should probably set the content-type to application/javascript.

Passes if the object has valid JSON or JSONP in the body

Examples:

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

See Also:



25
26
27
# File 'lib/rspec-api/matchers/json/be_valid_json.rb', line 25

def be_valid_json
  RSpecApi::Matchers::Json::Matcher.new
end