Skip to content

Commit

Permalink
mock expectations are now run recursively to avoid looping through ea…
Browse files Browse the repository at this point in the history
…ch one every call.
  • Loading branch information
andykent committed May 16, 2008
1 parent dfcc9a7 commit f4ac38c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 3 additions & 6 deletions lib/smoke.mock.js
Expand Up @@ -33,15 +33,12 @@ Smoke.Mock = function(originalObj) {
var expectation = new Smoke.Mock.Expectation(this, attr);
if(this._expectations[attr]==undefined) this._expectations[attr] = [];
this._expectations[attr].push(expectation);
var e = this._expectations[attr]; // closure var
var previousFunction = this[attr];
var mock = this;
this[attr] = function() {
for(var i in e) {
var result = e[i].run(arguments);
if(result!=undefined) return result;
};
return previousFunction ? previousFunction.call(mock) : undefined;
var result = expectation.run(arguments);
if(result!=undefined) return result;
return previousFunction!=undefined ? previousFunction.apply(mock,arguments) : undefined;
};
return expectation;
},
Expand Down
2 changes: 1 addition & 1 deletion spec/mock_spec.js
Expand Up @@ -49,8 +49,8 @@ Screw.Unit(function() {
mockObj = mock()
mockObj.should_receive('foo').with_arguments('bar').and_return('foobar');
mockObj.should_receive('foo').with_arguments('mouse').and_return('cheese');
expect(mockObj.foo('bar')).to(equal, 'foobar');
expect(mockObj.foo('mouse')).to(equal, 'cheese');
expect(mockObj.foo('bar')).to(equal, 'foobar');
});
it("should allow mocking a method signature with arguments and setting expectations", function() {
mockObj = mock()
Expand Down

0 comments on commit f4ac38c

Please sign in to comment.