Rename a spy's callReturn and callThrow

.and.callReturn is now .and.returnValue
.and.callThrow is now .and.throwError

[finishes #56281634]
This commit is contained in:
Sheel Choksi
2013-09-06 21:55:14 -07:00
parent e3f0389ac2
commit 4bff199c2a
15 changed files with 44 additions and 44 deletions

View File

@@ -1557,14 +1557,14 @@ getJasmineRequireObj().SpyStrategy = function() {
return getSpy();
};
this.callReturn = function(value) {
this.returnValue = function(value) {
plan = function() {
return value;
};
return getSpy();
};
this.callThrow = function(something) {
this.throwError = function(something) {
var error = (something instanceof Error) ? something : new Error(something);
plan = function() {
throw error;

View File

@@ -90,7 +90,7 @@ describe("ConsoleReporter", function() {
reporter.jasmineStarted();
reporter.specDone({status: "passed"});
timerSpy.elapsed.and.callReturn(1000);
timerSpy.elapsed.and.returnValue(1000);
out.clear();
reporter.jasmineDone();
@@ -127,7 +127,7 @@ describe("ConsoleReporter", function() {
out.clear();
timerSpy.elapsed.and.callReturn(100);
timerSpy.elapsed.and.returnValue(100);
reporter.jasmineDone();

View File

@@ -131,7 +131,7 @@ describe("Clock", function() {
it("returns an id for the delayed function", function() {
var fakeSetTimeout = jasmine.createSpy('setTimeout'),
scheduleId = 123,
scheduleFunction = jasmine.createSpy('scheduleFunction').and.callReturn(scheduleId),
scheduleFunction = jasmine.createSpy('scheduleFunction').and.returnValue(scheduleId),
delayedFunctionScheduler = {scheduleFunction: scheduleFunction},
fakeGlobal = { setTimeout: fakeSetTimeout },
delayedFn = jasmine.createSpy('delayedFn'),
@@ -176,7 +176,7 @@ describe("Clock", function() {
it("returns an id for the delayed function", function() {
var fakeSetInterval = jasmine.createSpy('setInterval'),
scheduleId = 123,
scheduleFunction = jasmine.createSpy('scheduleFunction').and.callReturn(scheduleId),
scheduleFunction = jasmine.createSpy('scheduleFunction').and.returnValue(scheduleId),
delayedFunctionScheduler = {scheduleFunction: scheduleFunction},
fakeGlobal = { setInterval: fakeSetInterval },
delayedFn = jasmine.createSpy('delayedFn'),

View File

@@ -16,7 +16,7 @@ describe("buildExpectationResult", function() {
it("delegates message formatting to the provided formatter if there was an Error", function() {
var fakeError = {message: 'foo'},
messageFormatter = jasmine.createSpy("exception message formatter").and.callReturn(fakeError.message);
messageFormatter = jasmine.createSpy("exception message formatter").and.returnValue(fakeError.message);
var result = j$.buildExpectationResult(
{
@@ -31,7 +31,7 @@ describe("buildExpectationResult", function() {
it("delegates stack formatting to the provided formatter if there was an Error", function() {
var fakeError = {stack: 'foo'},
stackFormatter = jasmine.createSpy("stack formatter").and.callReturn(fakeError.stack);
stackFormatter = jasmine.createSpy("stack formatter").and.returnValue(fakeError.stack);
var result = j$.buildExpectationResult(
{

View File

@@ -56,7 +56,7 @@ describe("Expectation", function() {
it("wraps matchers's compare functions, passing in matcher dependencies", function() {
var fakeCompare = function() { return { pass: true }; },
matcherFactory = jasmine.createSpy("matcher").and.callReturn({ compare: fakeCompare }),
matcherFactory = jasmine.createSpy("matcher").and.returnValue({ compare: fakeCompare }),
matchers = {
toFoo: matcherFactory
},
@@ -80,7 +80,7 @@ describe("Expectation", function() {
});
it("wraps matchers's compare functions, passing the actual and expected", function() {
var fakeCompare = jasmine.createSpy('fake-compare').and.callReturn({pass: true}),
var fakeCompare = jasmine.createSpy('fake-compare').and.returnValue({pass: true}),
matchers = {
toFoo: function() {
return {

View File

@@ -196,7 +196,7 @@ describe("JsApiReporter", function() {
timer: timerSpy
});
timerSpy.elapsed.and.callReturn(1000);
timerSpy.elapsed.and.returnValue(1000);
reporter.jasmineDone();
expect(reporter.executionTime()).toEqual(1000);
});

View File

@@ -22,7 +22,7 @@ describe("SpyStrategy", function() {
});
it("allows an original function to be called, passed through the params and returns it's value", function() {
var originalFn = jasmine.createSpy("original").and.callReturn(42),
var originalFn = jasmine.createSpy("original").and.returnValue(42),
spyStrategy = new j$.SpyStrategy({fn: originalFn}),
returnValue;
@@ -39,7 +39,7 @@ describe("SpyStrategy", function() {
spyStrategy = new j$.SpyStrategy({fn: originalFn}),
returnValue;
spyStrategy.callReturn(17);
spyStrategy.returnValue(17);
returnValue = spyStrategy.exec();
expect(originalFn).not.toHaveBeenCalled();
@@ -50,7 +50,7 @@ describe("SpyStrategy", function() {
var originalFn = jasmine.createSpy("original"),
spyStrategy = new j$.SpyStrategy({fn: originalFn});
spyStrategy.callThrow(new TypeError("bar"));
spyStrategy.throwError(new TypeError("bar"));
expect(function() { spyStrategy.exec(); }).toThrowError(TypeError, "bar");
expect(originalFn).not.toHaveBeenCalled();
@@ -60,7 +60,7 @@ describe("SpyStrategy", function() {
var originalFn = jasmine.createSpy("original"),
spyStrategy = new j$.SpyStrategy({fn: originalFn});
spyStrategy.callThrow("bar");
spyStrategy.throwError("bar");
expect(function() { spyStrategy.exec(); }).toThrowError(Error, "bar");
expect(originalFn).not.toHaveBeenCalled();
@@ -68,7 +68,7 @@ describe("SpyStrategy", function() {
it("allows a fake function to be called instead", function() {
var originalFn = jasmine.createSpy("original"),
fakeFn = jasmine.createSpy("fake").and.callReturn(67),
fakeFn = jasmine.createSpy("fake").and.returnValue(67),
spyStrategy = new j$.SpyStrategy({fn: originalFn}),
returnValue;
@@ -81,7 +81,7 @@ describe("SpyStrategy", function() {
it("allows a return to plan stubbing after another strategy", function() {
var originalFn = jasmine.createSpy("original"),
fakeFn = jasmine.createSpy("fake").and.callReturn(67),
fakeFn = jasmine.createSpy("fake").and.returnValue(67),
spyStrategy = new j$.SpyStrategy({fn: originalFn}),
returnValue;
@@ -99,12 +99,12 @@ describe("SpyStrategy", function() {
it("returns the spy after changing the strategy", function(){
var spy = {},
spyFn = jasmine.createSpy('spyFn').and.callReturn(spy),
spyFn = jasmine.createSpy('spyFn').and.returnValue(spy),
spyStrategy = new j$.SpyStrategy({getSpy: spyFn});
expect(spyStrategy.callThrough()).toBe(spy);
expect(spyStrategy.callReturn()).toBe(spy);
expect(spyStrategy.callThrow()).toBe(spy);
expect(spyStrategy.returnValue()).toBe(spy);
expect(spyStrategy.throwError()).toBe(spy);
expect(spyStrategy.callFake()).toBe(spy);
expect(spyStrategy.stub()).toBe(spy);
});

View File

@@ -3,10 +3,10 @@ describe("Timer", function() {
var fakeNow = jasmine.createSpy('fake Date.now'),
timer = new j$.Timer({now: fakeNow});
fakeNow.and.callReturn(100);
fakeNow.and.returnValue(100);
timer.start();
fakeNow.and.callReturn(200);
fakeNow.and.returnValue(200);
expect(timer.elapsed()).toEqual(100);
});

View File

@@ -1,7 +1,7 @@
describe("toContain", function() {
it("delegates to j$.matchersUtil.contains", function() {
var util = {
contains: jasmine.createSpy('delegated-contains').and.callReturn(true)
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
},
matcher = j$.matchers.toContain(util);
@@ -12,7 +12,7 @@ describe("toContain", function() {
it("delegates to j$.matchersUtil.contains, passing in equality testers if present", function() {
var util = {
contains: jasmine.createSpy('delegated-contains').and.callReturn(true)
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
},
customEqualityTesters = ['a', 'b'],
matcher = j$.matchers.toContain(util, customEqualityTesters);

View File

@@ -1,7 +1,7 @@
describe("toEqual", function() {
it("delegates to equals function", function() {
var util = {
equals: jasmine.createSpy('delegated-equals').and.callReturn(true)
equals: jasmine.createSpy('delegated-equals').and.returnValue(true)
},
matcher = j$.matchers.toEqual(util),
result;
@@ -14,7 +14,7 @@ describe("toEqual", function() {
it("delegates custom equality testers, if present", function() {
var util = {
equals: jasmine.createSpy('delegated-equals').and.callReturn(true)
equals: jasmine.createSpy('delegated-equals').and.returnValue(true)
},
customEqualityTesters = ['a', 'b'],
matcher = j$.matchers.toEqual(util, customEqualityTesters),

View File

@@ -1,7 +1,7 @@
describe("toHaveBeenCalledWith", function() {
it("passes when the actual was called with matching parameters", function() {
var util = {
contains: jasmine.createSpy('delegated-contains').and.callReturn(true)
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
},
matcher = j$.matchers.toHaveBeenCalledWith(util),
calledSpy = j$.createSpy('called-spy'),
@@ -16,7 +16,7 @@ describe("toHaveBeenCalledWith", function() {
it("fails when the actual was not called", function() {
var util = {
contains: jasmine.createSpy('delegated-contains').and.callReturn(false)
contains: jasmine.createSpy('delegated-contains').and.returnValue(false)
},
matcher = j$.matchers.toHaveBeenCalledWith(util),
uncalledSpy = j$.createSpy('uncalled spy'),
@@ -29,7 +29,7 @@ describe("toHaveBeenCalledWith", function() {
it("fails when the actual was called with different parameters", function() {
var util = {
contains: jasmine.createSpy('delegated-contains').and.callReturn(false)
contains: jasmine.createSpy('delegated-contains').and.returnValue(false)
},
matcher = j$.matchers.toHaveBeenCalledWith(util),
calledSpy = j$.createSpy('called spy'),

View File

@@ -144,7 +144,7 @@ describe("toThrowError", function() {
it("passes if thrown is an Error and the expected the same Error", function() {
var util = {
equals: jasmine.createSpy('delegated-equal').and.callReturn(true)
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
},
matcher = j$.matchers.toThrowError(util),
fn = function() {
@@ -160,7 +160,7 @@ describe("toThrowError", function() {
it("passes if thrown is a custom error that takes arguments and the expected is the same error", function() {
var util = {
equals: jasmine.createSpy('delegated-equal').and.callReturn(true)
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
},
matcher = j$.matchers.toThrowError(util),
CustomError = function CustomError(arg) { arg.x },
@@ -180,7 +180,7 @@ describe("toThrowError", function() {
it("fails if thrown is an Error and the expected is a different Error", function() {
var util = {
equals: jasmine.createSpy('delegated-equal').and.callReturn(false)
equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
},
matcher = j$.matchers.toThrowError(util),
fn = function() {
@@ -196,7 +196,7 @@ describe("toThrowError", function() {
it("passes if thrown is a type of Error and it is equal to the expected Error and message", function() {
var util = {
equals: jasmine.createSpy('delegated-equal').and.callReturn(true)
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
},
matcher = j$.matchers.toThrowError(util),
fn = function() {
@@ -212,7 +212,7 @@ describe("toThrowError", function() {
it("passes if thrown is a custom error that takes arguments and it is equal to the expected custom error and message", function() {
var util = {
equals: jasmine.createSpy('delegated-equal').and.callReturn(true)
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
},
matcher = j$.matchers.toThrowError(util),
CustomError = function CustomError(arg) { this.message = arg.message },
@@ -232,7 +232,7 @@ describe("toThrowError", function() {
it("fails if thrown is a type of Error and the expected is a different Error", function() {
var util = {
equals: jasmine.createSpy('delegated-equal').and.callReturn(false)
equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
},
matcher = j$.matchers.toThrowError(util),
fn = function() {
@@ -248,7 +248,7 @@ describe("toThrowError", function() {
it("passes if thrown is a type of Error and has the same type as the expected Error and the message matches the exepcted message", function() {
var util = {
equals: jasmine.createSpy('delegated-equal').and.callReturn(true)
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
},
matcher = j$.matchers.toThrowError(util),
fn = function() {
@@ -264,7 +264,7 @@ describe("toThrowError", function() {
it("fails if thrown is a type of Error and the expected is a different Error", function() {
var util = {
equals: jasmine.createSpy('delegated-equal').and.callReturn(false)
equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
},
matcher = j$.matchers.toThrowError(util),
fn = function() {

View File

@@ -22,7 +22,7 @@ describe("toThrow", function() {
it("passes if it throws but there is no expected", function() {
var util = {
equals: jasmine.createSpy('delegated-equal').and.callReturn(true)
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
},
matcher = j$.matchers.toThrow(util),
fn = function() {
@@ -50,7 +50,7 @@ describe("toThrow", function() {
it("passes if what is thrown is equivalent to what is expected", function() {
var util = {
equals: jasmine.createSpy('delegated-equal').and.callReturn(true)
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
},
matcher = j$.matchers.toThrow(util),
fn = function() {
@@ -66,7 +66,7 @@ describe("toThrow", function() {
it("fails if what is thrown is not equivalent to what is expected", function() {
var util = {
equals: jasmine.createSpy('delegated-equal').and.callReturn(false)
equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
},
matcher = j$.matchers.toThrow(util),
fn = function() {
@@ -82,7 +82,7 @@ describe("toThrow", function() {
it("fails if what is thrown is not equivalent to undefined", function() {
var util = {
equals: jasmine.createSpy('delegated-equal').and.callReturn(false)
equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
},
matcher = j$.matchers.toThrow(util),
fn = function() {

View File

@@ -148,7 +148,7 @@ describe("New HtmlReporter", function() {
reporter.jasmineStarted({});
timer.elapsed.and.callReturn(100);
timer.elapsed.and.returnValue(100);
reporter.jasmineDone();
var duration = container.querySelector(".banner .duration");

View File

@@ -21,14 +21,14 @@ getJasmineRequireObj().SpyStrategy = function() {
return getSpy();
};
this.callReturn = function(value) {
this.returnValue = function(value) {
plan = function() {
return value;
};
return getSpy();
};
this.callThrow = function(something) {
this.throwError = function(something) {
var error = (something instanceof Error) ? something : new Error(something);
plan = function() {
throw error;