Skip to content

Commit

Permalink
Release 2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
btd committed Dec 5, 2013
1 parent ddaed65 commit 6bf8580
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 37 deletions.
5 changes: 5 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2.1.1 / 2013-12-05
==================

* Move date formatting out of should.inspect

2.1.0 / 2013-11-11
==================

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ "name": "should"
, "description": "test framework agnostic BDD-style assertions"
, "version": "2.1.0"
, "version": "2.1.1"
, "author": "TJ Holowaychuk <[email protected]>"
, "repository": { "type": "git", "url": "git://github.com/visionmedia/should.js.git" }
, "homepage": "https://github.com/visionmedia/should.js"
Expand Down
74 changes: 38 additions & 36 deletions should.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,12 @@ var should = function(obj) {
return new Assertion(util.isWrapperType(obj) ? obj.valueOf(): obj);
};

should.inspect = function(obj, opts) {
if(util.isDate(obj) && typeof obj.inspect !== 'function') obj = obj.toISOString();
return inspect(obj, opts);
};
should.inspect = inspect;

function i(value) {
if(util.isDate(value) && typeof value.inspect !== 'function') return value.toISOString(); //show millis in dates
return should.inspect(value);
}

/**
* Expose assert to should
Expand All @@ -215,7 +217,7 @@ util.merge(should, assert);
should.exist = should.exists = function(obj, msg) {
if(null == obj) {
throw new AssertionError({
message: msg || ('expected ' + should.inspect(obj) + ' to exist')
message: msg || ('expected ' + i(obj) + ' to exist')
, stackStartFunction: should.exist
});
}
Expand All @@ -233,7 +235,7 @@ should.not = {};
should.not.exist = should.not.exists = function(obj, msg){
if (null != obj) {
throw new AssertionError({
message: msg || ('expected ' + should.inspect(obj) + ' to not exist')
message: msg || ('expected ' + i(obj) + ' to not exist')
, stackStartFunction: should.not.exist
});
}
Expand Down Expand Up @@ -401,7 +403,7 @@ Assertion.prototype = {
*/

get inspect() {
return should.inspect(this.obj);
return i(this.obj);
},

