From 1c6f9a0fddd8c2d8dde059ebec16cc12bbd450e5 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Sun, 12 Feb 2012 14:45:08 -0800 Subject: [PATCH] Make Assertion.prototype properties configurable This allows plugins to install object-specific behavior for built-in assertions. --- lib/assertion.js | 51 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/lib/assertion.js b/lib/assertion.js index 575b885f8..79ffd4479 100644 --- a/lib/assertion.js +++ b/lib/assertion.js @@ -98,7 +98,8 @@ Assertion.prototype.assert = function (expr, msg, negateMsg) { Object.defineProperty(Assertion.prototype, 'inspect', { get: function () { return inspect(this.obj); - } + }, + configurable: true }); /** @@ -113,7 +114,8 @@ Object.defineProperty(Assertion.prototype, 'inspect', Object.defineProperty(Assertion.prototype, 'to', { get: function () { return this; - } + }, + configurable: true }); /** @@ -128,7 +130,8 @@ Object.defineProperty(Assertion.prototype, 'to', Object.defineProperty(Assertion.prototype, 'be', { get: function () { return this; - } + }, + configurable: true }); /** @@ -145,7 +148,8 @@ Object.defineProperty(Assertion.prototype, 'been', { get: function () { this.tense = 'past'; return this; - } + }, + configurable: true }); /** @@ -160,7 +164,8 @@ Object.defineProperty(Assertion.prototype, 'been', Object.defineProperty(Assertion.prototype, 'an', { get: function () { return this; - } + }, + configurable: true }); /** * # is @@ -174,7 +179,8 @@ Object.defineProperty(Assertion.prototype, 'an', Object.defineProperty(Assertion.prototype, 'is', { get: function () { return this; - } + }, + configurable: true }); /** @@ -189,7 +195,8 @@ Object.defineProperty(Assertion.prototype, 'is', Object.defineProperty(Assertion.prototype, 'and', { get: function () { return this; - } + }, + configurable: true }); /** @@ -204,7 +211,8 @@ Object.defineProperty(Assertion.prototype, 'and', Object.defineProperty(Assertion.prototype, 'have', { get: function () { return this; - } + }, + configurable: true }); /** @@ -219,7 +227,8 @@ Object.defineProperty(Assertion.prototype, 'have', Object.defineProperty(Assertion.prototype, 'with', { get: function () { return this; - } + }, + configurable: true }); /** @@ -235,7 +244,8 @@ Object.defineProperty(Assertion.prototype, 'not', { get: function () { this.negate = true; return this; - } + }, + configurable: true }); /** @@ -260,7 +270,8 @@ Object.defineProperty(Assertion.prototype, 'ok', , 'expected ' + this.inspect + ' to be falsey'); return this; - } + }, + configurable: true }); /** @@ -280,7 +291,8 @@ Object.defineProperty(Assertion.prototype, 'true', , 'expected ' + this.inspect + ' to be false'); return this; - } + }, + configurable: true }); /** @@ -300,7 +312,8 @@ Object.defineProperty(Assertion.prototype, 'false', , 'expected ' + this.inspect + ' to be true'); return this; - } + }, + configurable: true }); /** @@ -325,7 +338,8 @@ Object.defineProperty(Assertion.prototype, 'exist', , 'expected ' + this.inspect + ' to not exist'); return this; - } + }, + configurable: true }); /** @@ -349,7 +363,8 @@ Object.defineProperty(Assertion.prototype, 'empty', , 'expected ' + this.inspect + ' not to be empty'); return this; - } + }, + configurable: true }); /** @@ -373,7 +388,8 @@ Object.defineProperty(Assertion.prototype, 'arguments', , 'expected ' + this.inspect + ' to not be arguments'); return this; - } + }, + configurable: true }); /** @@ -698,7 +714,8 @@ Object.defineProperty(Assertion.prototype, 'contain', { get: function () { this.contains = true; return this; - } + }, + configurable: true }); /**