Skip to content

Commit

Permalink
Merge pull request #207 from unexpectedjs/feature/fancy-labels-for-ex…
Browse files Browse the repository at this point in the history
…pect-it

Omit subject for expect.it as well
  • Loading branch information
papandreou committed Sep 7, 2015
2 parents 3d31f03 + 2f288ce commit 664f847
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 33 deletions.
2 changes: 1 addition & 1 deletion documentation/api/promise-any.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ aggregate error
[
0,
'1', // expected '1' to be a number after a short delay
'1', // should be a number after a short delay
2
]
2: expected { a: '0', b: 1 }
Expand Down
6 changes: 3 additions & 3 deletions documentation/assertions/any/to-satisfy.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ expected { foo: 9, bar: 'bar', baz: 'bogus', qux: 42, quux: 'wat' } to satisfy
}
{
foo: 9, // ✓ expected 9 to be a number and
// ⨯ expected 9 to be greater than 10
foo: 9, // ✓ should be a number and
// ⨯ should be greater than 10
bar: 'bar',
baz: 'bogus', // expected 'bogus' not to match /^bog/
baz: 'bogus', // should not match /^bog/
//
// bogus
// ^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ expect.it('to be a number')
.and('to be positive')
[
0, // ✓ expected 0 to be a number and
// ⨯ expected 0 to be positive
0, // ✓ should be a number and
// ⨯ should be positive
1,
2,
3,
Expand Down
8 changes: 4 additions & 4 deletions documentation/assertions/object/to-have-values-satisfying.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ expected object to have values satisfying
bar: [...],
baz: [
7,
8, // ✓ expected 8 to be a number and
// ⨯ expected 8 to be below 8
9 // ✓ expected 9 to be a number and
// ⨯ expected 9 to be below 8
8, // ✓ should be a number and
// ⨯ should be below 8
9 // ✓ should be a number and
// ⨯ should be below 8
]
}
```
2 changes: 1 addition & 1 deletion lib/Assertion.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Assertion(expect, subject, testDescription, flags, alternations, args)
Assertion.prototype.standardErrorMessage = function (output, options) {
options = typeof options === 'object' ? options : {};

if ('omitSubject' in options) {
if ('omitSubject' in output) {
options.subject = this.subject;
}

Expand Down
18 changes: 13 additions & 5 deletions lib/Unexpected.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,19 @@ function writeGroupEvaluationsToOutput(expect, output, groupEvaluations) {

var expectation = evaluation.expectation;
output.block(function (output) {
output[style]('expected ');
output.appendInspected(expectation[0]).sp();
output[style](expectation[1]);
expectation.slice(2).forEach(function (v) {
output.sp().appendInspected(v);
var subject = expectation[0];
var subjectOutput = function (output) {
output.appendInspected(subject);
};
var args = expectation.slice(2);
var argsOutput = args.map(function (arg) {
return function (output) {
output.appendInspected(arg);
};
});
var testDescription = expectation[1];
createStandardErrorMessage(output, expect, subjectOutput, testDescription, argsOutput, {
subject: subject
});
});
}
Expand Down
3 changes: 2 additions & 1 deletion lib/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,7 @@ module.exports = function (expect) {

var isInlineDiff = true;

output.omitSubject = subject[key];
if (!(key in value)) {
if (commonType.is('array-like') || flags.exhaustively) {
annotation.error('should be removed');
Expand All @@ -914,7 +915,7 @@ module.exports = function (expect) {
valueOutput = keyDiff.diff;
} else if (typeof value[key] === 'function') {
isInlineDiff = false;
annotation.appendErrorMessage(conflicting, { omitSubject: subject[key] });
annotation.appendErrorMessage(conflicting);
} else if (!keyDiff || (keyDiff && !keyDiff.inline)) {
annotation.error((conflicting && conflicting.getLabel()) || 'should satisfy').sp()
.block(inspect(value[key]));
Expand Down
2 changes: 1 addition & 1 deletion lib/createStandardErrorMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = function createStandardErrorMessage(output, expect, subject, te
var width = preamble.length + subjectSize.width + argsSize.width + testDescription.length;
var height = Math.max(subjectSize.height, argsSize.height);

if ('omitSubject' in options && options.omitSubject === options.subject) {
if ('omitSubject' in output && output.omitSubject === options.subject) {
var matchTestDescription = /^(not )?to (.*)/.exec(testDescription);
if (matchTestDescription) {
output.error('should ');
Expand Down
20 changes: 10 additions & 10 deletions test/documentation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ describe("documentation tests", function () {
"\n" +
" [\n" +
" 0,\n" +
" '1', // expected '1' to be a number after a short delay\n" +
" '1', // should be a number after a short delay\n" +
" 2\n" +
" ]\n" +
" 2: expected { a: '0', b: 1 }\n" +
Expand Down Expand Up @@ -2106,10 +2106,10 @@ describe("documentation tests", function () {
"}\n" +
"\n" +
"{\n" +
" foo: 9, // ✓ expected 9 to be a number and\n" +
" // ⨯ expected 9 to be greater than 10\n" +
" foo: 9, // ✓ should be a number and\n" +
" // ⨯ should be greater than 10\n" +
" bar: 'bar',\n" +
" baz: 'bogus', // expected 'bogus' not to match /^bog/\n" +
" baz: 'bogus', // should not match /^bog/\n" +
" //\n" +
" // bogus\n" +
" // ^^^\n" +
Expand Down Expand Up @@ -2305,8 +2305,8 @@ describe("documentation tests", function () {
" .and('to be positive')\n" +
"\n" +
"[\n" +
" 0, // ✓ expected 0 to be a number and\n" +
" // ⨯ expected 0 to be positive\n" +
" 0, // ✓ should be a number and\n" +
" // ⨯ should be positive\n" +
" 1,\n" +
" 2,\n" +
" 3,\n" +
Expand Down Expand Up @@ -3627,10 +3627,10 @@ describe("documentation tests", function () {
" bar: [...],\n" +
" baz: [\n" +
" 7,\n" +
" 8, // ✓ expected 8 to be a number and\n" +
" // ⨯ expected 8 to be below 8\n" +
" 9 // ✓ expected 9 to be a number and\n" +
" // ⨯ expected 9 to be below 8\n" +
" 8, // ✓ should be a number and\n" +
" // ⨯ should be below 8\n" +
" 9 // ✓ should be a number and\n" +
" // ⨯ should be below 8\n" +
" ]\n" +
"}"
);
Expand Down
10 changes: 5 additions & 5 deletions test/unexpected.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3241,7 +3241,7 @@ describe('unexpected', function () {
"expected { foo: 'foo' } to satisfy { foo: expect.it('not to match', /oo/) }\n" +
"\n" +
"{\n" +
" foo: 'foo' // expected 'foo' not to match /oo/\n" +
" foo: 'foo' // should not match /oo/\n" +
" //\n" +
" // foo\n" +
" // ^^\n" +
Expand Down Expand Up @@ -3526,8 +3526,8 @@ describe('unexpected', function () {
"}\n" +
"\n" +
"{\n" +
" foo: 123 // ✓ expected 123 to be a number and\n" +
" // ⨯ expected 123 to be greater than 200\n" +
" foo: 123 // ✓ should be a number and\n" +
" // ⨯ should be greater than 200\n" +
"}");
});

Expand Down Expand Up @@ -3869,7 +3869,7 @@ describe('unexpected', function () {
"\n" +
"{\n" +
" foo: MysteryBox({\n" +
" baz: 123, // expected 123 not to be a number\n" +
" baz: 123, // should not be a number\n" +
" quux: 987\n" +
" })\n" +
"}");
Expand Down Expand Up @@ -3967,7 +3967,7 @@ describe('unexpected', function () {
"expected { foo: 123 } to satisfy { foo: expect.it('to be a string') }\n" +
"\n" +
"{\n" +
" foo: 123 // expected 123 to be a string\n" +
" foo: 123 // should be a string\n" +
"}");

expect(function () {
Expand Down

0 comments on commit 664f847

Please sign in to comment.