diff --git a/lib/jasmine-0.10.0.js b/lib/jasmine-0.10.0.js index f7f621b..d5abe6a 100644 --- a/lib/jasmine-0.10.0.js +++ b/lib/jasmine-0.10.0.js @@ -1201,12 +1201,28 @@ jasmine.Matchers.prototype.wasCalledWith = function() { } this.message = function() { - return "Expected spy to have been called with " + jasmine.pp(arguments) + " but was called with " + jasmine.pp(this.actual.argsForCall); + if (this.actual.callCount == 0) { + return "Expected spy to have been called with " + jasmine.pp(arguments) + " 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 this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments)); }; +jasmine.Matchers.prototype.wasNotCalledWith = function() { + 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 !this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments)); +}; + /** * Matcher that checks that the expected item is an element in the actual Array. * @@ -1437,14 +1453,14 @@ jasmine.PrettyPrinter.prototype.format = function(value) { this.emitString(value); } else if (jasmine.isSpy(value)) { this.emitScalar("spy on " + value.identity); + } else if (value instanceof RegExp) { + this.emitScalar(value.toString()); } else if (typeof value === 'function') { this.emitScalar('Function'); } else if (typeof value.nodeType === 'number') { this.emitScalar('HTMLNode'); } else if (value instanceof Date) { this.emitScalar('Date(' + value + ')'); - } else if (value instanceof RegExp) { - this.emitScalar(value.toString()); } else if (value.__Jasmine_been_here_before__) { this.emitScalar(''); } else if (jasmine.isArray_(value) || typeof value == 'object') { @@ -2241,5 +2257,5 @@ jasmine.version_= { "major": 0, "minor": 10, "build": 0, - "revision": 1259251766 + "revision": 1261424713 }; diff --git a/spec/suites/SpySpec.js b/spec/suites/SpySpec.js index 1e782fb..37dd04f 100644 --- a/spec/suites/SpySpec.js +++ b/spec/suites/SpySpec.js @@ -33,8 +33,8 @@ describe('Spies', function () { TestClass.someFunction('foo'); TestClass.someFunction('bar'); - expect(TestClass.someFunction.argsForCall[0]).toEqual(['foo']); - expect(TestClass.someFunction.argsForCall[1]).toEqual(['bar']); + expect(TestClass.someFunction.calls[0].args).toEqual(['foo']); + expect(TestClass.someFunction.calls[1].args).toEqual(['bar']); expect(TestClass.someFunction.mostRecentCall.args).toEqual(['bar']); }); @@ -184,4 +184,4 @@ describe('Spies', function () { expect(spyObj.method2.identity).toEqual('BaseName.method2'); }); -}); \ No newline at end of file +}); diff --git a/src/Matchers.js b/src/Matchers.js index 79f5d53..fd88829 100644 --- a/src/Matchers.js +++ b/src/Matchers.js @@ -198,12 +198,28 @@ jasmine.Matchers.prototype.wasCalledWith = function() { } this.message = function() { - return "Expected spy to have been called with " + jasmine.pp(arguments) + " but was called with " + jasmine.pp(this.actual.argsForCall); + if (this.actual.callCount == 0) { + return "Expected spy to have been called with " + jasmine.pp(arguments) + " 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 this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments)); }; +jasmine.Matchers.prototype.wasNotCalledWith = function() { + 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 !this.env.contains_(this.actual.argsForCall, jasmine.util.argsToArray(arguments)); +}; + /** * Matcher that checks that the expected item is an element in the actual Array. *