Skip to content

Commit

Permalink
reorganize
Browse files Browse the repository at this point in the history
  • Loading branch information
vilmibm committed Aug 31, 2012
1 parent 561437a commit 06dca7f
Showing 1 changed file with 20 additions and 26 deletions.
46 changes: 20 additions & 26 deletions lib/faux.js
@@ -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) {
Expand All @@ -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 = [];
Expand All @@ -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.