From a22a6deae08020e4857c558c1ed500efd88d3d85 Mon Sep 17 00:00:00 2001 From: Borys Levytskyi Date: Sat, 4 Apr 2015 19:35:18 +0300 Subject: [PATCH] should append names --- core/should.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/core/should.js b/core/should.js index 5046ad2..bc328ca 100644 --- a/core/should.js +++ b/core/should.js @@ -4,19 +4,19 @@ window.core.should = { beNumber: function (num, name) { this.check(typeof num == "number" && !isNaN(num), num + " is not a number"); - this.check(isFinite(num), num + "is an infinite number") + this.check(isFinite(num), append(name, "is an infinite number")); }, - bePositiveInteger: function(num) { + bePositiveInteger: function(num, name) { this.beNumber(num); - this.check(num >= 0, "Should be positive integer") + this.check(num >= 0, append(name, "should be positive integer")); }, notBeNull: function (obj, name) { - this.check(obj != null, name + " is null or undefined"); + this.check(obj != null, append(name, "is null or undefined")); }, - beString: function(obj) { + beString: function(obj, name) { this.check(typeof obj == "string", "should be a string"); }, check: function(assertion, message) { @@ -25,6 +25,10 @@ } } }; + + function append(name, msg) { + return typeof name == "string" ? name + " " + msg : msg; + } })();