From 9d531ea85c748623e94179f63e26bf4c7ed4b9d7 Mon Sep 17 00:00:00 2001 From: Stijn van Drunen Date: Thu, 3 Mar 2016 16:08:19 +0100 Subject: [PATCH] Added example to response object for use in hooks later (e.g. comparing). --- lib/add-tests.coffee | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/add-tests.coffee b/lib/add-tests.coffee index bfe56f4..0e737bf 100644 --- a/lib/add-tests.coffee +++ b/lib/add-tests.coffee @@ -85,11 +85,19 @@ addTests = (raml, tests, hooks, parent, callback, testFactory) -> # expect content-type of response body to be identical to request body if contentType && res.body[contentType]?.schema test.response.schema = parseSchema res.body[contentType].schema + try + test.response.example = JSON.parse res.body[contentType]?.example + catch + console.warn "cannot parse JSON example response body for #{test.name}" # otherwise filter in responses section for compatible content-types (vendor tree, i.e. application/vnd.api+json) else contentType = (type for type of res.body when type.match(/^application\/(.*\+)?json/i))?[0] if res.body[contentType]?.schema test.response.schema = parseSchema res.body[contentType].schema + try + test.response.example = JSON.parse res.body[contentType]?.example + catch + console.warn "cannot parse JSON example response body for #{test.name}" callback() , (err) -> @@ -101,4 +109,3 @@ addTests = (raml, tests, hooks, parent, callback, testFactory) -> module.exports = addTests -