Skip to content

Commit

Permalink
Little bit of cleanup of Smoke's namespace pollution on mocked object…
Browse files Browse the repository at this point in the history
…s by prefixing Smoke-internal functions with an underscore.

(Might want to put these under a "_smoke" data structure in the future?)
  • Loading branch information
Larry Karnowski committed Jul 17, 2009
1 parent e759795 commit bf422f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions lib/smoke.mock.js
Expand Up @@ -11,15 +11,15 @@ Smoke.failed = function(mock, message){
// Some helpers
Smoke.reset = function(){
Smoke.mocks = Smoke.mocks || [];
for(var i=0; i<Smoke.mocks.length; i++) Smoke.mocks[i].resetMocks();
for(var i=0; i<Smoke.mocks.length; i++) Smoke.mocks[i]._resetMocks();
Smoke.mocks = [];
Smoke.passCount = 0;
Smoke.failCount = 0;
};
Smoke.reset();

Smoke.checkExpectations = function(){
for(var i=0; i<Smoke.mocks.length; i++) Smoke.mocks[i].checkExpectations();
for(var i=0; i<Smoke.mocks.length; i++) Smoke.mocks[i]._checkExpectations();
};

Smoke.Mock = function(originalObj) {
Expand All @@ -41,24 +41,24 @@ Smoke.Mock = function(originalObj) {
return expectation;
};

obj.checkExpectations = function(){
obj._checkExpectations = function(){
for(var e in this._expectations) {
var expectations = this._expectations[e]
for(var i=0; i < expectations.length; i++) expectations[i].check();
};
};

obj.resetMocks = function(){
obj._resetMocks = function(){
for(var attr in this._valuesBeforeMocking) {
this[attr] = this._valuesBeforeMocking[attr];
}

delete this._valuesBeforeMocking;
delete this._expectations;
delete this._resetMocks;
delete this._checkExpectations;
delete this.stub;
delete this.should_receive;
delete this.checkExpectations;
delete this.resetMocks;
};

Smoke.mocks.push(obj);
Expand Down
12 changes: 6 additions & 6 deletions spec/mock_spec.js
Expand Up @@ -150,26 +150,26 @@ Screw.Unit(function() {
expect(obj._expectations).to_not(equal, null);
expect(obj.stub).to_not(equal, null);
expect(obj.should_receive).to_not(equal, null);
expect(obj.checkExpectations).to_not(equal, null);
expect(obj.resetMocks).to_not(equal, null);
expect(obj._checkExpectations).to_not(equal, null);
expect(obj._resetMocks).to_not(equal, null);

obj.resetMocks();
obj._resetMocks();
Smoke.mocks = [];

expect(obj._valuesBeforeMocking).to(equal, null);
expect(obj._expectations).to(equal, null);
expect(obj.stub).to(equal, null);
expect(obj.should_receive).to(equal, null);
expect(obj.checkExpectations).to(equal, null);
expect(obj.resetMocks).to(equal, null);
expect(obj._checkExpectations).to(equal, null);
expect(obj._resetMocks).to(equal, null);
});

it("should replace the original functionality to the object", function(){
var obj = { say: "hello", shout: function() { return this.say.toUpperCase(); } };
mock(obj).should_receive("shout").and_return("some string");
expect(obj.shout()).to(equal, "some string");

obj.resetMocks();
obj._resetMocks();
Smoke.mocks = [];

expect(obj.shout()).to(equal, "HELLO");
Expand Down

0 comments on commit bf422f7

Please sign in to comment.