Permalink
Browse files

reorganize

  • Loading branch information...
1 parent 561437a commit 06dca7fb8f10230ee53451e05dccd46f3b6c5df8 @vilmibm committed Aug 31, 2012
Showing with 20 additions and 26 deletions.
  1. +20 −26 lib/faux.js
View
@@ -1,16 +1,5 @@
-var create_nested_mock = function(obj, props) {
- var help = function(o, ps) {
- if (ps.length === 0) { return }
- else {
- o[ps[0]] = {};
- help(o[ps[0]], ps.slice(1));
- }
- }
- help(obj, props);
- return obj;
-};
-
var Mock = function(spec) {
+ // TODO support constructor
spec || (spec = {});
var apply = function(s, o) {
Object.keys(o).forEach(function(k) {
@@ -20,18 +9,28 @@ var Mock = function(spec) {
apply(s[k], thing);
}
else if (typeof thing === 'function') {
- s[k] = new MockFunction(thing).wrapped;
- }
- else {
- s[k] = thing;
+ s[k] = new Mock.MockFunction().wrapped;
}
+ else { s[k] = thing; }
});
- }
+ };
apply(this, spec);
};
-var MockFunction = function(f) {
- this.f = (f || noop);
+Mock.create_nested_mock = function(obj, props) {
+ var help = function(o, ps) {
+ if (ps.length === 0) { return }
+ else {
+ o[ps[0]] = {};
+ help(o[ps[0]], ps.slice(1));
+ }
+ }
+ help(obj, props);
+ return obj;
+};
+
+Mock.MockFunction = function(f) {
+ this.f = (f || Mock.noop);
this.called = false;
this.calls = 0;
this.args = [];
@@ -51,11 +50,6 @@ var MockFunction = function(f) {
});
};
-var noop = function() {};
+Mock.noop = function() {};
-module.exports = {
- create_nested_mock: create_nested_mock,
- Mock: Mock,
- MockFunction: MockFunction,
- noop: noop
-};
+module.exports = { Mock: Mock };

0 comments on commit 06dca7f

Please sign in to comment.