/**
Expand Down Expand Up @@ -531,8 +533,8 @@ Assertion.prototype = {
eql: function(val, description){
this.assert(
eql(val, this.obj)
, function(){ return 'expected ' + this.inspect + ' to equal ' + should.inspect(val) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not equal ' + should.inspect(val) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to equal ' + i(val) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not equal ' + i(val) + (description ? " | " + description : "") }
, val
, true
, description);
Expand All @@ -550,8 +552,8 @@ Assertion.prototype = {
equal: function(val, description){
this.assert(
val === this.obj
, function(){ return 'expected ' + this.inspect + ' to equal ' + should.inspect(val) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not equal ' + should.inspect(val) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to equal ' + i(val) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not equal ' + i(val) + (description ? " | " + description : "") }
, val
, void 0
, description);
Expand Down Expand Up @@ -803,13 +805,13 @@ Assertion.prototype = {
property: function(name, val, description){
if (this.negate && undefined !== val) {
if (undefined === this.obj[name]) {
throw new Error(this.inspect + ' has no property ' + should.inspect(name) + (description ? " | " + description : ""));
throw new Error(this.inspect + ' has no property ' + i(name) + (description ? " | " + description : ""));
}
} else {
this.assert(
undefined !== this.obj[name]
, function(){ return 'expected ' + this.inspect + ' to have a property ' + should.inspect(name) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not have a property ' + should.inspect(name) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to have a property ' + i(name) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not have a property ' + i(name) + (description ? " | " + description : "") }
, void 0
, void 0
, description);
Expand All @@ -818,9 +820,9 @@ Assertion.prototype = {
if (undefined !== val) {
this.assert(
val === this.obj[name]
, function(){ return 'expected ' + this.inspect + ' to have a property ' + should.inspect(name)
+ ' of ' + should.inspect(val) + ', but got ' + should.inspect(this.obj[name]) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not have a property ' + should.inspect(name) + ' of ' + should.inspect(val) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to have a property ' + i(name)
+ ' of ' + i(val) + ', but got ' + i(this.obj[name]) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not have a property ' + i(name) + ' of ' + i(val) + (description ? " | " + description : "") }
, void 0
, void 0
, description);
Expand Down Expand Up @@ -854,12 +856,12 @@ Assertion.prototype = {
// key string
if (len > 1) {
names = names.map(function(name){
return should.inspect(name);
return i(name);
});
var last = names.pop();
str = names.join(', ') + ', and ' + last;
} else {
str = should.inspect(names[0]);
str = i(names[0]);
}

// message
Expand All @@ -884,8 +886,8 @@ Assertion.prototype = {
ownProperty: function(name, description){
this.assert(
hasOwnProperty.call(this.obj, name)
, function(){ return 'expected ' + this.inspect + ' to have own property ' + should.inspect(name) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not have own property ' + should.inspect(name) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to have own property ' + i(name) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not have own property ' + i(name) + (description ? " | " + description : "") }
, void 0
, void 0
, description);
Expand All @@ -902,8 +904,8 @@ Assertion.prototype = {

startWith: function(str, description) {
this.assert(0 === this.obj.indexOf(str)
, function() { return 'expected ' + this.inspect + ' to start with ' + should.inspect(str) + (description ? " | " + description : "") }
, function() { return 'expected ' + this.inspect + ' to not start with ' + should.inspect(str) + (description ? " | " + description : "") }
, function() { return 'expected ' + this.inspect + ' to start with ' + i(str) + (description ? " | " + description : "") }
, function() { return 'expected ' + this.inspect + ' to not start with ' + i(str) + (description ? " | " + description : "") }
, void 0
, void 0
, description);
Expand All @@ -919,8 +921,8 @@ Assertion.prototype = {

endWith: function(str, description) {
this.assert(-1 !== this.obj.indexOf(str, this.obj.length - str.length)
, function() { return 'expected ' + this.inspect + ' to end with ' + should.inspect(str) + (description ? " | " + description : "") }
, function() { return 'expected ' + this.inspect + ' to not end with ' + should.inspect(str) + (description ? " | " + description : "") }
, function() { return 'expected ' + this.inspect + ' to end with ' + i(str) + (description ? " | " + description : "") }
, function() { return 'expected ' + this.inspect + ' to not end with ' + i(str) + (description ? " | " + description : "") }
, void 0
, void 0
, description);
Expand All @@ -941,16 +943,16 @@ Assertion.prototype = {
for (var key in obj) cmp[key] = this.obj[key];
this.assert(
eql(cmp, obj)
, function(){ return 'expected ' + this.inspect + ' to include an object equal to ' + should.inspect(obj) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not include an object equal to ' + should.inspect(obj) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to include an object equal to ' + i(obj) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not include an object equal to ' + i(obj) + (description ? " | " + description : "") }
, void 0
, void 0
, description);
} else {
this.assert(
~this.obj.indexOf(obj)
, function(){ return 'expected ' + this.inspect + ' to include ' + should.inspect(obj) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not include ' + should.inspect(obj) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to include ' + i(obj) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not include ' + i(obj) + (description ? " | " + description : "") }
, void 0
, void 0
, description);
Expand All @@ -969,8 +971,8 @@ Assertion.prototype = {
includeEql: function(obj, description){
this.assert(
this.obj.some(function(item) { return eql(obj, item); })
, function(){ return 'expected ' + this.inspect + ' to include an object equal to ' + should.inspect(obj) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not include an object equal to ' + should.inspect(obj) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to include an object equal to ' + i(obj) + (description ? " | " + description : "") }
, function(){ return 'expected ' + this.inspect + ' to not include an object equal to ' + i(obj) + (description ? " | " + description : "") }
, void 0
, void 0
, description);
Expand Down Expand Up @@ -1009,12 +1011,12 @@ Assertion.prototype = {
// key string
if (len > 1) {
keys = keys.map(function(key){
return should.inspect(key);
return i(key);
});
var last = keys.pop();
str = keys.join(', ') + ', and ' + last;
} else {
str = should.inspect(keys[0]);
str = i(keys[0]);
}

// message
Expand Down Expand Up @@ -1058,9 +1060,9 @@ Assertion.prototype = {

this.assert(
code == status
, function(){ return 'expected response code of ' + code + ' ' + should.inspect(statusCodes[code])
+ ', but got ' + status + ' ' + should.inspect(statusCodes[status]) }
, function(){ return 'expected to not respond with ' + code + ' ' + should.inspect(statusCodes[code]) });
, function(){ return 'expected response code of ' + code + ' ' + i(statusCodes[code])
+ ', but got ' + status + ' ' + i(statusCodes[status]) }
, function(){ return 'expected to not respond with ' + code + ' ' + i(statusCodes[code]) });

return this;
},
Expand Down

0 comments on commit 6bf8580

Please sign in to comment.