{"_id":"mocks","_rev":"48-58c788084effc3d2b4f826de091639dd","name":"mocks","description":"Set of mock modules for easy testing (fs, http)","dist-tags":{"latest":"0.0.15"},"versions":{"0.0.1":{"name":"mocks","description":"Set of mock modules for easy testing (fs, http)","homepage":"","keywords":["mock","stub","dummy","test double","fake","nodejs","js","testing","test","fs","fs mock","http","http mock"],"author":{"name":"Vojta Jína","email":"vojta.jina@gmail.com"},"contributors":[],"dependencies":{},"devDependencies":{"coffee-script":"1.1.2","jasmine-node":"1.0.11","jake":"0.2.15"},"repository":{"type":"git","url":"git://github.com/vojtajina/node-mocks.git"},"main":"./lib/index","bin":{},"engines":{"node":">= 0.6.5"},"version":"0.0.1","_npmUser":{"name":"vojtajina","email":"vojta.jina@gmail.com"},"_id":"mocks@0.0.1","optionalDependencies":{},"_engineSupported":true,"_npmVersion":"1.1.0-3","_nodeVersion":"v0.6.10","_defaultsLoaded":true,"dist":{"shasum":"76063048d182cbf2e672175326d063f357039c92","tarball":"https://registry.npmjs.org/mocks/-/mocks-0.0.1.tgz","integrity":"sha512-x5uVhjlR+EvdZHZViB9a97OyAWrREW4gLjw1bjojMWJyb9q1dDdoqz71HcLXRQh3vUu4BJCFAK/lxFPKA5dsRA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDhog8XtQa7Cy9/K4ut5ibhLSzxy/5y0WMSA1mb0c7+oQIgWCTnPlpVADEi223ku2N2kODgFJKigYkBwFxN+qG4htk="}]},"readme":"","maintainers":[{"name":"vojtajina","email":"vojta.jina@gmail.com"}],"directories":{}},"0.0.2":{"name":"mocks","description":"Set of mock modules for easy testing (fs, http)","homepage":"","keywords":["mock","stub","dummy","test double","fake","nodejs","js","testing","test","fs","fs mock","http","http mock"],"author":{"name":"Vojta Jína","email":"vojta.jina@gmail.com"},"contributors":[],"dependencies":{},"devDependencies":{"coffee-script":"1.1.2","jasmine-node":"1.0.11","jake":"0.2.15"},"repository":{"type":"git","url":"git://github.com/vojtajina/node-mocks.git"},"main":"./lib/index","bin":{},"engines":{"node":">= 0.6.5"},"version":"0.0.2","_npmUser":{"name":"vojtajina","email":"vojta.jina@gmail.com"},"_id":"mocks@0.0.2","optionalDependencies":{},"_engineSupported":true,"_npmVersion":"1.1.4","_nodeVersion":"v0.6.10","_defaultsLoaded":true,"dist":{"shasum":"29fc48e495338c217d93b9f8c985162a79270efc","tarball":"https://registry.npmjs.org/mocks/-/mocks-0.0.2.tgz","integrity":"sha512-ESENYZiM0smQhKUPmUfmcxTU5kz9BWwGGidb4y+siu1JHBTYHisSIWzg3FYgKEq6fFwstHt0zTXvY+nvCxEdVQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD5wjNiZwYa0k63dGstAldqrB3/9lB6wQnoL+4jvYyMOgIgTcuAdgtzrJbOgGxiAAEBJC4mOLxY9tI2p2UjrhhSJiY="}]},"readme":"# Node Mocks\n\nSet of mocks and utilities for easier unit testing with [Node.js].\n\nSee http://howtonode.org/testing-private-state-and-mocking-deps for better explanation.\n\n## Prerequisites\n\n* [Node.js]\n* [NPM] (shipped with Node since 0.6.3)\n\n\n## Installation\n\n    sudo npm install -g mocks\n\n    # or install in local folder\n    npm install mocks\n\n\n## Example\n\n### Mocking a file system\n\n````javascript\n// during unit test - we inject mock file system instead of real fs\nvar fs = require('fs');\n\n// even if this function is not public, we can test it directly\nvar filterOnlyExistingFiles = function(collection, done) {\n  var filtered = [],\n      waiting = 0;\n\n  collection.forEach(function(file) {\n    waiting++;\n    fs.stat(file, function(err, stat) {\n      if (!err && stat.isFile()) filtered.push(file);\n      waiting--;\n      if (!waiting) done(null, filtered);\n    });\n  });\n};\n````\n\n````coffeescript\n# simple unit test (jasmine syntax, coffescript)\ndescribe 'app', ->\n  mocks = require 'mocks'\n  loadFile = mocks.loadFile\n  app = done = null\n\n  beforeEach ->\n    done = jasmine.createSpy 'done'\n    # load the file and inject fake fs module\n    app = loadFile __dirname + '/app.js',\n      fs: mocks.fs.create\n        'bin':\n          'run.sh': 1,\n          'install.sh': 1\n        'home':\n          'some.js': 1,\n          'another.txt': 1\n        'one.js': 1,\n        'two.js': 1,\n        'three.js': 1\n\n\n  it 'should return only existing files', ->\n    done.andCallFake (err, filtered) ->\n      expect(err).toBeFalsy()\n      expect(filtered).toEqual ['/bin/run.sh']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/non.txt'], done\n    waitsFor -> done.callCount\n\n  it 'should ignore directories', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/bin/run.sh', '/home/some.js']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/home', '/home/some.js'], done\n    waitsFor -> done.callCount\n````\n\n### Faking randomness\nNon-blocking I/O operations can return in random order. Let's say you read a content of two files (asynchronously). There is no guarantee, that you get the content in right order. That's fine, but we want to test our code, whether it can handle such a situation and still work properly. In that case, you can use `predictableNextTick`, which process callbacks depending on given pattern.\n\n````coffeescript\n\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nThis test will always pass. That's cool, as we like to see tests passing. The bad thing is, that it does not work in production, with real file system, as it might return in different order...\nSo, we need to test, whether our app works even when the `fs` returns in random order. Having randomness in unit tests is not good habit, as it leads to flaky tests.\nLet's change the previous unit test to this:\n\n````coffeescript\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    mocks.predictableNextTick.pattern = [2, 0, 1]\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nNow, the unit test fails, because our fake file system calls back in different order. Note, it's not random, as you explicitly specified the pattern (2, 0, 1), so it the fake fs will consistently call back in this order: /three.js, /one.js, two.js.\n\n\n## API\nCurrently supported API is only very small part of real [Node's API]. Basically I only implemented methods I need for testing [SlimJim].\n\nI will keep adding more and of course if anyone wants to help - pull requests are more than welcomed.\n\n### fs\n\n- stat(path, callback)\n- readdir(path, callback)\n- readFile(path [, encoding], callback)\n- readFileSync(path)\n- watchFile(path [, options], callback)\n- _touchFile(path, mtime, content) *\n\n### http\n\n- http.ServerResponse\n- http.ServerRequest\n\n\n### loadFile(path [, mocks] [, globals])\n### predictableNextTick(fn)\n### predictableNextTick.pattern\n\n[Node.js]: http://nodejs.org/\n[NPM]: http://npmjs.org/\n[Node's API]: http://nodejs.org/docs/latest/api/index.html\n[SlimJim]: https://github.com/vojtajina/slim-jim\n","maintainers":[{"name":"vojtajina","email":"vojta.jina@gmail.com"}],"directories":{}},"0.0.3":{"name":"mocks","description":"Set of mock modules for easy testing (fs, http)","homepage":"","keywords":["mock","stub","dummy","test double","fake","nodejs","js","testing","test","fs","fs mock","http","http mock"],"author":{"name":"Vojta Jína","email":"vojta.jina@gmail.com"},"contributors":[],"dependencies":{},"devDependencies":{"coffee-script":"1.1.2","jasmine-node":"1.0.11","jake":"0.2.15"},"repository":{"type":"git","url":"git://github.com/vojtajina/node-mocks.git"},"main":"./lib/index","bin":{},"engines":{"node":">= 0.6.5"},"version":"0.0.3","_npmUser":{"name":"vojtajina","email":"vojta.jina@gmail.com"},"_id":"mocks@0.0.3","optionalDependencies":{},"_engineSupported":true,"_npmVersion":"1.1.4","_nodeVersion":"v0.6.10","_defaultsLoaded":true,"dist":{"shasum":"c2eb04d642c97ef85b367c3a5b93eb9ec9e3f255","tarball":"https://registry.npmjs.org/mocks/-/mocks-0.0.3.tgz","integrity":"sha512-jFo34ABzlIxd+1+4PeiTV9OEwcLHS7LB6qK6i8UQM88WPYD1UkWlmkCBdbCptQf+tPkgS4ec3Hd8vt3Nschdfw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC+oYSSby8Ta2yIvFvssFQcoDw5IB8mXysNjb7I6O8xwwIgNpsrw6RVNWOdvHuV82A3zr4gKa3FCw/WdzO9QoURHzo="}]},"readme":"# Node Mocks [![Build Status](https://secure.travis-ci.org/vojtajina/node-mocks.png?branch=master)](http://travis-ci.org/vojtajina/node-mocks)\n\nSet of mocks and utilities for easier unit testing with [Node.js].\n\nSee http://howtonode.org/testing-private-state-and-mocking-deps for better explanation.\n\n## Prerequisites\n\n* [Node.js]\n* [NPM] (shipped with Node since 0.6.3)\n\n\n## Installation\n\n    sudo npm install -g mocks\n\n    # or install in local folder\n    npm install mocks\n\n\n## Example\n\n### Mocking a file system\n\n````javascript\n// during unit test - we inject mock file system instead of real fs\nvar fs = require('fs');\n\n// even if this function is not public, we can test it directly\nvar filterOnlyExistingFiles = function(collection, done) {\n  var filtered = [],\n      waiting = 0;\n\n  collection.forEach(function(file) {\n    waiting++;\n    fs.stat(file, function(err, stat) {\n      if (!err && stat.isFile()) filtered.push(file);\n      waiting--;\n      if (!waiting) done(null, filtered);\n    });\n  });\n};\n````\n\n````coffeescript\n# simple unit test (jasmine syntax, coffescript)\ndescribe 'app', ->\n  mocks = require 'mocks'\n  loadFile = mocks.loadFile\n  app = done = null\n\n  beforeEach ->\n    done = jasmine.createSpy 'done'\n    # load the file and inject fake fs module\n    app = loadFile __dirname + '/app.js',\n      fs: mocks.fs.create\n        'bin':\n          'run.sh': 1,\n          'install.sh': 1\n        'home':\n          'some.js': 1,\n          'another.txt': 1\n        'one.js': 1,\n        'two.js': 1,\n        'three.js': 1\n\n\n  it 'should return only existing files', ->\n    done.andCallFake (err, filtered) ->\n      expect(err).toBeFalsy()\n      expect(filtered).toEqual ['/bin/run.sh']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/non.txt'], done\n    waitsFor -> done.callCount\n\n  it 'should ignore directories', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/bin/run.sh', '/home/some.js']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/home', '/home/some.js'], done\n    waitsFor -> done.callCount\n````\n\n### Faking randomness\nNon-blocking I/O operations can return in random order. Let's say you read a content of two files (asynchronously). There is no guarantee, that you get the content in right order. That's fine, but we want to test our code, whether it can handle such a situation and still work properly. In that case, you can use `predictableNextTick`, which process callbacks depending on given pattern.\n\n````coffeescript\n\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nThis test will always pass. That's cool, as we like to see tests passing. The bad thing is, that it does not work in production, with real file system, as it might return in different order...\nSo, we need to test, whether our app works even when the `fs` returns in random order. Having randomness in unit tests is not good habit, as it leads to flaky tests.\nLet's change the previous unit test to this:\n\n````coffeescript\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    mocks.predictableNextTick.pattern = [2, 0, 1]\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nNow, the unit test fails, because our fake file system calls back in different order. Note, it's not random, as you explicitly specified the pattern (2, 0, 1), so it the fake fs will consistently call back in this order: /three.js, /one.js, two.js.\n\n\n## API\nCurrently supported API is only very small part of real [Node's API]. Basically I only implemented methods I need for testing [Testacular].\n\nI will keep adding more and of course if anyone wants to help - pull requests are more than welcomed.\n\n### fs\n\n- stat(path, callback)\n- readdir(path, callback)\n- readFile(path [, encoding], callback)\n- readFileSync(path)\n- watchFile(path [, options], callback)\n- _touchFile(path, mtime, content) *\n\n### http\n\n- http.ServerResponse\n- http.ServerRequest\n\n\n### loadFile(path [, mocks] [, globals])\n### predictableNextTick(fn)\n### predictableNextTick.pattern\n\n[Node.js]: http://nodejs.org/\n[NPM]: http://npmjs.org/\n[Node's API]: http://nodejs.org/docs/latest/api/index.html\n[Testacular]: https://github.com/vojtajina/testacular\n","maintainers":[{"name":"vojtajina","email":"vojta.jina@gmail.com"}],"directories":{}},"0.0.4":{"name":"mocks","description":"Set of mock modules for easy testing (fs, http)","homepage":"","keywords":["mock","stub","dummy","test double","fake","nodejs","js","testing","test","fs","fs mock","http","http mock"],"author":{"name":"Vojta Jína","email":"vojta.jina@gmail.com"},"contributors":[],"dependencies":{},"devDependencies":{"coffee-script":"1.1.2","jasmine-node":"1.0.11","jake":"0.2.15"},"repository":{"type":"git","url":"git://github.com/vojtajina/node-mocks.git"},"main":"./lib/index","bin":{},"engines":{"node":">= 0.6.5"},"version":"0.0.4","_npmUser":{"name":"vojtajina","email":"vojta.jina@gmail.com"},"_id":"mocks@0.0.4","optionalDependencies":{},"_engineSupported":true,"_npmVersion":"1.1.21","_nodeVersion":"v0.6.18","_defaultsLoaded":true,"dist":{"shasum":"b3b759c7431d5c5513ababb5931e2b97fc0aa341","tarball":"https://registry.npmjs.org/mocks/-/mocks-0.0.4.tgz","integrity":"sha512-++F/RQBvIlaBeRbFlBmqY1iRxwTNto+g/kB5bRGDOjCEmSlaQlq5gSq5geebGdwwYhx3BHIjEDBkwX2A3eIhIQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHA4P+OIIVrJLqIZeeUQ3XiX2L4tpj9BzWVcXXwdlNtrAiAMOJpP7grJQla0Ud0g0VhshrJdWcrluInqomEP8jzWQA=="}]},"readme":"# Node Mocks [![Build Status](https://secure.travis-ci.org/vojtajina/node-mocks.png?branch=master)](http://travis-ci.org/vojtajina/node-mocks)\n\nSet of mocks and utilities for easier unit testing with [Node.js].\n\nSee http://howtonode.org/testing-private-state-and-mocking-deps for better explanation.\n\n## Prerequisites\n\n* [Node.js]\n* [NPM] (shipped with Node since 0.6.3)\n\n\n## Installation\n\n    sudo npm install -g mocks\n\n    # or install in local folder\n    npm install mocks\n\n\n## Example\n\n### Mocking a file system\n\n````javascript\n// during unit test - we inject mock file system instead of real fs\nvar fs = require('fs');\n\n// even if this function is not public, we can test it directly\nvar filterOnlyExistingFiles = function(collection, done) {\n  var filtered = [],\n      waiting = 0;\n\n  collection.forEach(function(file) {\n    waiting++;\n    fs.stat(file, function(err, stat) {\n      if (!err && stat.isFile()) filtered.push(file);\n      waiting--;\n      if (!waiting) done(null, filtered);\n    });\n  });\n};\n````\n\n````coffeescript\n# simple unit test (jasmine syntax, coffescript)\ndescribe 'app', ->\n  mocks = require 'mocks'\n  loadFile = mocks.loadFile\n  app = done = null\n\n  beforeEach ->\n    done = jasmine.createSpy 'done'\n    # load the file and inject fake fs module\n    app = loadFile __dirname + '/app.js',\n      fs: mocks.fs.create\n        'bin':\n          'run.sh': 1,\n          'install.sh': 1\n        'home':\n          'some.js': 1,\n          'another.txt': 1\n        'one.js': 1,\n        'two.js': 1,\n        'three.js': 1\n\n\n  it 'should return only existing files', ->\n    done.andCallFake (err, filtered) ->\n      expect(err).toBeFalsy()\n      expect(filtered).toEqual ['/bin/run.sh']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/non.txt'], done\n    waitsFor -> done.callCount\n\n  it 'should ignore directories', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/bin/run.sh', '/home/some.js']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/home', '/home/some.js'], done\n    waitsFor -> done.callCount\n````\n\n### Faking randomness\nNon-blocking I/O operations can return in random order. Let's say you read a content of two files (asynchronously). There is no guarantee, that you get the content in right order. That's fine, but we want to test our code, whether it can handle such a situation and still work properly. In that case, you can use `predictableNextTick`, which process callbacks depending on given pattern.\n\n````coffeescript\n\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nThis test will always pass. That's cool, as we like to see tests passing. The bad thing is, that it does not work in production, with real file system, as it might return in different order...\nSo, we need to test, whether our app works even when the `fs` returns in random order. Having randomness in unit tests is not good habit, as it leads to flaky tests.\nLet's change the previous unit test to this:\n\n````coffeescript\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    mocks.predictableNextTick.pattern = [2, 0, 1]\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nNow, the unit test fails, because our fake file system calls back in different order. Note, it's not random, as you explicitly specified the pattern (2, 0, 1), so it the fake fs will consistently call back in this order: /three.js, /one.js, two.js.\n\n\n## API\nCurrently supported API is only very small part of real [Node's API]. Basically I only implemented methods I need for testing [Testacular].\n\nI will keep adding more and of course if anyone wants to help - pull requests are more than welcomed.\n\n### fs\n\n- stat(path, callback)\n- readdir(path, callback)\n- readFile(path [, encoding], callback)\n- readFileSync(path)\n- watchFile(path [, options], callback)\n- _touchFile(path, mtime, content) *\n\n### http\n\n- http.ServerResponse\n- http.ServerRequest\n\n\n### loadFile(path [, mocks] [, globals])\n### predictableNextTick(fn)\n### predictableNextTick.pattern\n\n[Node.js]: http://nodejs.org/\n[NPM]: http://npmjs.org/\n[Node's API]: http://nodejs.org/docs/latest/api/index.html\n[Testacular]: https://github.com/vojtajina/testacular\n","maintainers":[{"name":"vojtajina","email":"vojta.jina@gmail.com"}],"directories":{}},"0.0.5":{"name":"mocks","description":"Set of mock modules for easy testing (fs, http)","homepage":"","keywords":["mock","stub","dummy","test double","fake","nodejs","js","testing","test","fs","fs mock","http","http mock"],"author":{"name":"Vojta Jína","email":"vojta.jina@gmail.com"},"contributors":[],"dependencies":{},"devDependencies":{"coffee-script":"1.1.2","jasmine-node":"1.0.11","jake":"0.2.15"},"repository":{"type":"git","url":"git://github.com/vojtajina/node-mocks.git"},"main":"./lib/index","bin":{},"engines":{"node":">= 0.6.5"},"version":"0.0.5","_npmUser":{"name":"vojtajina","email":"vojta.jina@gmail.com"},"_id":"mocks@0.0.5","optionalDependencies":{},"_engineSupported":true,"_npmVersion":"1.1.21","_nodeVersion":"v0.6.18","_defaultsLoaded":true,"dist":{"shasum":"235755ec5290e533d6eaae62fb71f91e6e506c94","tarball":"https://registry.npmjs.org/mocks/-/mocks-0.0.5.tgz","integrity":"sha512-sTtahcpGwm6iZkGL5CLmg4amu/tW25d0I2z28CZSz2+uj0iUG7+8lCn2ynKOwb6S1pMkxB/FUA/TRHsLbrcJkw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC5xSQIFlfgxSujFzlHzSvijQUXqMxgJc7RBxBa9HTRGwIgKYDFLI+RO/AXMKG/1wV9/l5iLXrYRmhPq4ozG3PKX0k="}]},"readme":"# Node Mocks [![Build Status](https://secure.travis-ci.org/vojtajina/node-mocks.png?branch=master)](http://travis-ci.org/vojtajina/node-mocks)\n\nSet of mocks and utilities for easier unit testing with [Node.js].\n\nSee http://howtonode.org/testing-private-state-and-mocking-deps for better explanation.\n\n## Prerequisites\n\n* [Node.js]\n* [NPM] (shipped with Node since 0.6.3)\n\n\n## Installation\n\n    sudo npm install -g mocks\n\n    # or install in local folder\n    npm install mocks\n\n\n## Example\n\n### Mocking a file system\n\n````javascript\n// during unit test - we inject mock file system instead of real fs\nvar fs = require('fs');\n\n// even if this function is not public, we can test it directly\nvar filterOnlyExistingFiles = function(collection, done) {\n  var filtered = [],\n      waiting = 0;\n\n  collection.forEach(function(file) {\n    waiting++;\n    fs.stat(file, function(err, stat) {\n      if (!err && stat.isFile()) filtered.push(file);\n      waiting--;\n      if (!waiting) done(null, filtered);\n    });\n  });\n};\n````\n\n````coffeescript\n# simple unit test (jasmine syntax, coffescript)\ndescribe 'app', ->\n  mocks = require 'mocks'\n  loadFile = mocks.loadFile\n  app = done = null\n\n  beforeEach ->\n    done = jasmine.createSpy 'done'\n    # load the file and inject fake fs module\n    app = loadFile __dirname + '/app.js',\n      fs: mocks.fs.create\n        'bin':\n          'run.sh': 1,\n          'install.sh': 1\n        'home':\n          'some.js': 1,\n          'another.txt': 1\n        'one.js': 1,\n        'two.js': 1,\n        'three.js': 1\n\n\n  it 'should return only existing files', ->\n    done.andCallFake (err, filtered) ->\n      expect(err).toBeFalsy()\n      expect(filtered).toEqual ['/bin/run.sh']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/non.txt'], done\n    waitsFor -> done.callCount\n\n  it 'should ignore directories', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/bin/run.sh', '/home/some.js']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/home', '/home/some.js'], done\n    waitsFor -> done.callCount\n````\n\n### Faking randomness\nNon-blocking I/O operations can return in random order. Let's say you read a content of two files (asynchronously). There is no guarantee, that you get the content in right order. That's fine, but we want to test our code, whether it can handle such a situation and still work properly. In that case, you can use `predictableNextTick`, which process callbacks depending on given pattern.\n\n````coffeescript\n\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nThis test will always pass. That's cool, as we like to see tests passing. The bad thing is, that it does not work in production, with real file system, as it might return in different order...\nSo, we need to test, whether our app works even when the `fs` returns in random order. Having randomness in unit tests is not good habit, as it leads to flaky tests.\nLet's change the previous unit test to this:\n\n````coffeescript\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    mocks.predictableNextTick.pattern = [2, 0, 1]\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nNow, the unit test fails, because our fake file system calls back in different order. Note, it's not random, as you explicitly specified the pattern (2, 0, 1), so it the fake fs will consistently call back in this order: /three.js, /one.js, two.js.\n\n\n## API\nCurrently supported API is only very small part of real [Node's API]. Basically I only implemented methods I need for testing [Testacular].\n\nI will keep adding more and of course if anyone wants to help - pull requests are more than welcomed.\n\n### [fs](http://nodejs.org/api/fs.html)\n\n- stat(path, callback)\n- readdir(path, callback)\n- readFile(path [, encoding], callback)\n- readFileSync(path)\n- watchFile(path [, options], callback)\n- _touchFile(path, mtime, content) *\n\n### [http](http://nodejs.org/api/http.html)\n\n- http.ServerResponse\n- http.ServerRequest\n\n### [glob](https://github.com/isaacs/node-glob)\n\n\n### loadFile(path [, mocks] [, globals])\n### predictableNextTick(fn)\n### predictableNextTick.pattern\n\n[Node.js]: http://nodejs.org/\n[NPM]: http://npmjs.org/\n[Node's API]: http://nodejs.org/docs/latest/api/index.html\n[Testacular]: https://github.com/vojtajina/testacular\n","maintainers":[{"name":"vojtajina","email":"vojta.jina@gmail.com"}],"directories":{}},"0.0.6":{"name":"mocks","description":"Set of mock modules for easy testing (fs, http)","homepage":"","keywords":["mock","stub","dummy","test double","fake","nodejs","js","testing","test","fs","fs mock","http","http mock"],"author":{"name":"Vojta Jína","email":"vojta.jina@gmail.com"},"contributors":[],"dependencies":{},"devDependencies":{"coffee-script":"1.1.2","jasmine-node":"1.0.11","jake":"0.2.15"},"repository":{"type":"git","url":"git://github.com/vojtajina/node-mocks.git"},"main":"./lib/index","bin":{},"engines":{"node":">= 0.6.5"},"version":"0.0.6","readme":"# Node Mocks [![Build Status](https://secure.travis-ci.org/vojtajina/node-mocks.png?branch=master)](http://travis-ci.org/vojtajina/node-mocks)\n\nSet of mocks and utilities for easier unit testing with [Node.js].\n\nSee http://howtonode.org/testing-private-state-and-mocking-deps for better explanation.\n\n## Prerequisites\n\n* [Node.js]\n* [NPM] (shipped with Node since 0.6.3)\n\n\n## Installation\n\n    sudo npm install -g mocks\n\n    # or install in local folder\n    npm install mocks\n\n\n## Example\n\n### Mocking a file system\n\n````javascript\n// during unit test - we inject mock file system instead of real fs\nvar fs = require('fs');\n\n// even if this function is not public, we can test it directly\nvar filterOnlyExistingFiles = function(collection, done) {\n  var filtered = [],\n      waiting = 0;\n\n  collection.forEach(function(file) {\n    waiting++;\n    fs.stat(file, function(err, stat) {\n      if (!err && stat.isFile()) filtered.push(file);\n      waiting--;\n      if (!waiting) done(null, filtered);\n    });\n  });\n};\n````\n\n````coffeescript\n# simple unit test (jasmine syntax, coffescript)\ndescribe 'app', ->\n  mocks = require 'mocks'\n  loadFile = mocks.loadFile\n  app = done = null\n\n  beforeEach ->\n    done = jasmine.createSpy 'done'\n    # load the file and inject fake fs module\n    app = loadFile __dirname + '/app.js',\n      fs: mocks.fs.create\n        'bin':\n          'run.sh': 1,\n          'install.sh': 1\n        'home':\n          'some.js': 1,\n          'another.txt': 1\n        'one.js': 1,\n        'two.js': 1,\n        'three.js': 1\n\n\n  it 'should return only existing files', ->\n    done.andCallFake (err, filtered) ->\n      expect(err).toBeFalsy()\n      expect(filtered).toEqual ['/bin/run.sh']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/non.txt'], done\n    waitsFor -> done.callCount\n\n  it 'should ignore directories', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/bin/run.sh', '/home/some.js']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/home', '/home/some.js'], done\n    waitsFor -> done.callCount\n````\n\n### Faking randomness\nNon-blocking I/O operations can return in random order. Let's say you read a content of two files (asynchronously). There is no guarantee, that you get the content in right order. That's fine, but we want to test our code, whether it can handle such a situation and still work properly. In that case, you can use `predictableNextTick`, which process callbacks depending on given pattern.\n\n````coffeescript\n\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nThis test will always pass. That's cool, as we like to see tests passing. The bad thing is, that it does not work in production, with real file system, as it might return in different order...\nSo, we need to test, whether our app works even when the `fs` returns in random order. Having randomness in unit tests is not good habit, as it leads to flaky tests.\nLet's change the previous unit test to this:\n\n````coffeescript\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    mocks.predictableNextTick.pattern = [2, 0, 1]\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nNow, the unit test fails, because our fake file system calls back in different order. Note, it's not random, as you explicitly specified the pattern (2, 0, 1), so it the fake fs will consistently call back in this order: /three.js, /one.js, two.js.\n\n\n## API\nCurrently supported API is only very small part of real [Node's API]. Basically I only implemented methods I need for testing [Testacular].\n\nI will keep adding more and of course if anyone wants to help - pull requests are more than welcomed.\n\n### [fs](http://nodejs.org/api/fs.html)\n\n- stat(path, callback)\n- readdir(path, callback)\n- readFile(path [, encoding], callback)\n- readFileSync(path)\n- watchFile(path [, options], callback)\n- _touchFile(path, mtime, content) *\n\n### [http](http://nodejs.org/api/http.html)\n\n- http.ServerResponse\n- http.ServerRequest\n\n### [glob](https://github.com/isaacs/node-glob)\n\n\n### loadFile(path [, mocks] [, globals])\n### predictableNextTick(fn)\n### predictableNextTick.pattern\n\n[Node.js]: http://nodejs.org/\n[NPM]: http://npmjs.org/\n[Node's API]: http://nodejs.org/docs/latest/api/index.html\n[Testacular]: https://github.com/vojtajina/testacular\n","_id":"mocks@0.0.6","dist":{"shasum":"af66b24089cc2c3e594569f6c5082db41dee407d","tarball":"https://registry.npmjs.org/mocks/-/mocks-0.0.6.tgz","integrity":"sha512-KoOX5Aspov8CX8Jpr9+oueO6n9oTKig/Wm+uWv099KK01DpKEGzbIFFwy5I5zQdaOmfBR7eI3zZynsYpzaigNA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD941MEZaEdVKZPBUUit/F9iGCFzFxCMTuTFUnoauIpHgIgDdjMPB8KC46Olto5fxonx/3LusSDgMwhQaKYVy+OgqA="}]},"maintainers":[{"name":"vojtajina","email":"vojta.jina@gmail.com"}],"directories":{}},"0.0.7":{"name":"mocks","description":"Set of mock modules for easy testing (fs, http)","homepage":"","keywords":["mock","stub","dummy","test double","fake","nodejs","js","testing","test","fs","fs mock","http","http mock"],"author":{"name":"Vojta Jína","email":"vojta.jina@gmail.com"},"contributors":[],"dependencies":{},"devDependencies":{"coffee-script":"1.1.2","jasmine-node":"1.0.11","jake":"0.2.15"},"repository":{"type":"git","url":"git://github.com/vojtajina/node-mocks.git"},"main":"./lib/index","bin":{},"engines":{"node":">= 0.6.5"},"version":"0.0.7","readme":"# Node Mocks [![Build Status](https://secure.travis-ci.org/vojtajina/node-mocks.png?branch=master)](http://travis-ci.org/vojtajina/node-mocks)\n\nSet of mocks and utilities for easier unit testing with [Node.js].\n\nSee http://howtonode.org/testing-private-state-and-mocking-deps for better explanation.\n\n## Prerequisites\n\n* [Node.js]\n* [NPM] (shipped with Node since 0.6.3)\n\n\n## Installation\n\n    sudo npm install -g mocks\n\n    # or install in local folder\n    npm install mocks\n\n\n## Example\n\n### Mocking a file system\n\n````javascript\n// during unit test - we inject mock file system instead of real fs\nvar fs = require('fs');\n\n// even if this function is not public, we can test it directly\nvar filterOnlyExistingFiles = function(collection, done) {\n  var filtered = [],\n      waiting = 0;\n\n  collection.forEach(function(file) {\n    waiting++;\n    fs.stat(file, function(err, stat) {\n      if (!err && stat.isFile()) filtered.push(file);\n      waiting--;\n      if (!waiting) done(null, filtered);\n    });\n  });\n};\n````\n\n````coffeescript\n# simple unit test (jasmine syntax, coffescript)\ndescribe 'app', ->\n  mocks = require 'mocks'\n  loadFile = mocks.loadFile\n  app = done = null\n\n  beforeEach ->\n    done = jasmine.createSpy 'done'\n    # load the file and inject fake fs module\n    app = loadFile __dirname + '/app.js',\n      fs: mocks.fs.create\n        'bin':\n          'run.sh': 1,\n          'install.sh': 1\n        'home':\n          'some.js': 1,\n          'another.txt': 1\n        'one.js': 1,\n        'two.js': 1,\n        'three.js': 1\n\n\n  it 'should return only existing files', ->\n    done.andCallFake (err, filtered) ->\n      expect(err).toBeFalsy()\n      expect(filtered).toEqual ['/bin/run.sh']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/non.txt'], done\n    waitsFor -> done.callCount\n\n  it 'should ignore directories', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/bin/run.sh', '/home/some.js']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/home', '/home/some.js'], done\n    waitsFor -> done.callCount\n````\n\n### Faking randomness\nNon-blocking I/O operations can return in random order. Let's say you read a content of two files (asynchronously). There is no guarantee, that you get the content in right order. That's fine, but we want to test our code, whether it can handle such a situation and still work properly. In that case, you can use `predictableNextTick`, which process callbacks depending on given pattern.\n\n````coffeescript\n\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nThis test will always pass. That's cool, as we like to see tests passing. The bad thing is, that it does not work in production, with real file system, as it might return in different order...\nSo, we need to test, whether our app works even when the `fs` returns in random order. Having randomness in unit tests is not good habit, as it leads to flaky tests.\nLet's change the previous unit test to this:\n\n````coffeescript\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    mocks.predictableNextTick.pattern = [2, 0, 1]\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nNow, the unit test fails, because our fake file system calls back in different order. Note, it's not random, as you explicitly specified the pattern (2, 0, 1), so it the fake fs will consistently call back in this order: /three.js, /one.js, two.js.\n\n\n## API\nCurrently supported API is only very small part of real [Node's API]. Basically I only implemented methods I need for testing [Testacular].\n\nI will keep adding more and of course if anyone wants to help - pull requests are more than welcomed.\n\n### [fs](http://nodejs.org/api/fs.html)\n\n- stat(path, callback)\n- readdir(path, callback)\n- readFile(path [, encoding], callback)\n- readFileSync(path)\n- watchFile(path [, options], callback)\n- _touchFile(path, mtime, content) *\n\n### [http](http://nodejs.org/api/http.html)\n\n- http.ServerResponse\n- http.ServerRequest\n\n### [glob](https://github.com/isaacs/node-glob)\n\n\n### loadFile(path [, mocks] [, globals])\n### predictableNextTick(fn)\n### predictableNextTick.pattern\n\n[Node.js]: http://nodejs.org/\n[NPM]: http://npmjs.org/\n[Node's API]: http://nodejs.org/docs/latest/api/index.html\n[Testacular]: https://github.com/vojtajina/testacular\n","_id":"mocks@0.0.7","dist":{"shasum":"8f679e60bdd7cceeae776d1b3a63df87561c7d27","tarball":"https://registry.npmjs.org/mocks/-/mocks-0.0.7.tgz","integrity":"sha512-LWFKsNODzNRVtQglLN9FdniAqXpxLExd4Wb4oLPMtCGuLcVu21qO2jKJBuSiDvxQ0jWDbXRQK4Fd1a9E0LinYg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDIW8zivpJbWYByK0pCUFNEmSpPwlmxW/JhKq+VqZ+VHAIhAJhtZbgPs8iQIAi5vrn6H2g6IQJ/j7043sO3whr3qy11"}]},"maintainers":[{"name":"vojtajina","email":"vojta.jina@gmail.com"}]},"0.0.8":{"name":"mocks","description":"Set of mock modules for easy testing (fs, http)","homepage":"","keywords":["mock","stub","dummy","test double","fake","nodejs","js","testing","test","fs","fs mock","http","http mock"],"author":{"name":"Vojta Jína","email":"vojta.jina@gmail.com"},"contributors":[{"name":"Damien Duportal","email":"damien.duportal@gmail.com"}],"dependencies":{},"devDependencies":{"coffee-script":"1.1.2","jasmine-node":"1.0.11","jake":"0.2.15"},"repository":{"type":"git","url":"git://github.com/vojtajina/node-mocks.git"},"main":"./lib/index","bin":{},"engines":{"node":">= 0.6.5"},"version":"0.0.8","readme":"# Node Mocks [![Build Status](https://secure.travis-ci.org/vojtajina/node-mocks.png?branch=master)](http://travis-ci.org/vojtajina/node-mocks)\n\nSet of mocks and utilities for easier unit testing with [Node.js].\n\nSee http://howtonode.org/testing-private-state-and-mocking-deps for better explanation.\n\n## Prerequisites\n\n* [Node.js]\n* [NPM] (shipped with Node since 0.6.3)\n\n\n## Installation\n\n    sudo npm install -g mocks\n\n    # or install in local folder\n    npm install mocks\n\n\n## Example\n\n### Mocking a file system\n\n````javascript\n// during unit test - we inject mock file system instead of real fs\nvar fs = require('fs');\n\n// even if this function is not public, we can test it directly\nvar filterOnlyExistingFiles = function(collection, done) {\n  var filtered = [],\n      waiting = 0;\n\n  collection.forEach(function(file) {\n    waiting++;\n    fs.stat(file, function(err, stat) {\n      if (!err && stat.isFile()) filtered.push(file);\n      waiting--;\n      if (!waiting) done(null, filtered);\n    });\n  });\n};\n````\n\n````coffeescript\n# simple unit test (jasmine syntax, coffescript)\ndescribe 'app', ->\n  mocks = require 'mocks'\n  loadFile = mocks.loadFile\n  app = done = null\n\n  beforeEach ->\n    done = jasmine.createSpy 'done'\n    # load the file and inject fake fs module\n    app = loadFile __dirname + '/app.js',\n      fs: mocks.fs.create\n        'bin':\n          'run.sh': 1,\n          'install.sh': 1\n        'home':\n          'some.js': 1,\n          'another.txt': 1\n        'one.js': 1,\n        'two.js': 1,\n        'three.js': 1\n\n\n  it 'should return only existing files', ->\n    done.andCallFake (err, filtered) ->\n      expect(err).toBeFalsy()\n      expect(filtered).toEqual ['/bin/run.sh']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/non.txt'], done\n    waitsFor -> done.callCount\n\n  it 'should ignore directories', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/bin/run.sh', '/home/some.js']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/home', '/home/some.js'], done\n    waitsFor -> done.callCount\n````\n\n### Faking randomness\nNon-blocking I/O operations can return in random order. Let's say you read a content of two files (asynchronously). There is no guarantee, that you get the content in right order. That's fine, but we want to test our code, whether it can handle such a situation and still work properly. In that case, you can use `predictableNextTick`, which process callbacks depending on given pattern.\n\n````coffeescript\n\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nThis test will always pass. That's cool, as we like to see tests passing. The bad thing is, that it does not work in production, with real file system, as it might return in different order...\nSo, we need to test, whether our app works even when the `fs` returns in random order. Having randomness in unit tests is not good habit, as it leads to flaky tests.\nLet's change the previous unit test to this:\n\n````coffeescript\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    mocks.predictableNextTick.pattern = [2, 0, 1]\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nNow, the unit test fails, because our fake file system calls back in different order. Note, it's not random, as you explicitly specified the pattern (2, 0, 1), so it the fake fs will consistently call back in this order: /three.js, /one.js, two.js.\n\n\n## API\nCurrently supported API is only very small part of real [Node's API]. Basically I only implemented methods I need for testing [Testacular].\n\nI will keep adding more and of course if anyone wants to help - pull requests are more than welcomed.\n\n### [fs](http://nodejs.org/api/fs.html)\n\n- stat(path, callback)\n- readdir(path, callback)\n- readFile(path [, encoding], callback)\n- readFileSync(path)\n- watchFile(path [, options], callback)\n- _touchFile(path, mtime, content) *\n\n### [http](http://nodejs.org/api/http.html)\n\n- http.ServerResponse\n- http.ServerRequest\n\n### [glob](https://github.com/isaacs/node-glob)\n\n\n### loadFile(path [, mocks] [, globals])\n### predictableNextTick(fn)\n### predictableNextTick.pattern\n\n[Node.js]: http://nodejs.org/\n[NPM]: http://npmjs.org/\n[Node's API]: http://nodejs.org/docs/latest/api/index.html\n[Testacular]: https://github.com/vojtajina/testacular\n","_id":"mocks@0.0.8","dist":{"shasum":"f2dae3a8cd6c6bd9ee57395b0f1de2327743ba0e","tarball":"https://registry.npmjs.org/mocks/-/mocks-0.0.8.tgz","integrity":"sha512-whdHS2Ex4FRDUA2bQbeLjm4xCrQC5FBUsn9j3tlAS4f0EHgoacVSdP5YFCJZXbQX+cqQulkHH2UzdbImOJwN3A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCGwjtoj3AXi+jH4ZNloLtFQHIVSxivWaQlx1ZKHlgpHAIgS9v1eget6XGLlpy/GSXJLbnu3wBknWuCozw5aGCKcDo="}]},"maintainers":[{"name":"vojtajina","email":"vojta.jina@gmail.com"}]},"0.0.9":{"name":"mocks","description":"Set of mock modules for easy testing (fs, http)","homepage":"","keywords":["mock","stub","dummy","test double","fake","nodejs","js","testing","test","fs","fs mock","http","http mock"],"author":{"name":"Vojta Jína","email":"vojta.jina@gmail.com"},"contributors":[{"name":"Damien Duportal","email":"damien.duportal@gmail.com"},{"name":"Taichi","email":"ryushi@gmail.com"}],"dependencies":{},"devDependencies":{"coffee-script":"1.1.2","jasmine-node":"1.0.11","jake":"0.2.15"},"repository":{"type":"git","url":"git://github.com/vojtajina/node-mocks.git"},"main":"./lib/index","bin":{},"engines":{"node":">= 0.6.5"},"version":"0.0.9","readme":"# Node Mocks [![Build Status](https://secure.travis-ci.org/vojtajina/node-mocks.png?branch=master)](http://travis-ci.org/vojtajina/node-mocks)\n\nSet of mocks and utilities for easier unit testing with [Node.js].\n\nSee http://howtonode.org/testing-private-state-and-mocking-deps for better explanation.\n\n## Prerequisites\n\n* [Node.js]\n* [NPM] (shipped with Node since 0.6.3)\n\n\n## Installation\n\n    sudo npm install -g mocks\n\n    # or install in local folder\n    npm install mocks\n\n\n## Example\n\n### Mocking a file system\n\n````javascript\n// during unit test - we inject mock file system instead of real fs\nvar fs = require('fs');\n\n// even if this function is not public, we can test it directly\nvar filterOnlyExistingFiles = function(collection, done) {\n  var filtered = [],\n      waiting = 0;\n\n  collection.forEach(function(file) {\n    waiting++;\n    fs.stat(file, function(err, stat) {\n      if (!err && stat.isFile()) filtered.push(file);\n      waiting--;\n      if (!waiting) done(null, filtered);\n    });\n  });\n};\n````\n\n````coffeescript\n# simple unit test (jasmine syntax, coffescript)\ndescribe 'app', ->\n  mocks = require 'mocks'\n  loadFile = mocks.loadFile\n  app = done = null\n\n  beforeEach ->\n    done = jasmine.createSpy 'done'\n    # load the file and inject fake fs module\n    app = loadFile __dirname + '/app.js',\n      fs: mocks.fs.create\n        'bin':\n          'run.sh': 1,\n          'install.sh': 1\n        'home':\n          'some.js': 1,\n          'another.txt': 1\n        'one.js': 1,\n        'two.js': 1,\n        'three.js': 1\n\n\n  it 'should return only existing files', ->\n    done.andCallFake (err, filtered) ->\n      expect(err).toBeFalsy()\n      expect(filtered).toEqual ['/bin/run.sh']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/non.txt'], done\n    waitsFor -> done.callCount\n\n  it 'should ignore directories', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/bin/run.sh', '/home/some.js']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/home', '/home/some.js'], done\n    waitsFor -> done.callCount\n````\n\n### Faking randomness\nNon-blocking I/O operations can return in random order. Let's say you read a content of two files (asynchronously). There is no guarantee, that you get the content in right order. That's fine, but we want to test our code, whether it can handle such a situation and still work properly. In that case, you can use `predictableNextTick`, which process callbacks depending on given pattern.\n\n````coffeescript\n\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nThis test will always pass. That's cool, as we like to see tests passing. The bad thing is, that it does not work in production, with real file system, as it might return in different order...\nSo, we need to test, whether our app works even when the `fs` returns in random order. Having randomness in unit tests is not good habit, as it leads to flaky tests.\nLet's change the previous unit test to this:\n\n````coffeescript\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    mocks.predictableNextTick.pattern = [2, 0, 1]\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nNow, the unit test fails, because our fake file system calls back in different order. Note, it's not random, as you explicitly specified the pattern (2, 0, 1), so it the fake fs will consistently call back in this order: /three.js, /one.js, two.js.\n\n\n## API\nCurrently supported API is only very small part of real [Node's API]. Basically I only implemented methods I need for testing [Testacular].\n\nI will keep adding more and of course if anyone wants to help - pull requests are more than welcomed.\n\n### [fs](http://nodejs.org/api/fs.html)\n\n- stat(path, callback)\n- readdir(path, callback)\n- readFile(path [, encoding], callback)\n- readFileSync(path)\n- watchFile(path [, options], callback)\n- _touchFile(path, mtime, content) *\n\n### [http](http://nodejs.org/api/http.html)\n\n- http.ServerResponse\n- http.ServerRequest\n\n### [glob](https://github.com/isaacs/node-glob)\n\n\n### loadFile(path [, mocks] [, globals])\n### predictableNextTick(fn)\n### predictableNextTick.pattern\n\n[Node.js]: http://nodejs.org/\n[NPM]: http://npmjs.org/\n[Node's API]: http://nodejs.org/docs/latest/api/index.html\n[Testacular]: https://github.com/vojtajina/testacular\n","_id":"mocks@0.0.9","dist":{"shasum":"e7bea4f7855b22dff24f8ed8f5cb4f516386dfbf","tarball":"https://registry.npmjs.org/mocks/-/mocks-0.0.9.tgz","integrity":"sha512-1Jz75l1fJevNSA8gyR/1Y9FRD5G/8kagIa78Q02r9Hh6C42pIJW96pgUBe8w82pRx6PuoI0JdPzwE4vBj6pRbg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDbwnyoGMZM3USjOgVWAP01WbWP9B8MgXBI8WKvJ4RaBwIhAIR5+jwJksjyNZ9HI2tgcwmQru1kLdEEyYQH2HRq3goA"}]},"_npmVersion":"1.1.63","_npmUser":{"name":"vojtajina","email":"vojta.jina@gmail.com"},"maintainers":[{"name":"vojtajina","email":"vojta.jina@gmail.com"}]},"0.0.10":{"name":"mocks","description":"Set of mock modules for easy testing (fs, http)","homepage":"","keywords":["mock","stub","dummy","test double","fake","nodejs","js","testing","test","fs","fs mock","http","http mock"],"author":{"name":"Vojta Jína","email":"vojta.jina@gmail.com"},"contributors":[{"name":"Damien Duportal","email":"damien.duportal@gmail.com"},{"name":"Taichi","email":"ryushi@gmail.com"}],"dependencies":{},"devDependencies":{"coffee-script":"1.1.2","jasmine-node":"1.0.11","jake":"0.2.15"},"repository":{"type":"git","url":"git://github.com/vojtajina/node-mocks.git"},"main":"./lib/index","bin":{},"engines":{"node":">= 0.6.5"},"version":"0.0.10","readme":"# Node Mocks [![Build Status](https://secure.travis-ci.org/vojtajina/node-mocks.png?branch=master)](http://travis-ci.org/vojtajina/node-mocks)\n\nSet of mocks and utilities for easier unit testing with [Node.js].\n\nSee http://howtonode.org/testing-private-state-and-mocking-deps for better explanation.\n\n## Prerequisites\n\n* [Node.js]\n* [NPM] (shipped with Node since 0.6.3)\n\n\n## Installation\n\n    sudo npm install -g mocks\n\n    # or install in local folder\n    npm install mocks\n\n\n## Example\n\n### Mocking a file system\n\n````javascript\n// during unit test - we inject mock file system instead of real fs\nvar fs = require('fs');\n\n// even if this function is not public, we can test it directly\nvar filterOnlyExistingFiles = function(collection, done) {\n  var filtered = [],\n      waiting = 0;\n\n  collection.forEach(function(file) {\n    waiting++;\n    fs.stat(file, function(err, stat) {\n      if (!err && stat.isFile()) filtered.push(file);\n      waiting--;\n      if (!waiting) done(null, filtered);\n    });\n  });\n};\n````\n\n````coffeescript\n# simple unit test (jasmine syntax, coffescript)\ndescribe 'app', ->\n  mocks = require 'mocks'\n  loadFile = mocks.loadFile\n  app = done = null\n\n  beforeEach ->\n    done = jasmine.createSpy 'done'\n    # load the file and inject fake fs module\n    app = loadFile __dirname + '/app.js',\n      fs: mocks.fs.create\n        'bin':\n          'run.sh': 1,\n          'install.sh': 1\n        'home':\n          'some.js': 1,\n          'another.txt': 1\n        'one.js': 1,\n        'two.js': 1,\n        'three.js': 1\n\n\n  it 'should return only existing files', ->\n    done.andCallFake (err, filtered) ->\n      expect(err).toBeFalsy()\n      expect(filtered).toEqual ['/bin/run.sh']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/non.txt'], done\n    waitsFor -> done.callCount\n\n  it 'should ignore directories', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/bin/run.sh', '/home/some.js']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/home', '/home/some.js'], done\n    waitsFor -> done.callCount\n````\n\n### Faking randomness\nNon-blocking I/O operations can return in random order. Let's say you read a content of two files (asynchronously). There is no guarantee, that you get the content in right order. That's fine, but we want to test our code, whether it can handle such a situation and still work properly. In that case, you can use `predictableNextTick`, which process callbacks depending on given pattern.\n\n````coffeescript\n\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nThis test will always pass. That's cool, as we like to see tests passing. The bad thing is, that it does not work in production, with real file system, as it might return in different order...\nSo, we need to test, whether our app works even when the `fs` returns in random order. Having randomness in unit tests is not good habit, as it leads to flaky tests.\nLet's change the previous unit test to this:\n\n````coffeescript\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    mocks.predictableNextTick.pattern = [2, 0, 1]\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nNow, the unit test fails, because our fake file system calls back in different order. Note, it's not random, as you explicitly specified the pattern (2, 0, 1), so it the fake fs will consistently call back in this order: /three.js, /one.js, two.js.\n\n\n## API\nCurrently supported API is only very small part of real [Node's API]. Basically I only implemented methods I need for testing [Testacular].\n\nI will keep adding more and of course if anyone wants to help - pull requests are more than welcomed.\n\n### [fs](http://nodejs.org/api/fs.html)\n\n- stat(path, callback)\n- readdir(path, callback)\n- readFile(path [, encoding], callback)\n- readFileSync(path)\n- watchFile(path [, options], callback)\n- _touchFile(path, mtime, content) *\n\n### [http](http://nodejs.org/api/http.html)\n\n- http.ServerResponse\n- http.ServerRequest\n\n### [glob](https://github.com/isaacs/node-glob)\n\n\n### loadFile(path [, mocks] [, globals])\n### predictableNextTick(fn)\n### predictableNextTick.pattern\n\n[Node.js]: http://nodejs.org/\n[NPM]: http://npmjs.org/\n[Node's API]: http://nodejs.org/docs/latest/api/index.html\n[Testacular]: https://github.com/vojtajina/testacular\n","_id":"mocks@0.0.10","dist":{"shasum":"e1ff4e895125b145a88e2f91bb0f651c8cc8cca6","tarball":"https://registry.npmjs.org/mocks/-/mocks-0.0.10.tgz","integrity":"sha512-GW3PFtsFzMb7j4NZBT0Qmlm9WJ8lt1/OZE3FVd3CyHwTGdHO4j4Hsm9hNpzDk8pehEb89lz18khwltnc3K67hA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFmNM92ye1f6533lK9A2gX6Hn3Y0mAQEPRycMin1P2G7AiEApk/GdrJb29ByRdSQ+5uocnkujIB+jA1ysxxFPjRBqy4="}]},"_npmVersion":"1.1.63","_npmUser":{"name":"vojtajina","email":"vojta.jina@gmail.com"},"maintainers":[{"name":"vojtajina","email":"vojta.jina@gmail.com"}]},"0.0.11":{"name":"mocks","description":"Set of mock modules for easy testing (fs, http)","homepage":"","keywords":["mock","stub","dummy","test double","fake","nodejs","js","testing","test","fs","fs mock","http","http mock"],"author":{"name":"Vojta Jína","email":"vojta.jina@gmail.com"},"contributors":[{"name":"Damien Duportal","email":"damien.duportal@gmail.com"},{"name":"Taichi","email":"ryushi@gmail.com"}],"dependencies":{},"devDependencies":{"coffee-script":"1.1.2","jasmine-node":"1.0.11","jake":"0.2.15"},"repository":{"type":"git","url":"git://github.com/vojtajina/node-mocks.git"},"main":"./lib/index","bin":{},"engines":{"node":">= 0.6.5"},"version":"0.0.11","readme":"# Node Mocks [![Build Status](https://secure.travis-ci.org/vojtajina/node-mocks.png?branch=master)](http://travis-ci.org/vojtajina/node-mocks)\n\nSet of mocks and utilities for easier unit testing with [Node.js].\n\nSee http://howtonode.org/testing-private-state-and-mocking-deps for better explanation.\n\n## Prerequisites\n\n* [Node.js]\n* [NPM] (shipped with Node since 0.6.3)\n\n\n## Installation\n\n    sudo npm install -g mocks\n\n    # or install in local folder\n    npm install mocks\n\n\n## Example\n\n### Mocking a file system\n\n````javascript\n// during unit test - we inject mock file system instead of real fs\nvar fs = require('fs');\n\n// even if this function is not public, we can test it directly\nvar filterOnlyExistingFiles = function(collection, done) {\n  var filtered = [],\n      waiting = 0;\n\n  collection.forEach(function(file) {\n    waiting++;\n    fs.stat(file, function(err, stat) {\n      if (!err && stat.isFile()) filtered.push(file);\n      waiting--;\n      if (!waiting) done(null, filtered);\n    });\n  });\n};\n````\n\n````coffeescript\n# simple unit test (jasmine syntax, coffescript)\ndescribe 'app', ->\n  mocks = require 'mocks'\n  loadFile = mocks.loadFile\n  app = done = null\n\n  beforeEach ->\n    done = jasmine.createSpy 'done'\n    # load the file and inject fake fs module\n    app = loadFile __dirname + '/app.js',\n      fs: mocks.fs.create\n        'bin':\n          'run.sh': 1,\n          'install.sh': 1\n        'home':\n          'some.js': 1,\n          'another.txt': 1\n        'one.js': 1,\n        'two.js': 1,\n        'three.js': 1\n\n\n  it 'should return only existing files', ->\n    done.andCallFake (err, filtered) ->\n      expect(err).toBeFalsy()\n      expect(filtered).toEqual ['/bin/run.sh']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/non.txt'], done\n    waitsFor -> done.callCount\n\n  it 'should ignore directories', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/bin/run.sh', '/home/some.js']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/home', '/home/some.js'], done\n    waitsFor -> done.callCount\n````\n\n### Faking randomness\nNon-blocking I/O operations can return in random order. Let's say you read a content of two files (asynchronously). There is no guarantee, that you get the content in right order. That's fine, but we want to test our code, whether it can handle such a situation and still work properly. In that case, you can use `predictableNextTick`, which process callbacks depending on given pattern.\n\n````coffeescript\n\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nThis test will always pass. That's cool, as we like to see tests passing. The bad thing is, that it does not work in production, with real file system, as it might return in different order...\nSo, we need to test, whether our app works even when the `fs` returns in random order. Having randomness in unit tests is not good habit, as it leads to flaky tests.\nLet's change the previous unit test to this:\n\n````coffeescript\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    mocks.predictableNextTick.pattern = [2, 0, 1]\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nNow, the unit test fails, because our fake file system calls back in different order. Note, it's not random, as you explicitly specified the pattern (2, 0, 1), so it the fake fs will consistently call back in this order: /three.js, /one.js, two.js.\n\n\n## API\nCurrently supported API is only very small part of real [Node's API]. Basically I only implemented methods I need for testing [Testacular].\n\nI will keep adding more and of course if anyone wants to help - pull requests are more than welcomed.\n\n### [fs](http://nodejs.org/api/fs.html)\n\n- stat(path, callback)\n- readdir(path, callback)\n- readFile(path [, encoding], callback)\n- readFileSync(path)\n- watchFile(path [, options], callback)\n- _touchFile(path, mtime, content) *\n\n### [http](http://nodejs.org/api/http.html)\n\n- http.ServerResponse\n- http.ServerRequest\n\n### [glob](https://github.com/isaacs/node-glob)\n\n\n### loadFile(path [, mocks] [, globals])\n### predictableNextTick(fn)\n### predictableNextTick.pattern\n\n[Node.js]: http://nodejs.org/\n[NPM]: http://npmjs.org/\n[Node's API]: http://nodejs.org/docs/latest/api/index.html\n[Testacular]: https://github.com/vojtajina/testacular\n","readmeFilename":"README.md","_id":"mocks@0.0.11","dist":{"shasum":"746ea8a60be20ca7e09098c27f8a034df4ab7358","tarball":"https://registry.npmjs.org/mocks/-/mocks-0.0.11.tgz","integrity":"sha512-hPyjwJ/+eNjzeqtq8KYvV3mZbDUPoQPdK4Afzhl0qxFXrBqNLKAIh/ZHpVB2hXNHWqALuXhitD5WuLNE7vSQcA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDyGAq2BZftu3ko7193Dd0KGbmmp7uOTk4sw2v0GPFRxQIgW0+wr+pmVJ63QZ0lsf4CFGE7F6A9C59vXcnbIM9QGlw="}]},"_from":".","_npmVersion":"1.2.12","_npmUser":{"name":"vojtajina","email":"vojta.jina@gmail.com"},"maintainers":[{"name":"vojtajina","email":"vojta.jina@gmail.com"}]},"0.0.12":{"name":"mocks","description":"Set of mock modules for easy testing (fs, http)","homepage":"","keywords":["mock","stub","dummy","test double","fake","nodejs","js","testing","test","fs","fs mock","http","http mock"],"author":{"name":"Vojta Jína","email":"vojta.jina@gmail.com"},"contributors":[{"name":"Damien Duportal","email":"damien.duportal@gmail.com"},{"name":"Taichi","email":"ryushi@gmail.com"}],"dependencies":{},"devDependencies":{"coffee-script":"1.1.2","jasmine-node":"1.0.11","jake":"0.2.15"},"repository":{"type":"git","url":"git://github.com/vojtajina/node-mocks.git"},"main":"./lib/index","bin":{},"engines":{"node":">= 0.6.5"},"version":"0.0.12","readme":"# Node Mocks [![Build Status](https://secure.travis-ci.org/vojtajina/node-mocks.png?branch=master)](http://travis-ci.org/vojtajina/node-mocks)\n\nSet of mocks and utilities for easier unit testing with [Node.js].\n\nSee http://howtonode.org/testing-private-state-and-mocking-deps for better explanation.\n\n## Prerequisites\n\n* [Node.js]\n* [NPM] (shipped with Node since 0.6.3)\n\n\n## Installation\n\n    sudo npm install -g mocks\n\n    # or install in local folder\n    npm install mocks\n\n\n## Example\n\n### Mocking a file system\n\n````javascript\n// during unit test - we inject mock file system instead of real fs\nvar fs = require('fs');\n\n// even if this function is not public, we can test it directly\nvar filterOnlyExistingFiles = function(collection, done) {\n  var filtered = [],\n      waiting = 0;\n\n  collection.forEach(function(file) {\n    waiting++;\n    fs.stat(file, function(err, stat) {\n      if (!err && stat.isFile()) filtered.push(file);\n      waiting--;\n      if (!waiting) done(null, filtered);\n    });\n  });\n};\n````\n\n````coffeescript\n# simple unit test (jasmine syntax, coffescript)\ndescribe 'app', ->\n  mocks = require 'mocks'\n  loadFile = mocks.loadFile\n  app = done = null\n\n  beforeEach ->\n    done = jasmine.createSpy 'done'\n    # load the file and inject fake fs module\n    app = loadFile __dirname + '/app.js',\n      fs: mocks.fs.create\n        'bin':\n          'run.sh': 1,\n          'install.sh': 1\n        'home':\n          'some.js': 1,\n          'another.txt': 1\n        'one.js': 1,\n        'two.js': 1,\n        'three.js': 1\n\n\n  it 'should return only existing files', ->\n    done.andCallFake (err, filtered) ->\n      expect(err).toBeFalsy()\n      expect(filtered).toEqual ['/bin/run.sh']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/non.txt'], done\n    waitsFor -> done.callCount\n\n  it 'should ignore directories', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/bin/run.sh', '/home/some.js']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/home', '/home/some.js'], done\n    waitsFor -> done.callCount\n````\n\n### Faking randomness\nNon-blocking I/O operations can return in random order. Let's say you read a content of two files (asynchronously). There is no guarantee, that you get the content in right order. That's fine, but we want to test our code, whether it can handle such a situation and still work properly. In that case, you can use `predictableNextTick`, which process callbacks depending on given pattern.\n\n````coffeescript\n\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nThis test will always pass. That's cool, as we like to see tests passing. The bad thing is, that it does not work in production, with real file system, as it might return in different order...\nSo, we need to test, whether our app works even when the `fs` returns in random order. Having randomness in unit tests is not good habit, as it leads to flaky tests.\nLet's change the previous unit test to this:\n\n````coffeescript\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    mocks.predictableNextTick.pattern = [2, 0, 1]\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nNow, the unit test fails, because our fake file system calls back in different order. Note, it's not random, as you explicitly specified the pattern (2, 0, 1), so it the fake fs will consistently call back in this order: /three.js, /one.js, two.js.\n\n\n## API\nCurrently supported API is only very small part of real [Node's API]. Basically I only implemented methods I need for testing [Testacular].\n\nI will keep adding more and of course if anyone wants to help - pull requests are more than welcomed.\n\n### [fs](http://nodejs.org/api/fs.html)\n\n- stat(path, callback)\n- readdir(path, callback)\n- readFile(path [, encoding], callback)\n- readFileSync(path)\n- watchFile(path [, options], callback)\n- _touchFile(path, mtime, content) *\n\n### [http](http://nodejs.org/api/http.html)\n\n- http.ServerResponse\n- http.ServerRequest\n\n### [glob](https://github.com/isaacs/node-glob)\n\n\n### loadFile(path [, mocks] [, globals])\n### predictableNextTick(fn)\n### predictableNextTick.pattern\n\n[Node.js]: http://nodejs.org/\n[NPM]: http://npmjs.org/\n[Node's API]: http://nodejs.org/docs/latest/api/index.html\n[Testacular]: https://github.com/vojtajina/testacular\n","readmeFilename":"README.md","bugs":{"url":"https://github.com/vojtajina/node-mocks/issues"},"_id":"mocks@0.0.12","dist":{"shasum":"852761067cfbb30fc05b774fbe23f3148ffe3b41","tarball":"https://registry.npmjs.org/mocks/-/mocks-0.0.12.tgz","integrity":"sha512-m/v8InUC3BjMqurNhaHrk0Oe9D3qbK992TZtmhi339B3HGSbfMn2vNUVfJmD6U8TNiw0xXwBmH+N8G/UrvqPcg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDNzaWv1taqnJLnYGdELy7M98qYsmXDy9gNX0YUblvfewIgc7avL1l3WAUilTbcp4vvhNgtnoG9VqmrnGWdRg/ZAso="}]},"_from":".","_npmVersion":"1.3.1","_npmUser":{"name":"vojtajina","email":"vojta.jina@gmail.com"},"maintainers":[{"name":"vojtajina","email":"vojta.jina@gmail.com"}]},"0.0.13":{"name":"mocks","description":"Set of mock modules for easy testing (fs, http)","homepage":"","keywords":["mock","stub","dummy","test double","fake","nodejs","js","testing","test","fs","fs mock","http","http mock"],"author":{"name":"Vojta Jína","email":"vojta.jina@gmail.com"},"contributors":[{"name":"Damien Duportal","email":"damien.duportal@gmail.com"},{"name":"Taichi","email":"ryushi@gmail.com"}],"dependencies":{},"devDependencies":{"coffee-script":"1.1.2","jasmine-node":"1.0.11","jake":"0.2.15"},"repository":{"type":"git","url":"git://github.com/vojtajina/node-mocks.git"},"main":"./lib/index","bin":{},"engines":{"node":">= 0.6.5"},"version":"0.0.13","readme":"# Node Mocks [![Build Status](https://secure.travis-ci.org/vojtajina/node-mocks.png?branch=master)](http://travis-ci.org/vojtajina/node-mocks)\n\nSet of mocks and utilities for easier unit testing with [Node.js].\n\nSee http://howtonode.org/testing-private-state-and-mocking-deps for better explanation.\n\n## Prerequisites\n\n* [Node.js]\n* [NPM] (shipped with Node since 0.6.3)\n\n\n## Installation\n\n    sudo npm install -g mocks\n\n    # or install in local folder\n    npm install mocks\n\n\n## Example\n\n### Mocking a file system\n\n````javascript\n// during unit test - we inject mock file system instead of real fs\nvar fs = require('fs');\n\n// even if this function is not public, we can test it directly\nvar filterOnlyExistingFiles = function(collection, done) {\n  var filtered = [],\n      waiting = 0;\n\n  collection.forEach(function(file) {\n    waiting++;\n    fs.stat(file, function(err, stat) {\n      if (!err && stat.isFile()) filtered.push(file);\n      waiting--;\n      if (!waiting) done(null, filtered);\n    });\n  });\n};\n````\n\n````coffeescript\n# simple unit test (jasmine syntax, coffescript)\ndescribe 'app', ->\n  mocks = require 'mocks'\n  loadFile = mocks.loadFile\n  app = done = null\n\n  beforeEach ->\n    done = jasmine.createSpy 'done'\n    # load the file and inject fake fs module\n    app = loadFile __dirname + '/app.js',\n      fs: mocks.fs.create\n        'bin':\n          'run.sh': 1,\n          'install.sh': 1\n        'home':\n          'some.js': 1,\n          'another.txt': 1\n        'one.js': 1,\n        'two.js': 1,\n        'three.js': 1\n\n\n  it 'should return only existing files', ->\n    done.andCallFake (err, filtered) ->\n      expect(err).toBeFalsy()\n      expect(filtered).toEqual ['/bin/run.sh']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/non.txt'], done\n    waitsFor -> done.callCount\n\n  it 'should ignore directories', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/bin/run.sh', '/home/some.js']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/home', '/home/some.js'], done\n    waitsFor -> done.callCount\n````\n\n### Faking randomness\nNon-blocking I/O operations can return in random order. Let's say you read a content of two files (asynchronously). There is no guarantee, that you get the content in right order. That's fine, but we want to test our code, whether it can handle such a situation and still work properly. In that case, you can use `predictableNextTick`, which process callbacks depending on given pattern.\n\n````coffeescript\n\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nThis test will always pass. That's cool, as we like to see tests passing. The bad thing is, that it does not work in production, with real file system, as it might return in different order...\nSo, we need to test, whether our app works even when the `fs` returns in random order. Having randomness in unit tests is not good habit, as it leads to flaky tests.\nLet's change the previous unit test to this:\n\n````coffeescript\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    mocks.predictableNextTick.pattern = [2, 0, 1]\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nNow, the unit test fails, because our fake file system calls back in different order. Note, it's not random, as you explicitly specified the pattern (2, 0, 1), so it the fake fs will consistently call back in this order: /three.js, /one.js, two.js.\n\n\n## API\nCurrently supported API is only very small part of real [Node's API]. Basically I only implemented methods I need for testing [Testacular].\n\nI will keep adding more and of course if anyone wants to help - pull requests are more than welcomed.\n\n### [fs](http://nodejs.org/api/fs.html)\n\n- stat(path, callback)\n- readdir(path, callback)\n- readFile(path [, encoding], callback)\n- readFileSync(path)\n- watchFile(path [, options], callback)\n- _touchFile(path, mtime, content) *\n\n### [http](http://nodejs.org/api/http.html)\n\n- http.ServerResponse\n- http.ServerRequest\n\n### [glob](https://github.com/isaacs/node-glob)\n\n\n### loadFile(path [, mocks] [, globals])\n### predictableNextTick(fn)\n### predictableNextTick.pattern\n\n[Node.js]: http://nodejs.org/\n[NPM]: http://npmjs.org/\n[Node's API]: http://nodejs.org/docs/latest/api/index.html\n[Testacular]: https://github.com/vojtajina/testacular\n","readmeFilename":"README.md","bugs":{"url":"https://github.com/vojtajina/node-mocks/issues"},"_id":"mocks@0.0.13","dist":{"shasum":"f2de8510083559373c7ef5f7088c9feee7df4084","tarball":"https://registry.npmjs.org/mocks/-/mocks-0.0.13.tgz","integrity":"sha512-axMVClcYXaWUNTo85OGYf9KzWw/Uz372qVqHxayl9nNf0fRAziHS6zg9080O2MSvIi16FNdB2d3RQiSQVm27oA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCG3cMB9VzLPkECvL4g+tvuV57+EEDm/OpFl4a3neOgMQIgP5KLdUfSm1gdz1ZZRHGWfSlN9ja8yS/RnR0XUOZs0VM="}]},"_from":".","_npmVersion":"1.3.1","_npmUser":{"name":"vojtajina","email":"vojta.jina@gmail.com"},"maintainers":[{"name":"vojtajina","email":"vojta.jina@gmail.com"}]},"0.0.14":{"name":"mocks","description":"Set of mock modules for easy testing (fs, http)","homepage":"","keywords":["mock","stub","dummy","test double","fake","nodejs","js","testing","test","fs","fs mock","http","http mock"],"author":{"name":"Vojta Jína","email":"vojta.jina@gmail.com"},"contributors":[{"name":"Damien Duportal","email":"damien.duportal@gmail.com"},{"name":"Taichi","email":"ryushi@gmail.com"}],"dependencies":{},"devDependencies":{"coffee-script":"1.1.2","jasmine-node":"1.0.11","jake":"0.2.15"},"repository":{"type":"git","url":"git://github.com/vojtajina/node-mocks.git"},"main":"./lib/index","bin":{},"engines":{"node":">= 0.6.5"},"version":"0.0.14","readme":"# Node Mocks [![Build Status](https://secure.travis-ci.org/vojtajina/node-mocks.png?branch=master)](http://travis-ci.org/vojtajina/node-mocks)\n\nSet of mocks and utilities for easier unit testing with [Node.js].\n\nSee http://howtonode.org/testing-private-state-and-mocking-deps for better explanation.\n\n## Prerequisites\n\n* [Node.js]\n* [NPM] (shipped with Node since 0.6.3)\n\n\n## Installation\n\n    sudo npm install -g mocks\n\n    # or install in local folder\n    npm install mocks\n\n\n## Example\n\n### Mocking a file system\n\n````javascript\n// during unit test - we inject mock file system instead of real fs\nvar fs = require('fs');\n\n// even if this function is not public, we can test it directly\nvar filterOnlyExistingFiles = function(collection, done) {\n  var filtered = [],\n      waiting = 0;\n\n  collection.forEach(function(file) {\n    waiting++;\n    fs.stat(file, function(err, stat) {\n      if (!err && stat.isFile()) filtered.push(file);\n      waiting--;\n      if (!waiting) done(null, filtered);\n    });\n  });\n};\n````\n\n````coffeescript\n# simple unit test (jasmine syntax, coffescript)\ndescribe 'app', ->\n  mocks = require 'mocks'\n  loadFile = mocks.loadFile\n  app = done = null\n\n  beforeEach ->\n    done = jasmine.createSpy 'done'\n    # load the file and inject fake fs module\n    app = loadFile __dirname + '/app.js',\n      fs: mocks.fs.create\n        'bin':\n          'run.sh': 1,\n          'install.sh': 1\n        'home':\n          'some.js': 1,\n          'another.txt': 1\n        'one.js': 1,\n        'two.js': 1,\n        'three.js': 1\n\n\n  it 'should return only existing files', ->\n    done.andCallFake (err, filtered) ->\n      expect(err).toBeFalsy()\n      expect(filtered).toEqual ['/bin/run.sh']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/non.txt'], done\n    waitsFor -> done.callCount\n\n  it 'should ignore directories', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/bin/run.sh', '/home/some.js']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/home', '/home/some.js'], done\n    waitsFor -> done.callCount\n````\n\n### Faking randomness\nNon-blocking I/O operations can return in random order. Let's say you read a content of two files (asynchronously). There is no guarantee, that you get the content in right order. That's fine, but we want to test our code, whether it can handle such a situation and still work properly. In that case, you can use `predictableNextTick`, which process callbacks depending on given pattern.\n\n````coffeescript\n\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nThis test will always pass. That's cool, as we like to see tests passing. The bad thing is, that it does not work in production, with real file system, as it might return in different order...\nSo, we need to test, whether our app works even when the `fs` returns in random order. Having randomness in unit tests is not good habit, as it leads to flaky tests.\nLet's change the previous unit test to this:\n\n````coffeescript\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    mocks.predictableNextTick.pattern = [2, 0, 1]\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nNow, the unit test fails, because our fake file system calls back in different order. Note, it's not random, as you explicitly specified the pattern (2, 0, 1), so it the fake fs will consistently call back in this order: /three.js, /one.js, two.js.\n\n\n## API\nCurrently supported API is only very small part of real [Node's API]. Basically I only implemented methods I need for testing [Testacular].\n\nI will keep adding more and of course if anyone wants to help - pull requests are more than welcomed.\n\n### [fs](http://nodejs.org/api/fs.html)\n\n- stat(path, callback)\n- readdir(path, callback)\n- readFile(path [, encoding], callback)\n- readFileSync(path)\n- watchFile(path [, options], callback)\n- _touchFile(path, mtime, content) *\n\n### [http](http://nodejs.org/api/http.html)\n\n- http.ServerResponse\n- http.ServerRequest\n\n### [glob](https://github.com/isaacs/node-glob)\n\n\n### loadFile(path [, mocks] [, globals])\n### predictableNextTick(fn)\n### predictableNextTick.pattern\n\n[Node.js]: http://nodejs.org/\n[NPM]: http://npmjs.org/\n[Node's API]: http://nodejs.org/docs/latest/api/index.html\n[Testacular]: https://github.com/vojtajina/testacular\n","readmeFilename":"README.md","bugs":{"url":"https://github.com/vojtajina/node-mocks/issues"},"_id":"mocks@0.0.14","dist":{"shasum":"5cfd88cb12b9ea303d49a46b5aae419a18fbdbd4","tarball":"https://registry.npmjs.org/mocks/-/mocks-0.0.14.tgz","integrity":"sha512-Ctai7vjhcyMWRbrllHt95YR0y8snKOyRnk2phAVDCkmyuE+YnMWFWP903XpDA6q28/DPE3NEkGZUKyjaY2WJqw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAt67Shr6izyGiaTurfKpqLygxBg+jtM9pugNfg6zZLhAiEAk8990+4SkrXord5RWcRKZbjBB2UYL0DQ9PPYqMKpdpw="}]},"_from":".","_npmVersion":"1.3.1","_npmUser":{"name":"vojtajina","email":"vojta.jina@gmail.com"},"maintainers":[{"name":"vojtajina","email":"vojta.jina@gmail.com"}]},"0.0.15":{"name":"mocks","description":"Set of mock modules for easy testing (fs, http)","homepage":"","keywords":["mock","stub","dummy","test double","fake","nodejs","js","testing","test","fs","fs mock","http","http mock"],"author":{"name":"Vojta Jína","email":"vojta.jina@gmail.com"},"contributors":[{"name":"Damien Duportal","email":"damien.duportal@gmail.com"},{"name":"Taichi","email":"ryushi@gmail.com"}],"dependencies":{},"devDependencies":{"coffee-script":"1.1.2","jasmine-node":"1.0.11","jake":"0.2.15"},"repository":{"type":"git","url":"git://github.com/vojtajina/node-mocks.git"},"main":"./lib/index","bin":{},"engines":{"node":">= 0.6.5"},"version":"0.0.15","readme":"# Node Mocks [![Build Status](https://secure.travis-ci.org/vojtajina/node-mocks.png?branch=master)](http://travis-ci.org/vojtajina/node-mocks)\n\nSet of mocks and utilities for easier unit testing with [Node.js].\n\nSee http://howtonode.org/testing-private-state-and-mocking-deps for better explanation.\n\n## Prerequisites\n\n* [Node.js]\n* [NPM] (shipped with Node since 0.6.3)\n\n\n## Installation\n\n    sudo npm install -g mocks\n\n    # or install in local folder\n    npm install mocks\n\n\n## Example\n\n### Mocking a file system\n\n````javascript\n// during unit test - we inject mock file system instead of real fs\nvar fs = require('fs');\n\n// even if this function is not public, we can test it directly\nvar filterOnlyExistingFiles = function(collection, done) {\n  var filtered = [],\n      waiting = 0;\n\n  collection.forEach(function(file) {\n    waiting++;\n    fs.stat(file, function(err, stat) {\n      if (!err && stat.isFile()) filtered.push(file);\n      waiting--;\n      if (!waiting) done(null, filtered);\n    });\n  });\n};\n````\n\n````coffeescript\n# simple unit test (jasmine syntax, coffescript)\ndescribe 'app', ->\n  mocks = require 'mocks'\n  loadFile = mocks.loadFile\n  app = done = null\n\n  beforeEach ->\n    done = jasmine.createSpy 'done'\n    # load the file and inject fake fs module\n    app = loadFile __dirname + '/app.js',\n      fs: mocks.fs.create\n        'bin':\n          'run.sh': 1,\n          'install.sh': 1\n        'home':\n          'some.js': 1,\n          'another.txt': 1\n        'one.js': 1,\n        'two.js': 1,\n        'three.js': 1\n\n\n  it 'should return only existing files', ->\n    done.andCallFake (err, filtered) ->\n      expect(err).toBeFalsy()\n      expect(filtered).toEqual ['/bin/run.sh']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/non.txt'], done\n    waitsFor -> done.callCount\n\n  it 'should ignore directories', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/bin/run.sh', '/home/some.js']\n\n    app.filterOnlyExistingFiles ['/bin/run.sh', '/home', '/home/some.js'], done\n    waitsFor -> done.callCount\n````\n\n### Faking randomness\nNon-blocking I/O operations can return in random order. Let's say you read a content of two files (asynchronously). There is no guarantee, that you get the content in right order. That's fine, but we want to test our code, whether it can handle such a situation and still work properly. In that case, you can use `predictableNextTick`, which process callbacks depending on given pattern.\n\n````coffeescript\n\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nThis test will always pass. That's cool, as we like to see tests passing. The bad thing is, that it does not work in production, with real file system, as it might return in different order...\nSo, we need to test, whether our app works even when the `fs` returns in random order. Having randomness in unit tests is not good habit, as it leads to flaky tests.\nLet's change the previous unit test to this:\n\n````coffeescript\n  it 'should preserve order', ->\n    done.andCallFake (err, filtered) ->\n      expect(filtered).toEqual ['/one.js', '/two.js', '/three.js']\n\n    mocks.predictableNextTick.pattern = [2, 0, 1]\n    app.filterOnlyExistingFiles ['/one.js', '/two.js', '/three.js'], done\n    waitsFor -> done.callCount\n````\nNow, the unit test fails, because our fake file system calls back in different order. Note, it's not random, as you explicitly specified the pattern (2, 0, 1), so it the fake fs will consistently call back in this order: /three.js, /one.js, two.js.\n\n\n## API\nCurrently supported API is only very small part of real [Node's API]. Basically I only implemented methods I need for testing [Testacular].\n\nI will keep adding more and of course if anyone wants to help - pull requests are more than welcomed.\n\n### [fs](http://nodejs.org/api/fs.html)\n\n- stat(path, callback)\n- readdir(path, callback)\n- readFile(path [, encoding], callback)\n- readFileSync(path)\n- watchFile(path [, options], callback)\n- _touchFile(path, mtime, content) *\n\n### [http](http://nodejs.org/api/http.html)\n\n- http.ServerResponse\n- http.ServerRequest\n\n### [glob](https://github.com/isaacs/node-glob)\n\n\n### loadFile(path [, mocks] [, globals])\n### predictableNextTick(fn)\n### predictableNextTick.pattern\n\n[Node.js]: http://nodejs.org/\n[NPM]: http://npmjs.org/\n[Node's API]: http://nodejs.org/docs/latest/api/index.html\n[Testacular]: https://github.com/vojtajina/testacular\n","readmeFilename":"README.md","bugs":{"url":"https://github.com/vojtajina/node-mocks/issues"},"_id":"mocks@0.0.15","dist":{"shasum":"4660a5cc59f4ec56eb93bfd72f0834f8fc4fa11c","tarball":"https://registry.npmjs.org/mocks/-/mocks-0.0.15.tgz","integrity":"sha512-uvYl9VB+nUinKvEhXTUvwDo4tOC90mSvl9odwXywCmkLp0QR1+WNUKY2iNlIx2WGcd1OcaQHN57U9Z2Ke4VTiw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIH4Zud/yYlBJv9PCK3FJHB0TtVht0IaAZpU/8dKYdN2+AiEAggyzreEaUJgKhFmXlU6eoxODlKgbv66i83G0bTrUImM="}]},"_from":".","_npmVersion":"1.3.2","_npmUser":{"name":"vojtajina","email":"vojta.jina@gmail.com"},"maintainers":[{"name":"vojtajina","email":"vojta.jina@gmail.com"}]}},"readme":"","maintainers":[{"name":"vojtajina","email":"vojta.jina@gmail.com"}],"time":{"modified":"2022-06-20T02:26:28.452Z","created":"2012-02-13T00:46:52.785Z","0.0.1":"2012-02-13T00:46:54.329Z","0.0.2":"2012-03-12T09:49:47.000Z","0.0.3":"2012-03-15T20:38:35.045Z","0.0.5":"2012-07-24T23:36:53.419Z","0.0.4":"2012-06-25T04:44:34.228Z","0.0.6":"2012-09-20T06:27:58.292Z","0.0.7":"2012-09-23T10:55:20.305Z","0.0.8":"2012-10-01T06:25:39.249Z","0.0.9":"2012-11-04T18:42:41.150Z","0.0.10":"2012-12-10T00:09:41.510Z","0.0.11":"2013-04-16T21:47:18.126Z","0.0.12":"2013-07-23T02:50:47.174Z","0.0.13":"2013-07-23T17:01:11.731Z","0.0.14":"2013-07-23T22:11:22.021Z","0.0.15":"2013-08-03T02:27:49.982Z"},"author":{"name":"Vojta Jína","email":"vojta.jina@gmail.com"},"repository":{"type":"git","url":"git://github.com/vojtajina/node-mocks.git"},"users":{"fgribreau":true,"pvorb":true,"ivangaravito":true}}