Squashed spy refactor and new spy syntax

Jasmine spies now have a 'and' property which allows the user to
change the spy's execution strategy-- such as '.and.callReturn(4)'
and a 'calls' property which allows inspection of the calls a spy
has received.

* This is a breaking change *

There is a CallTracker that keeps track of all calls and arguments
and a SpyStrategy which determines what the spy should do when it
is called.
This commit is contained in:
Davis W. Frank & Sheel Choksi
2013-07-17 23:11:55 -07:00
committed by Colin O'Byrne and JR Boyens
parent 18c30566bd
commit 3847557bbc
32 changed files with 692 additions and 413 deletions

View File

@@ -1,11 +1,11 @@
describe("toHaveBeenCalledWith", function() {
it("passes when the actual was called with matching parameters", function() {
var util = {
contains: jasmine.createSpy('delegated-contains').andReturn(true)
},
matcher = j$.matchers.toHaveBeenCalledWith(util),
calledSpy = jasmine.createSpy('called-spy'),
result;
contains: jasmine.createSpy('delegated-contains').and.callReturn(true)
},
matcher = j$.matchers.toHaveBeenCalledWith(util),
calledSpy = j$.createSpy('called-spy'),
result;
calledSpy('a', 'b');
result = matcher.compare(calledSpy, 'a', 'b');
@@ -15,11 +15,11 @@ describe("toHaveBeenCalledWith", function() {
it("fails when the actual was not called", function() {
var util = {
contains: jasmine.createSpy('delegated-contains').andReturn(false)
},
matcher = j$.matchers.toHaveBeenCalledWith(util),
uncalledSpy = jasmine.createSpy('uncalled spy'),
result;
contains: jasmine.createSpy('delegated-contains').and.callReturn(false)
},
matcher = j$.matchers.toHaveBeenCalledWith(util),
uncalledSpy = j$.createSpy('uncalled spy'),
result;
result = matcher.compare(uncalledSpy);
expect(result.pass).toBe(false);
@@ -27,11 +27,11 @@ describe("toHaveBeenCalledWith", function() {
it("fails when the actual was called with different parameters", function() {
var util = {
contains: jasmine.createSpy('delegated-contains').andReturn(false)
},
matcher = j$.matchers.toHaveBeenCalledWith(util),
calledSpy = jasmine.createSpy('called spy'),
result;
contains: jasmine.createSpy('delegated-contains').and.callReturn(false)
},
matcher = j$.matchers.toHaveBeenCalledWith(util),
calledSpy = j$.createSpy('called spy'),
result;
calledSpy('a');
result = matcher.compare(calledSpy, 'a', 'b');
@@ -41,15 +41,15 @@ describe("toHaveBeenCalledWith", function() {
it("throws an exception when the actual is not a spy", function() {
var matcher = j$.matchers.toHaveBeenCalledWith(),
fn = function() {};
fn = function() {};
expect(function() { matcher.compare(fn) }).toThrow(new Error("Expected a spy, but got Function."));
});
it("has a custom message on failure", function() {
var matcher = j$.matchers.toHaveBeenCalledWith(),
spy = jasmine.createSpy('sample-spy'),
messages = matcher.message(spy);
spy = j$.createSpy('sample-spy'),
messages = matcher.message(spy);
expect(messages.affirmative).toEqual("Expected spy sample-spy to have been called.")
expect(messages.negative).toEqual("Expected spy sample-spy not to have been called.")