diff --git a/ospec/README.md b/ospec/README.md index 1fccb1ae..b1ed5899 100644 --- a/ospec/README.md +++ b/ospec/README.md @@ -633,7 +633,7 @@ o.spec("message", function() { ### String result.context -In case of failure, a `>`-separated string showing the structure of the test specification. +A `>`-separated string showing the structure of the test specification. In the below example, `result.context` would be `testing > rocks`. ```javascript diff --git a/ospec/change-log.md b/ospec/change-log.md index b355dd20..df83a96b 100644 --- a/ospec/change-log.md +++ b/ospec/change-log.md @@ -3,6 +3,7 @@ ## Upcoming... _2018-xx-yy_ +- ospec: Test results now include `.message` and `.context` regardless of whether the test passed or failed. (#2227 @robertakarobin) - Add `spy.calls` array property to get the `this` and `arguments` values for any arbitrary call. - Added `.throws` and `.notThrows` assertions to ospec. (#2255 @robertakarobin) diff --git a/ospec/ospec.js b/ospec/ospec.js index 91483ead..e18cb4b6 100644 --- a/ospec/ospec.js +++ b/ospec/ospec.js @@ -287,16 +287,20 @@ else window.o = m() } function define(name, verb, compare) { Assert.prototype[name] = function assert(value) { - if (compare(this.value, value)) succeed(this) - else fail(this, serialize(this.value) + "\n " + verb + "\n" + serialize(value)) var self = this - return function(message) { - if (!self.pass) self.message = message + "\n\n" + self.message - } + var message = serialize(self.value) + "\n " + verb + "\n" + serialize(value) + if (compare(self.value, value)){ + succeed(self, message) + return function(message) { + if (!self.pass) self.message = message + "\n\n" + self.message + } + }else fail(self, message) } } - function succeed(assertion) { + function succeed(assertion, message) { results[assertion.i].pass = true + results[assertion.i].context = subjects.join(" > ") + results[assertion.i].message = message } function fail(assertion, message, error) { results[assertion.i].pass = false diff --git a/ospec/tests/test-ospec.js b/ospec/tests/test-ospec.js index 19c7af68..470a3b61 100644 --- a/ospec/tests/test-ospec.js +++ b/ospec/tests/test-ospec.js @@ -89,6 +89,8 @@ o.spec("reporting", function() { o(results.length).equals(2)("Two results") o("error" in results[0] && "pass" in results[0]).equals(true)("error and pass keys present in failing result") + o("message" in results[0] && "context" in results[0]).equals(true)("message and context keys present in failing result") + o("message" in results[1] && "context" in results[1]).equals(true)("message and context keys present in passing result") o(results[0].pass).equals(false)("Test meant to fail has failed") o(results[1].pass).equals(true)("Test meant to pass has passed")