diff --git a/lib/jasmine-0.10.1.js b/lib/jasmine-0.10.1.js index 0f6c015..f9bd7d6 100644 --- a/lib/jasmine-0.10.1.js +++ b/lib/jasmine-0.10.1.js @@ -1001,10 +1001,11 @@ jasmine.JsApiReporter.prototype.summarizeResult_ = function(result){ * @param actual * @param {jasmine.Spec} spec */ -jasmine.Matchers = function(env, actual, spec) { +jasmine.Matchers = function(env, actual, spec, opt_isNot) { this.env = env; this.actual = actual; this.spec = spec; + this.isNot = opt_isNot || false; this.reportWasCalled_ = false; }; @@ -1014,8 +1015,12 @@ jasmine.Matchers.pp = function(str) { /** @deprecated */ jasmine.Matchers.prototype.report = function(result, failing_message, details) { -// todo first: report deprecation warning [xw] -// todo later: throw new Error("As of jasmine 0.xx, custom matchers must be implemented differently -- please see jasmine docs"); + // todo: report a deprecation warning [xw] + + if (this.isNot) { + throw new Error("As of jasmine 0.11, custom matchers must be implemented differently -- please see jasmine docs"); + } + this.reportWasCalled_ = true; var expectationResult = new jasmine.ExpectationResult({ passed: result, @@ -1038,15 +1043,23 @@ jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) { return function() { var matcherArgs = jasmine.util.argsToArray(arguments); var result = matcherFunction.apply(this, arguments); + + if (this.isNot) { + result = !result; + } + if (this.reportWasCalled_) return result; var message; if (!result) { if (this.message) { message = this.message.apply(this, arguments); + if (jasmine.isArray_(message)) { + message = message[this.isNot ? 1 : 0]; + } } else { var englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); }); - message = "Expected " + jasmine.pp(this.actual) + " " + englishyPredicate; + message = "Expected " + jasmine.pp(this.actual) + (this.isNot ? " not " : " ") + englishyPredicate; if (matcherArgs.length > 0) { for (var i = 0; i < matcherArgs.length; i++) { if (i > 0) message += ","; @@ -1818,7 +1831,9 @@ jasmine.Spec.prototype.addMatcherResult = function(result) { }; jasmine.Spec.prototype.expect = function(actual) { - return new (this.getMatchersClass_())(this.env, actual, this); + var positive = new (this.getMatchersClass_())(this.env, actual, this); + positive.not = new (this.getMatchersClass_())(this.env, actual, this, true); + return positive; }; jasmine.Spec.prototype.waits = function(timeout) { @@ -2257,5 +2272,5 @@ jasmine.version_= { "major": 0, "minor": 10, "build": 1, - "revision": 1267069453 + "revision": 1267503060 };