Skip to content

Commit

Permalink
refactor(empower): always re-instantiate AssertionError on rethrow
Browse files Browse the repository at this point in the history
  • Loading branch information
twada committed Oct 1, 2014
1 parent ddebf3c commit 997da24
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
15 changes: 5 additions & 10 deletions build/empower.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ module.exports = decorate;
var escallmatch = _dereq_('escallmatch'),
extend = _dereq_('xtend/mutable'),
capturable = _dereq_('./capturable'),
decorate = _dereq_('./decorate'),
isPhantom = typeof window !== 'undefined' && typeof window.callPhantom === 'function';
decorate = _dereq_('./decorate');


function Decorator (receiver, formatter, config) {
Expand Down Expand Up @@ -247,24 +246,20 @@ Decorator.prototype.errorToRethrow = function (e, originalMessage, context) {
actual: e.actual,
expected: e.expected,
operator: e.operator,
message: e.message
message: e.message,
stackStartFunction: Decorator.prototype.concreteAssert
};

if (this.config.modifyMessageOnRethrow) {
attrs.message = this.buildPowerAssertText(originalMessage, context);
attrs.stackStartFunction = Decorator.prototype.concreteAssert;
}

if (isPhantom || this.config.modifyMessageOnRethrow) {
f = new this.receiver.AssertionError(attrs);
} else {
f = e;
f.message = attrs.message;
}
f = new this.receiver.AssertionError(attrs);

if (this.config.saveContextOnRethrow) {
f.powerAssertContext = context;
}

return f;
};

Expand Down
15 changes: 5 additions & 10 deletions lib/decorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
var escallmatch = require('escallmatch'),
extend = require('xtend/mutable'),
capturable = require('./capturable'),
decorate = require('./decorate'),
isPhantom = typeof window !== 'undefined' && typeof window.callPhantom === 'function';
decorate = require('./decorate');


function Decorator (receiver, formatter, config) {
Expand Down Expand Up @@ -78,24 +77,20 @@ Decorator.prototype.errorToRethrow = function (e, originalMessage, context) {
actual: e.actual,
expected: e.expected,
operator: e.operator,
message: e.message
message: e.message,
stackStartFunction: Decorator.prototype.concreteAssert
};

if (this.config.modifyMessageOnRethrow) {
attrs.message = this.buildPowerAssertText(originalMessage, context);
attrs.stackStartFunction = Decorator.prototype.concreteAssert;
}

if (isPhantom || this.config.modifyMessageOnRethrow) {
f = new this.receiver.AssertionError(attrs);
} else {
f = e;
f.message = attrs.message;
}
f = new this.receiver.AssertionError(attrs);

if (this.config.saveContextOnRethrow) {
f.powerAssertContext = context;
}

return f;
};

Expand Down

0 comments on commit 997da24

Please sign in to comment.