diff options
| author | Misko Hevery | 2010-03-15 14:36:50 -0700 |
|---|---|---|
| committer | Misko Hevery | 2010-03-15 14:36:50 -0700 |
| commit | cc71b745c3c821f5e012a363ae3267252a81fddb (patch) | |
| tree | b86a76a131aa222b8bdf032480dc2ef0dca51a97 /lib/jasmine | |
| parent | bf838aab5d65a1019a4867b496e971c488589512 (diff) | |
| download | angular.js-cc71b745c3c821f5e012a363ae3267252a81fddb.tar.bz2 | |
added resources; removed compiled code
Diffstat (limited to 'lib/jasmine')
| -rw-r--r-- | lib/jasmine/jasmine-0.10.1.js (renamed from lib/jasmine/jasmine-0.10.0.js) | 57 |
1 files changed, 36 insertions, 21 deletions
diff --git a/lib/jasmine/jasmine-0.10.0.js b/lib/jasmine/jasmine-0.10.1.js index bb7547e8..f9bd7d6f 100644 --- a/lib/jasmine/jasmine-0.10.0.js +++ b/lib/jasmine/jasmine-0.10.1.js @@ -15,7 +15,7 @@ jasmine.unimplementedMethod_ = function() { /** * Use <code>jasmine.undefined</code> instead of <code>undefined</code>, since <code>undefined</code is just * a plain old variable and may be redefined by somebody else. - * + * * @private */ jasmine.undefined = jasmine.___undefined___; @@ -66,7 +66,7 @@ jasmine.ExpectationResult = function(params) { /** @deprecated */ this.details = params.details; - + this.message = this.passed_ ? 'Passed.' : params.message; this.trace = this.passed_ ? '' : new Error(this.message); }; @@ -89,11 +89,7 @@ jasmine.getEnv = function() { * @returns {Boolean} */ jasmine.isArray_ = function(value) { - return value && - typeof value === 'object' && - typeof value.length === 'number' && - typeof value.splice === 'function' && - !(value.propertyIsEnumerable('length')); + return Object.prototype.toString.apply(value) === '[object Array]'; }; /** @@ -350,6 +346,9 @@ jasmine.isSpy = function(putativeSpy) { * @param {Array} methodNames array of names of methods to make spies */ jasmine.createSpyObj = function(baseName, methodNames) { + if (!jasmine.isArray_(methodNames) || methodNames.length == 0) { + throw new Error('createSpyObj requires a non-empty array of method names to create spies for'); + } var obj = {}; for (var i = 0; i < methodNames.length; i++) { obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]); @@ -1002,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; }; @@ -1015,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, @@ -1039,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 += ","; @@ -1204,31 +1216,32 @@ jasmine.Matchers.prototype.wasNotCalled = function() { * */ jasmine.Matchers.prototype.wasCalledWith = function() { + var expectedArgs = jasmine.util.argsToArray(arguments); if (!jasmine.isSpy(this.actual)) { throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); } - this.message = function() { if (this.actual.callCount == 0) { - return "Expected spy to have been called with " + jasmine.pp(arguments) + " but it was never called."; + return "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was never called."; } else { - return "Expected spy to have been called with " + jasmine.pp(arguments) + " but was called with " + jasmine.pp(this.actual.argsForCall); + return "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall); } }; - return this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments)); + return this.env.contains_(this.actual.argsForCall, expectedArgs); }; jasmine.Matchers.prototype.wasNotCalledWith = function() { + var expectedArgs = jasmine.util.argsToArray(arguments); if (!jasmine.isSpy(this.actual)) { throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); } this.message = function() { - return "Expected spy not to have been called with " + jasmine.pp(arguments) + " but it was"; + return "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was"; }; - return !this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments)); + return !this.env.contains_(this.actual.argsForCall, expectedArgs); }; /** @@ -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) { @@ -2256,6 +2271,6 @@ window.clearInterval = function(timeoutKey) { jasmine.version_= { "major": 0, "minor": 10, - "build": 0, - "revision": 1261768736 + "build": 1, + "revision": 1267503060 }; |
