Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

bit of a change so that multiple expectations on an object can be loo…

…ped through
  • Loading branch information...
commit 21fdfbc648b7b65c6c6f16fc1128eeaa0a48b132 1 parent 475aaab
@andykent andykent authored
Showing with 10 additions and 4 deletions.
  1. +10 −4 lib/smoke.mock.js
View
14 lib/smoke.mock.js
@@ -34,10 +34,15 @@ Smoke.Mock = function(originalObj) {
this._expectations[attr].push(expectation);
var previousFunction = this[attr];
var mock = this;
+ if(this._expectations[attr].length>1) return expectation;
this[attr] = function() {
- var expectationResult = expectation.run(arguments);
- functionResult = previousFunction!=undefined ? previousFunction.apply(mock,arguments) : undefined;
- return expectation.hasReturnValue ? expectationResult : functionResult
+ for(var i=0; i<mock._expectations[attr].length; i++) {
+ var expectation = mock._expectations[attr][i];
+ var ran = expectation.run(arguments);
+ var functionResult = previousFunction!=undefined ? previousFunction.apply(mock,arguments) : undefined;
+ if(ran && expectation.hasReturnValue) return expectation.returnValue;
+ };
+ return functionResult
};
return expectation;
};
@@ -95,8 +100,9 @@ Smoke.Mock.Expectation.prototype = {
run: function(args){
if(typeof(this.callerArgs) == 'undefined' || this.compareArrays(args, this.callerArgs)) {
this.callCount+=1;
- return this.returnValue;
+ return true;
};
+ return false
},
and_return: function(v){
this.hasReturnValue = true;
Please sign in to comment.
Something went wrong with that request. Please try again.