Ospec: expose messages for passing tests, in addition to failing tests (#2227)

* ospec: all results, failing and passing, include .message and .context

Previously only failing tests had .message and .context.

* Updated docs

* Function was ugly

* Ospec verbose passing tests: put changelog update in right place
This commit is contained in:
Robin (Robert) Thomas 2018-11-21 14:47:10 -06:00 committed by Isiah Meadows
parent 0fd1bc9cae
commit b5219920ab
4 changed files with 14 additions and 7 deletions

View file

@ -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

View file

@ -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 new lines here. Version number will be decided later -->
- 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)

View file

@ -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

View file

@ -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")