Skip to content

Commit

Permalink
Replaces assertIf name as it can lead to misunderstanding
Browse files Browse the repository at this point in the history
  • Loading branch information
btd committed Jan 10, 2014
1 parent 41531f3 commit 60e180a
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion lib/ext/bool.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ module.exports = function(should, Assertion) {
Assertion.add('ok', function() {
this.params = { operator: 'to be truthy' };

this.assertIf(this.obj);
this.assert(this.obj);
}, true);
};
6 changes: 3 additions & 3 deletions lib/ext/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ module.exports = function (should, Assertion) {
this.params = { operator: 'to include an object equal to ' + i(obj), message: description };
var cmp = {};
for (var key in obj) cmp[key] = this.obj[key];
this.assertIf(eql(cmp, obj));
this.assert(eql(cmp, obj));
} else {
this.params = { operator: 'to include ' + i(obj), message: description };

this.assertIf(~this.obj.indexOf(obj));
this.assert(~this.obj.indexOf(obj));
}
})

Assertion.add('includeEql', function(obj, description) {
this.params = { operator: 'to include an object equal to ' + i(obj), message: description };

this.assertIf(this.obj.some(function(item) { return eql(obj, item); }));
this.assert(this.obj.some(function(item) { return eql(obj, item); }));
});
}
4 changes: 2 additions & 2 deletions lib/ext/eql.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ module.exports = function(should, Assertion) {
Assertion.add('eql', function(val, description) {
this.params = { operator: 'to equal', expected: val, showDiff: true, message: description };

this.assertIf(eql(val, this.obj));
this.assert(eql(val, this.obj));
});

Assertion.add('equal', function(val, description) {
this.params = { operator: 'to be', expected: val, showDiff: true, message: description };

this.assertIf(val === this.obj);
this.assert(val === this.obj);
});

Assertion.alias('equal', 'exactly');
Expand Down
2 changes: 1 addition & 1 deletion lib/ext/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = function(should, Assertion) {

this.params = { operator: 'to throw exception' + errorInfo };

this.assertIf(ok);
this.assert(ok);
});

Assertion.alias('throw', 'throwError');
Expand Down
14 changes: 7 additions & 7 deletions lib/ext/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ module.exports = function(should, Assertion) {

if(util.isString(this.obj)) {

this.assertIf(other.exec(this.obj));
this.assert(other.exec(this.obj));
} else if(Array.isArray(this.obj)) {

this.obj.forEach(function(item) {
this.assertIf(other.exec(item));// should we try to convert to String and exec?
this.assert(other.exec(item));// should we try to convert to String and exec?
}, this);
} else if(util.isObject(this.obj)) {

Expand All @@ -37,7 +37,7 @@ module.exports = function(should, Assertion) {
if(matchedProps.length)
this.params.operator += '\n\tmatched properties: ' + matchedProps.join(', ');

this.assertIf(notMatchedProps.length == 0);
this.assert(notMatchedProps.length == 0);
} // should we try to convert to String and exec?
} else if(util.isFunction(other)) {
try {
Expand All @@ -55,7 +55,7 @@ module.exports = function(should, Assertion) {

//if we throw exception ok - it is used .should inside
if(util.isBoolean(res)) {
this.assertIf(res); // if it is just boolean function assert on it
this.assert(res); // if it is just boolean function assert on it
}
} else if(util.isObject(other)) { // try to match properties (for Object and Array)
var notMatchedProps = [], matchedProps = [];
Expand All @@ -78,9 +78,9 @@ module.exports = function(should, Assertion) {
if(matchedProps.length)
this.params.operator += '\n\tmatched properties: ' + matchedProps.join(', ');

this.assertIf(notMatchedProps.length == 0);
this.assert(notMatchedProps.length == 0);
} else {
this.assertIf(false);
this.assert(false);
}
}
});
Expand All @@ -100,7 +100,7 @@ module.exports = function(should, Assertion) {

//if we throw exception ok - it is used .should inside
if(util.isBoolean(res)) {
this.assertIf(res); // if it is just boolean function assert on it
this.assert(res); // if it is just boolean function assert on it
}
}, this);
});
Expand Down
12 changes: 6 additions & 6 deletions lib/ext/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,39 @@ module.exports = function(should, Assertion) {
this.params = { operator: 'to be NaN' };

this.is.a.Number
.and.assertIf(isNaN(this.obj));
.and.assert(isNaN(this.obj));
}, true);

