Permalink
Browse files

package.json, license, Mock()

  • Loading branch information...
1 parent d27a20e commit 16c40d6f581c215b7b6c29064885748716d2ad85 @vilmibm committed Aug 31, 2012
Showing with 61 additions and 1 deletion.
  1. +18 −0 LICENSE
  2. +22 −1 lib/faux.js
  3. +21 −0 package.json
View
18 LICENSE
@@ -0,0 +1,18 @@
+Copyright (c) 2012, nathaniel k smith
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
@@ -8,7 +8,27 @@ var create_nested_mock = function(obj, props) {
}
help(obj, props);
return obj;
-}
+};
+
+var Mock = function(spec) {
+ spec || (spec = {});
+ var apply = function(s, o) {
+ Object.keys(o).forEach(function(k) {
+ var thing = o[k];
+ if (typeof thing === 'object') {
+ s[k] = {};
+ apply(s[k], thing);
+ }
+ else if (typeof thing === 'function') {
+ s[k] = new MockFunction(thing).wrapped;
+ }
+ else {
+ s[k] = thing;
+ }
+ });
+ }
+ apply(this, spec);
+};
var MockFunction = function(f) {
this.f = (f || noop);
@@ -35,6 +55,7 @@ var noop = function() {};
module.exports = {
create_nested_mock: create_nested_mock,
+ Mock: Mock,
MockFunction: MockFunction,
noop: noop
};
View
@@ -0,0 +1,21 @@
+{
+ "name": "faux",
+ "version": "0.1.0",
+ "author": "nathaniel k smith <nathanielksmith@gmail.com>",
+ "description": "a mocking utility library",
+ "main": "./lib/faux",
+ "repository":{
+ "type":"git",
+ "url":"https://github.com/nathanielksmith/faux.git"
+ },
+ "keywords": [
+ "mock",
+ "testing"
+ ],
+ "dependencies": {
+ },
+ "license": "BSD",
+ "engines": {
+ "node": ">=0.8"
+ }
+}

0 comments on commit 16c40d6

Please sign in to comment.