sunesimonsen/unexpected — pull request #28 by sunesimonsen (2014-02-01 14:59:16+00:00)
Title: Handle nested expects inside of custom assertion in a more controlled manner

Changes the default handling of nested expects inside assertions to use
the standard error message of the assertion instead of the error
message of the nested expect.

Two new boolean flags has been added to the assertion in order to
control how error messages of nested expects are handled.

* bubbleExpectErrors: use the error message of the nested expect
* nestExpectErrors: show the standard error for the assertion followed
by the error message of the nested expect.

Example of the default behaviour:

```js
expect.addAssertion('to be a number with value', function (value) {
expect(this.obj, 'to be a number');
expect(this.obj, 'to be', value);
});
expect('42', 'to be a number with value', 42);

// throw: expected '42' to be a number with value 42
```

Example of bubbleExpectErrors:

```js
expect.addAssertion('to be a number with value', function (value) {
this.bubbleExpectErrors = true;
expect(this.obj, 'to be a number');
expect(this.obj, 'to be', value);
});
expect('42', 'to be a number with value', 42);

// throw: expected '42' to be a number
```

Example of nestExpectErrors:

```js
expect.addAssertion('to be a number with value', function (value) {
this.nestExpectErrors = true;
expect(this.obj, 'to be a number');
expect(this.obj, 'to be', value);
});
expect('42', 'to be a number with value', 42);

// throw: expected '42' to be a number with value 42
// expected '42' to be a number
```

This works recursively of cause.

------------------------------------------------------------------

After doing this change I need to fix the output of some of the
assertions and change the test to expect the improved error messages.