Permalink
Browse files

Merge pull request #32 from visionmedia/add/lazy-messages

Add/lazy messages
  • Loading branch information...
2 parents e0de582 + e8a6c47 commit de2fdcb85ffad038c1b4d134a34b9c7f70928767 @rauchg rauchg committed Aug 1, 2012
Showing with 40 additions and 40 deletions.
  1. +1 −1 Makefile
  2. +39 −39 expect.js
View
@@ -3,7 +3,7 @@ REPORTER = dot
test:
@./node_modules/.bin/mocha \
- --require $(shell pwd)/test/common \
+ --require ./test/common \
--reporter $(REPORTER) \
--growl \
test/expect.js
View
@@ -96,7 +96,7 @@
, ok = this.flags.not ? !truth : truth;
if (!ok) {
- throw new Error(msg);
+ throw new Error(msg.call(this));
}
this.and = new Assertion(this.obj);
@@ -111,8 +111,8 @@
Assertion.prototype.ok = function () {
this.assert(
!!this.obj
- , 'expected ' + i(this.obj) + ' to be truthy'
- , 'expected ' + i(this.obj) + ' to be falsy');
+ , function(){ return 'expected ' + i(this.obj) + ' to be truthy' }
+ , function(){ return 'expected ' + i(this.obj) + ' to be falsy' });
};
/**
@@ -154,8 +154,8 @@
var name = this.obj.name || 'fn';
this.assert(
thrown
- , 'expected ' + name + ' to throw an exception'
- , 'expected ' + name + ' not to throw an exception');
+ , function(){ return 'expected ' + name + ' to throw an exception' }
+ , function(){ return 'expected ' + name + ' not to throw an exception' });
};
/**
@@ -184,8 +184,8 @@
this.assert(
expectation
- , 'expected ' + i(this.obj) + ' to be empty'
- , 'expected ' + i(this.obj) + ' to not be empty');
+ , function(){ return 'expected ' + i(this.obj) + ' to be empty' }
+ , function(){ return 'expected ' + i(this.obj) + ' to not be empty' });
return this;
};
@@ -199,8 +199,8 @@
Assertion.prototype.equal = function (obj) {
this.assert(
obj === this.obj
- , 'expected ' + i(this.obj) + ' to equal ' + i(obj)
- , 'expected ' + i(this.obj) + ' to not equal ' + i(obj));
+ , function(){ return 'expected ' + i(this.obj) + ' to equal ' + i(obj) }
+ , function(){ return 'expected ' + i(this.obj) + ' to not equal ' + i(obj) });
return this;
};
@@ -213,8 +213,8 @@
Assertion.prototype.eql = function (obj) {
this.assert(
expect.eql(obj, this.obj)
- , 'expected ' + i(this.obj) + ' to sort of equal ' + i(obj)
- , 'expected ' + i(this.obj) + ' to sort of not equal ' + i(obj));
+ , function(){ return 'expected ' + i(this.obj) + ' to sort of equal ' + i(obj) }
+ , function(){ return 'expected ' + i(this.obj) + ' to sort of not equal ' + i(obj) });
return this;
};
@@ -230,8 +230,8 @@
var range = start + '..' + finish;
this.assert(
this.obj >= start && this.obj <= finish
- , 'expected ' + i(this.obj) + ' to be within ' + range
- , 'expected ' + i(this.obj) + ' to not be within ' + range);
+ , function(){ return 'expected ' + i(this.obj) + ' to be within ' + range }
+ , function(){ return 'expected ' + i(this.obj) + ' to not be within ' + range });
return this;
};
@@ -253,15 +253,15 @@
'object' == type
? 'object' == typeof this.obj && null !== this.obj
: type == typeof this.obj
- , 'expected ' + i(this.obj) + ' to be a' + n + ' ' + type
- , 'expected ' + i(this.obj) + ' not to be a' + n + ' ' + type);
+ , function(){ return 'expected ' + i(this.obj) + ' to be a' + n + ' ' + type }
+ , function(){ return 'expected ' + i(this.obj) + ' not to be a' + n + ' ' + type });
} else {
// instanceof
var name = type.name || 'supplied constructor';
this.assert(
this.obj instanceof type
- , 'expected ' + i(this.obj) + ' to be an instance of ' + name
- , 'expected ' + i(this.obj) + ' not to be an instance of ' + name);
+ , function(){ return 'expected ' + i(this.obj) + ' to be an instance of ' + name }
+ , function(){ return 'expected ' + i(this.obj) + ' not to be an instance of ' + name });
}
return this;
@@ -278,8 +278,8 @@
Assertion.prototype.above = function (n) {
this.assert(
this.obj > n
- , 'expected ' + i(this.obj) + ' to be above ' + n
- , 'expected ' + i(this.obj) + ' to be below ' + n);
+ , function(){ return 'expected ' + i(this.obj) + ' to be above ' + n }
+ , function(){ return 'expected ' + i(this.obj) + ' to be below ' + n });
return this;
};
@@ -294,8 +294,8 @@
Assertion.prototype.below = function (n) {
this.assert(
this.obj < n
- , 'expected ' + i(this.obj) + ' to be below ' + n
- , 'expected ' + i(this.obj) + ' to be above ' + n);
+ , function(){ return 'expected ' + i(this.obj) + ' to be below ' + n }
+ , function(){ return 'expected ' + i(this.obj) + ' to be above ' + n });
return this;
};
@@ -309,8 +309,8 @@
Assertion.prototype.match = function (regexp) {
this.assert(
regexp.exec(this.obj)
- , 'expected ' + i(this.obj) + ' to match ' + regexp
- , 'expected ' + i(this.obj) + ' not to match ' + regexp);
+ , function(){ return 'expected ' + i(this.obj) + ' to match ' + regexp }
+ , function(){ return 'expected ' + i(this.obj) + ' not to match ' + regexp });
return this;
};
@@ -326,8 +326,8 @@
var len = this.obj.length;
this.assert(
n == len
- , 'expected ' + i(this.obj) + ' to have a length of ' + n + ' but got ' + len
- , 'expected ' + i(this.obj) + ' to not have a length of ' + len);
+ , function(){ return 'expected ' + i(this.obj) + ' to have a length of ' + n + ' but got ' + len }
+ , function(){ return 'expected ' + i(this.obj) + ' to not have a length of ' + len });
return this;
};
@@ -343,8 +343,8 @@
if (this.flags.own) {
this.assert(
Object.prototype.hasOwnProperty.call(this.obj, name)
- , 'expected ' + i(this.obj) + ' to have own property ' + i(name)
- , 'expected ' + i(this.obj) + ' to not have own property ' + i(name));
+ , function(){ return 'expected ' + i(this.obj) + ' to have own property ' + i(name) }
+ , function(){ return 'expected ' + i(this.obj) + ' to not have own property ' + i(name) });
return this;
}
@@ -362,17 +362,17 @@
this.assert(
hasProp
- , 'expected ' + i(this.obj) + ' to have a property ' + i(name)
- , 'expected ' + i(this.obj) + ' to not have a property ' + i(name));
+ , function(){ return 'expected ' + i(this.obj) + ' to have a property ' + i(name) }
+ , function(){ return 'expected ' + i(this.obj) + ' to not have a property ' + i(name) });
}
if (undefined !== val) {
this.assert(
val === this.obj[name]
- , 'expected ' + i(this.obj) + ' to have a property ' + i(name)
- + ' of ' + i(val) + ', but got ' + i(this.obj[name])
- , 'expected ' + i(this.obj) + ' to not have a property ' + i(name)
- + ' of ' + i(val));
+ , function(){ return 'expected ' + i(this.obj) + ' to have a property ' + i(name)
+ + ' of ' + i(val) + ', but got ' + i(this.obj[name]) }
+ , function(){ return 'expected ' + i(this.obj) + ' to not have a property ' + i(name)
+ + ' of ' + i(val) });
}
this.obj = this.obj[name];
@@ -391,13 +391,13 @@
if ('string' == typeof this.obj) {
this.assert(
~this.obj.indexOf(obj)
- , 'expected ' + i(this.obj) + ' to contain ' + i(obj)
- , 'expected ' + i(this.obj) + ' to not contain ' + i(obj));
+ , function(){ return 'expected ' + i(this.obj) + ' to contain ' + i(obj) }
+ , function(){ return 'expected ' + i(this.obj) + ' to not contain ' + i(obj) });
} else {
this.assert(
~indexOf(this.obj, obj)
- , 'expected ' + i(this.obj) + ' to contain ' + i(obj)
- , 'expected ' + i(this.obj) + ' to not contain ' + i(obj));
+ , function(){ return 'expected ' + i(this.obj) + ' to contain ' + i(obj) }
+ , function(){ return 'expected ' + i(this.obj) + ' to not contain ' + i(obj) });
}
return this;
};
@@ -454,8 +454,8 @@
// Assertion
this.assert(
ok
- , 'expected ' + i(this.obj) + ' to ' + str
- , 'expected ' + i(this.obj) + ' to not ' + str);
+ , function(){ return 'expected ' + i(this.obj) + ' to ' + str }
+ , function(){ return 'expected ' + i(this.obj) + ' to not ' + str });
return this;
};

0 comments on commit de2fdcb

Please sign in to comment.