Permalink
Browse files

mocks are now destructive as this is the behaviour most other libs use

  • Loading branch information...
1 parent 1b5053e commit 99292588441142a1e370cc5e46ebe09c767c4ec4 @andykent andykent committed May 20, 2009
Showing with 6 additions and 21 deletions.
  1. +3 −3 lib/smoke.mock.js
  2. +3 −18 spec/mock_spec.js
View
6 lib/smoke.mock.js
@@ -36,13 +36,13 @@ Smoke.Mock = function(originalObj) {
var mock = this;
if(this._expectations[attr].length>1) return expectation;
this[attr] = function() {
+ var ret = undefined;
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;
+ if(ran && expectation.hasReturnValue) ret = expectation.returnValue;
};
- return functionResult
+ return ret;
};
return expectation;
};
View
21 spec/mock_spec.js
@@ -58,12 +58,6 @@ Screw.Unit(function() {
m.bar();
});
- it("should allow stubbing on mocks", function() {
- var m = mock({foo: function() { throw('I should not have been called!')}});
- m.should_receive('foo').stub.and_return('hello');
- m.foo();
- });
-
it("should allow return values directly from mocks",function() {
var m = mock()
m.should_receive('bar').exactly('once').and_return('hello');
@@ -128,10 +122,10 @@ Screw.Unit(function() {
expect(mockObj.length).to(equal,4);
});
- it("should place expectations on existing methods non-destructively", function() {
- myMock = mock({ say: "hello", shout: function() { return this.say.toUpperCase(); } });
+ it("should place expectations on existing methods destructively", function() {
+ myMock = mock({ say: "hello", shout: function() { throw "FAIL!" } });
myMock.should_receive('shout').exactly('once');
- expect(myMock.shout()).to(equal,'HELLO');
+ myMock.shout()
});
});
@@ -171,15 +165,6 @@ Screw.Unit(function() {
mockObj('a');
});
- it("should call the original even if a return value is specified", function() {
- var a = false
- var func = function() { a = true };
- var mockFunc = mock_function(func);
- mockFunc.should_be_invoked().and_return('hello');
- expect(mockFunc()).to(equal, 'hello');
- expect(a).to(equal, true);
- });
-
it("allows passing in a name for the function as a second argument to make error messages clearer", function() {
mock_function(foo, 'foo').should_be_invoked().exactly('once');
try {

0 comments on commit 9929258

Please sign in to comment.