Browse files

Little bit of cleanup of Smoke's namespace pollution on mocked object…

…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...
1 parent e759795 commit bf422f750fcee0c36f093c70bdfb155de833cf06 Larry Karnowski committed Jul 17, 2009
Showing with 12 additions and 12 deletions.
  1. +6 −6 lib/smoke.mock.js
  2. +6 −6 spec/mock_spec.js
View
12 lib/smoke.mock.js
@@ -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) {
@@ -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);
View
12 spec/mock_spec.js
@@ -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");

0 comments on commit bf422f7

Please sign in to comment.