Assertion.add('Infinity', function() {
this.params = { operator: 'to be Infinity' };

this.is.a.Number
.and.not.a.NaN
.and.assertIf(!isFinite(this.obj));
.and.assert(!isFinite(this.obj));
}, true);

Assertion.add('within', function(start, finish, description){
this.params = { operator: 'to be within '+ start + '..' + finish, message: description };

this.assertIf(this.obj >= start && this.obj <= finish);
this.assert(this.obj >= start && this.obj <= finish);
});

Assertion.add('approximately', function(value, delta, description) {
this.params = { operator: 'to be approximately ' + value + " ±" + delta, message: description };

this.assertIf(Math.abs(this.obj - value) <= delta);
this.assert(Math.abs(this.obj - value) <= delta);
});

Assertion.add('above', function(n, description){
this.params = { operator: 'to be above ' + n, message: description };

this.assertIf(this.obj > n);
this.assert(this.obj > n);
});

Assertion.add('below', function(n, description){
this.params = { operator: 'to be below ' + n, message: description };

this.assertIf(this.obj < n);
this.assert(this.obj < n);
});

Assertion.alias('above', 'greaterThan');
Expand Down
20 changes: 10 additions & 10 deletions lib/ext/property.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = function(should, Assertion) {

this.params = { operator: operator };

this.assertIf(missingProperties.length === 0);
this.assert(missingProperties.length === 0);

// check if values in object matched expected
var valueCheckNames = Object.keys(values);
Expand All @@ -80,7 +80,7 @@ module.exports = function(should, Assertion) {

this.params = { operator: operator };

this.assertIf(wrongValues.length === 0);
this.assert(wrongValues.length === 0);
}
});

Expand All @@ -95,7 +95,7 @@ module.exports = function(should, Assertion) {
Assertion.add('ownProperty', function(name, description){
this.params = { operator: 'to have own property ' + i(name), message: description };

this.assertIf(hasOwnProperty.call(this.obj, name));
this.assert(hasOwnProperty.call(this.obj, name));

this.obj = this.obj[name];
});
Expand Down Expand Up @@ -148,7 +148,7 @@ module.exports = function(should, Assertion) {
if(extraKeys.length > 0)
this.params.operator += '\n\textra keys: ' + extraKeys.join(', ');

this.assertIf(missingKeys.length === 0 && extraKeys.length === 0);
this.assert(missingKeys.length === 0 && extraKeys.length === 0);
});

