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,4 +1,4 @@
getJasmineRequireObj().StringPrettyPrinter = function(j$) {
getJasmineRequireObj().pp = function(j$) {
function PrettyPrinter() {
this.ppNestLevel_ = 0;
@@ -18,7 +18,7 @@ getJasmineRequireObj().StringPrettyPrinter = function(j$) {
} else if (typeof value === 'string') {
this.emitString(value);
} else if (j$.isSpy(value)) {
this.emitScalar("spy on " + value.identity);
this.emitScalar("spy on " + value.and.identity());
} else if (value instanceof RegExp) {
this.emitScalar(value.toString());
} else if (typeof value === 'function') {
@@ -50,7 +50,7 @@ getJasmineRequireObj().StringPrettyPrinter = function(j$) {
if (!obj.hasOwnProperty(property)) continue;
if (property == '__Jasmine_been_here_before__') continue;
fn(property, obj.__lookupGetter__ ? (!j$.util.isUndefined(obj.__lookupGetter__(property)) &&
obj.__lookupGetter__(property) !== null) : false);
obj.__lookupGetter__(property) !== null) : false);
}
};
@@ -64,6 +64,7 @@ getJasmineRequireObj().StringPrettyPrinter = function(j$) {
this.string = '';
}
j$.util.inherit(StringPrettyPrinter, PrettyPrinter);
StringPrettyPrinter.prototype.emitScalar = function(value) {
@@ -123,5 +124,9 @@ getJasmineRequireObj().StringPrettyPrinter = function(j$) {
this.string += value;
};
return StringPrettyPrinter;
return function(value) {
var stringPrettyPrinter = new StringPrettyPrinter();
stringPrettyPrinter.format(value);
return stringPrettyPrinter.string;
};
};