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

Passes if response body is a valid JSON or callback-wrapped JSON

For more examples check be_valid_json_spec.rb.

Examples:


# Passes if the body is valid JSON
body = '[{"id": 1}]'
expect(OpenStruct.new body: body).to be_valid_json


15
16
17
# File 'lib/rspec-api/matchers/json/be_valid_json.rb', line 15

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