0
@@ -84,7 +84,7 @@ function MockObject(master) {
0
if (typeof master == 'function') {
0
addMethods(new master);
0
- var finalizer = (master['mock']||{})
.finalize;
0
+ var finalizer = (master['mock']||{})
['finalize'] || null;
0
finalizer && finalizer(this);
0
var mock = this.mock = {expects: expector, verify: verify, testCase: null};
0
@@ -147,9 +147,10 @@ function MockObject(master) {
0
for (var ix = 0; ix < arguments.length; ix++)
0
if (expectation.arguments[ix] instanceof Mock.Callback)
0
expectation.arguments[ix].exec(arguments[ix]);
0
+ if (expectation.hasReturnValue)
0
+ return expectation.returnValue;
0
return stub.applyTo(arguments);
0
- return expectation.value;
0
expector[name] = function() {
0
Mock['trace'] && Debug.write('expect', name, arguments);
0
@@ -157,7 +158,8 @@ function MockObject(master) {
0
arguments: Array.slice(arguments, 0),
0
+ hasReturnValue: false,
0
+ returnValue: undefined
0
expectations.push(expectation);
0
@@ -165,27 +167,38 @@ function MockObject(master) {
0
define('calls', calls),
0
define('returns', returns);
0
define.alias('calls.back', 'calls');
0
+ define('captures.callback', function(pos) {
0
+ if (arguments.length < 1)
0
+ pos = findFirstFunction();
0
+ var cb = expectation.arguments[pos] = Mock.callback(undefined);
0
+ cb.exec = function(fn) { this.fn = fn }
0
+ cb.call = function(values) { this.fn.apply(undefined, arguments) }
0
define.modifier.dictionary(options);
0
define.modifier('eventually');
0
+ function findFirstFunction() {
0
+ var args = expectation.arguments,
0
+ for (var i = 0; i < len; i++)
0
+ if (args[i] == Function)
0
+ Debug.error('no function position');
0
function calls(pos, value) {
0
if (arguments.length < 2) {
0
- var args = expectation.arguments,
0
- for (var i = 0; i < len; i++)
0
- if (args[i] == Function) {
0
+ pos = findFirstFunction();
0
var cb = expectation.arguments[pos] = Mock.callback(value);
0
cb.async = options.eventually;
0
function returns(value) {
0
- expectation.value = value;
0
+ expectation.hasReturnValue = true;
0
+ expectation.returnValue = value;
Comments
No one has commented yet.