Assertion.alias("keys", "key");
Expand All @@ -157,20 +157,20 @@ module.exports = function(should, Assertion) {
this.params = { operator: 'to contain ' + i(other) };
var obj = this.obj;
if(Array.isArray(obj)) {
this.assertIf(obj.some(function(item) {
this.assert(obj.some(function(item) {
return eql(item, other);
}));
} else if(util.isString(obj)) {
// expect obj to be string
this.assertIf(obj.indexOf(String(other)) >= 0);
this.assert(obj.indexOf(String(other)) >= 0);
} else if(util.isObject(obj)) {
// object contains object case
Object.keys(other).forEach(function(key) {
Object(obj[key]).should.eql(other[key]);
}, this);
} else {
//other uncovered cases
this.assertIf(false);
this.assert(false);
}
});

Expand All @@ -179,7 +179,7 @@ module.exports = function(should, Assertion) {
var obj = this.obj;
if(Array.isArray(obj)) {
if(Array.isArray(other)) {
this.assertIf(other.every(function(item) {
this.assert(other.every(function(item) {
try {
obj.should.containDeep(item);
return true;
Expand All @@ -188,7 +188,7 @@ module.exports = function(should, Assertion) {
}
}));
} else {
this.assertIf(obj.some(function(item) {
this.assert(obj.some(function(item) {
try {
item.should.containDeep(other);
return true;
Expand All @@ -199,7 +199,7 @@ module.exports = function(should, Assertion) {
}
} else if(util.isString(obj)) {
// expect obj to be string
this.assertIf(obj.indexOf(String(other)) >= 0);
this.assert(obj.indexOf(String(other)) >= 0);
} else if(util.isObject(obj)) {
// object contains object case
Object.keys(other).forEach(function(key) {
Expand Down
4 changes: 2 additions & 2 deletions lib/ext/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ module.exports = function(should, Assertion) {
Assertion.add('startWith', function(str, description) {
this.params = { operator: 'to start with ' + should.format(str), message: description };

this.assertIf(0 === this.obj.indexOf(str));
this.assert(0 === this.obj.indexOf(str));
});

Assertion.add('endWith', function(str, description) {
this.params = { operator: 'to end with ' + should.format(str), message: description };

this.assertIf(this.obj.indexOf(str, this.obj.length - str.length) >= 0);
this.assert(this.obj.indexOf(str, this.obj.length - str.length) >= 0);
});
}
18 changes: 9 additions & 9 deletions lib/ext/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ module.exports = function(should, Assertion) {
Assertion.add('Number', function() {
this.params = { operator: 'to be a number' };

this.assertIf(util.isNumber(this.obj));
this.assert(util.isNumber(this.obj));
}, true);

Assertion.add('arguments', function() {
this.params = { operator: 'to be arguments' };

this.assertIf(util.isArguments(this.obj));
this.assert(util.isArguments(this.obj));
}, true);

Assertion.add('type', function(type, description) {
Expand All @@ -28,43 +28,43 @@ module.exports = function(should, Assertion) {
Assertion.add('instanceof', function(constructor, description){
this.params = { operator: 'to be an instance of ' + constructor.name, message: description };

this.assertIf(Object(this.obj) instanceof constructor);
this.assert(Object(this.obj) instanceof constructor);
});

Assertion.add('Function', function() {
this.params = { operator: 'to be a function' };

this.assertIf(util.isFunction(this.obj));
this.assert(util.isFunction(this.obj));
}, true);

Assertion.add('Object', function() {
this.params = { operator: 'to be an object' };

this.assertIf(util.isObject(this.obj));
this.assert(util.isObject(this.obj));
}, true);

Assertion.add('String', function() {
this.params = { operator: 'to be a string' };

this.assertIf(util.isString(this.obj));
this.assert(util.isString(this.obj));
}, true);

Assertion.add('Array', function() {
this.params = { operator: 'to be an array' };

this.assertIf(Array.isArray(this.obj));
this.assert(Array.isArray(this.obj));
}, true);

Assertion.add('Boolean', function() {
this.params = { operator: 'to be a boolean' };

this.assertIf(util.isBoolean(this.obj));
this.assert(util.isBoolean(this.obj));
}, true);

Assertion.add('Error', function() {
this.params = { operator: 'to be an error' };

this.assertIf(util.isError(this.obj));
this.assert(util.isError(this.obj));
}, true);


Expand Down
8 changes: 4 additions & 4 deletions lib/should.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ Assertion.add = function(name, f, isGetter) {
this.negate = false;
return this;
}
this.assertIf(false);
this.assert(false);
}
// throw if it is another exception
throw e;
}
//copy data from sub context to this
this.copy(context);
if(this.negate) {
this.assertIf(false);
this.assert(false);
}

this.obj = context.obj;
Expand Down Expand Up @@ -117,7 +117,7 @@ Object.defineProperty(Object.prototype, 'should', {
Assertion.prototype = {
constructor: Assertion,

assertIf: function(expr) {
assert: function(expr) {
if(expr) return;

var params = this.params;
Expand All @@ -132,7 +132,7 @@ Assertion.prototype = {
message: msg
, actual: this.obj
, expected: params.expected
, stackStartFunction: this.assertIf
, stackStartFunction: this.assert
});

err.showDiff = params.showDiff;
Expand Down

0 comments on commit 60e180a

Please sign in to comment.