From 60e180ad67b7a09dfa238bf6244aa4a8c3572785 Mon Sep 17 00:00:00 2001 From: Denis Bardadym Date: Fri, 10 Jan 2014 14:07:43 +0400 Subject: [PATCH] Replaces assertIf name as it can lead to misunderstanding --- lib/ext/bool.js | 2 +- lib/ext/deprecated.js | 6 +++--- lib/ext/eql.js | 4 ++-- lib/ext/error.js | 2 +- lib/ext/match.js | 14 +++++++------- lib/ext/number.js | 12 ++++++------ lib/ext/property.js | 20 ++++++++++---------- lib/ext/string.js | 4 ++-- lib/ext/type.js | 18 +++++++++--------- lib/should.js | 8 ++++---- 10 files changed, 45 insertions(+), 45 deletions(-) diff --git a/lib/ext/bool.js b/lib/ext/bool.js index a616a1d..42c73a9 100644 --- a/lib/ext/bool.js +++ b/lib/ext/bool.js @@ -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); }; \ No newline at end of file diff --git a/lib/ext/deprecated.js b/lib/ext/deprecated.js index 125e19f..3f512fc 100644 --- a/lib/ext/deprecated.js +++ b/lib/ext/deprecated.js @@ -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); })); }); } \ No newline at end of file diff --git a/lib/ext/eql.js b/lib/ext/eql.js index ee3a9c9..e3b03e5 100644 --- a/lib/ext/eql.js +++ b/lib/ext/eql.js @@ -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'); diff --git a/lib/ext/error.js b/lib/ext/error.js index 0af30cb..93a934a 100644 --- a/lib/ext/error.js +++ b/lib/ext/error.js @@ -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'); diff --git a/lib/ext/match.js b/lib/ext/match.js index f7b1a9b..45f0e81 100644 --- a/lib/ext/match.js +++ b/lib/ext/match.js @@ -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)) { @@ -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 { @@ -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 = []; @@ -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); } } }); @@ -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); }); diff --git a/lib/ext/number.js b/lib/ext/number.js index 0684e5d..ad80c4e 100644 --- a/lib/ext/number.js +++ b/lib/ext/number.js @@ -9,7 +9,7 @@ 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() { @@ -17,31 +17,31 @@ module.exports = function(should, Assertion) { 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'); diff --git a/lib/ext/property.js b/lib/ext/property.js index bfa857c..873fb5b 100644 --- a/lib/ext/property.js +++ b/lib/ext/property.js @@ -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); @@ -80,7 +80,7 @@ module.exports = function(should, Assertion) { this.params = { operator: operator }; - this.assertIf(wrongValues.length === 0); + this.assert(wrongValues.length === 0); } }); @@ -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]; }); @@ -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"); @@ -157,12 +157,12 @@ 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) { @@ -170,7 +170,7 @@ module.exports = function(should, Assertion) { }, this); } else { //other uncovered cases - this.assertIf(false); + this.assert(false); } }); @@ -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; @@ -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; @@ -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) { diff --git a/lib/ext/string.js b/lib/ext/string.js index 379bcdc..e89eb37 100644 --- a/lib/ext/string.js +++ b/lib/ext/string.js @@ -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); }); } \ No newline at end of file diff --git a/lib/ext/type.js b/lib/ext/type.js index 57afcb9..72739eb 100644 --- a/lib/ext/type.js +++ b/lib/ext/type.js @@ -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) { @@ -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); diff --git a/lib/should.js b/lib/should.js index 126a8df..408e4b9 100644 --- a/lib/should.js +++ b/lib/should.js @@ -58,7 +58,7 @@ 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; @@ -66,7 +66,7 @@ Assertion.add = function(name, f, isGetter) { //copy data from sub context to this this.copy(context); if(this.negate) { - this.assertIf(false); + this.assert(false); } this.obj = context.obj; @@ -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; @@ -132,7 +132,7 @@ Assertion.prototype = { message: msg , actual: this.obj , expected: params.expected - , stackStartFunction: this.assertIf + , stackStartFunction: this.assert }); err.showDiff = params.showDiff;