Skip to content

Commit

Permalink
Revert "For consideration: child => inherit"
Browse files Browse the repository at this point in the history
This reverts commit c0a8c9b.

Conflicts:
	test/api/exportAssertion.spec.js
  • Loading branch information
papandreou committed Apr 4, 2017
1 parent 4431792 commit 5b61027
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 126 deletions.
62 changes: 31 additions & 31 deletions lib/Unexpected.js
Expand Up @@ -488,13 +488,13 @@ Unexpected.prototype.fail = function (arg) {
if (key === 'diff') {
if (typeof value === 'function' && this.parent) {
error.createDiff = function (output, diff, inspect, equal) {
var inheritedOutput = expect.createOutput(output.format);
inheritedOutput.inline = output.inline;
inheritedOutput.output = output.output;
return value(inheritedOutput, function diff(actual, expected) {
return expect.diff(actual, expected, inheritedOutput.clone());
var childOutput = expect.createOutput(output.format);
childOutput.inline = output.inline;
childOutput.output = output.output;
return value(childOutput, function diff(actual, expected) {
return expect.diff(actual, expected, childOutput.clone());
}, function inspect(v, depth) {
return inheritedOutput.clone().appendInspected(v, (depth || defaultDepth) - 1);
return childOutput.clone().appendInspected(v, (depth || defaultDepth) - 1);
}, function (actual, expected) {
return expect.equal(actual, expected);
});
Expand Down Expand Up @@ -563,9 +563,9 @@ function calculateAssertionSpecificity(assertion) {

// expect.addAssertion(pattern, handler)
// expect.addAssertion([pattern, ...], handler)
Unexpected.prototype.addAssertion = function (patternOrPatterns, handler, inheritedUnexpected) {
Unexpected.prototype.addAssertion = function (patternOrPatterns, handler, childUnexpected) {
var maxArguments;
if (typeof inheritedUnexpected === 'object') {
if (typeof childUnexpected === 'object') {
maxArguments = 3;
} else {
maxArguments = 2;
Expand Down Expand Up @@ -616,7 +616,7 @@ Unexpected.prototype.addAssertion = function (patternOrPatterns, handler, inheri
args: assertionDeclaration.args,
testDescriptionString: expandedAssertion.text,
declaration: pattern,
unexpected: inheritedUnexpected
unexpected: childUnexpected
});
});
});
Expand Down Expand Up @@ -645,7 +645,7 @@ Unexpected.prototype.addAssertion = function (patternOrPatterns, handler, inheri
return this.expect; // for chaining
};

Unexpected.prototype.addType = function (type, inheritedUnexpected) {
Unexpected.prototype.addType = function (type, childUnexpected) {
var that = this;
var baseType;
if (typeof type.name !== 'string' || !/^[a-z_](?:|[a-z0-9_.-]*[_a-z0-9])$/i.test(type.name)) {
Expand Down Expand Up @@ -706,22 +706,22 @@ Unexpected.prototype.addType = function (type, inheritedUnexpected) {
extendedType.inspect = function (obj, depth, output, inspect) {
if (arguments.length < 2 || (!output || !output.isMagicPen)) {
return 'type: ' + type.name;
} else if (inheritedUnexpected) {
var inheritedOutput = inheritedUnexpected.createOutput(output.format);
return originalInspect.call(this, obj, depth, inheritedOutput, inspect) || inheritedOutput;
} else if (childUnexpected) {
var childOutput = childUnexpected.createOutput(output.format);
return originalInspect.call(this, obj, depth, childOutput, inspect) || childOutput;
} else {
return originalInspect.call(this, obj, depth, output, inspect) || output;
}
};

if (inheritedUnexpected) {
extendedType.inheritedUnexpected = inheritedUnexpected;
if (childUnexpected) {
extendedType.childUnexpected = childUnexpected;
var originalDiff = extendedType.diff;
extendedType.diff = function (actual, expected, output, inspect, diff, equal) {
var inheritedOutput = inheritedUnexpected.createOutput(output.format);
var childOutput = childUnexpected.createOutput(output.format);
// Make sure that already buffered up output is preserved:
inheritedOutput.output = output.output;
return originalDiff.call(this, actual, expected, inheritedOutput, inspect, diff, equal) || output;
childOutput.output = output.output;
return originalDiff.call(this, actual, expected, childOutput, inspect, diff, equal) || output;
};
}

Expand Down Expand Up @@ -869,7 +869,7 @@ function installExpectMethods(unexpected, expectFunction) {
expect.addType = unexpected.addType.bind(unexpected);
expect.getType = unexpected.getType;
expect.clone = unexpected.clone.bind(unexpected);
expect.inherit = unexpected.inherit.bind(unexpected);
expect.child = unexpected.child.bind(unexpected);
expect.toString = unexpected.toString.bind(unexpected);
expect.assertions = unexpected.assertions;
expect.use = expect.installPlugin = unexpected.use.bind(unexpected);
Expand Down Expand Up @@ -1339,33 +1339,33 @@ Unexpected.prototype.clone = function () {
return makeExpectFunction(unexpected);
};

Unexpected.prototype.inherit = function () {
var inheritedUnexpected = new Unexpected({
Unexpected.prototype.child = function () {
var childUnexpected = new Unexpected({
assertions: {},
types: [],
typeByName: {},
output: this.output.clone(),
format: this.outputFormat(),
installedPlugins: []
});
var parent = inheritedUnexpected.parent = this;
var inheritedExpect = makeExpectFunction(inheritedUnexpected);
inheritedExpect.exportAssertion = function (testDescription, handler) {
parent.addAssertion(testDescription, handler, inheritedUnexpected);
var parent = childUnexpected.parent = this;
var childExpect = makeExpectFunction(childUnexpected);
childExpect.exportAssertion = function (testDescription, handler) {
parent.addAssertion(testDescription, handler, childUnexpected);
return this;
};
inheritedExpect.exportType = function (type) {
parent.addType(type, inheritedUnexpected);
childExpect.exportType = function (type) {
parent.addType(type, childUnexpected);
return this;
};
inheritedExpect.exportStyle = function (name, handler) {
childExpect.exportStyle = function (name, handler) {
parent.addStyle(name, function () { // ...
var inheritedOutput = inheritedExpect.createOutput(this.format);
this.append(handler.apply(inheritedOutput, arguments) || inheritedOutput);
var childOutput = childExpect.createOutput(this.format);
this.append(handler.apply(childOutput, arguments) || childOutput);
});
return this;
};
return inheritedExpect;
return childExpect;
};

Unexpected.prototype.outputFormat = function (format) {
Expand Down

0 comments on commit 5b61027

Please sign in to comment.