{"name":"gently","version":"0.10.0","directories":{"lib":"./lib/gently"},"main":"./lib/gently/index","repository":{"type":"git","url":"git+https://github.com/felixge/node-gently.git"},"dependencies":{},"devDependencies":{},"engines":{"node":"*"},"optionalDependencies":{},"gitHead":"fa9774cff356aa0fd30dda69f64031a9993e638a","description":"<!-- badges/ --> [![Build Status](https://travis-ci.org/felixge/node-gently.svg?branch=master)](https://travis-ci.org/felixge/node-gently) [![npm](https://img.shields.io/npm/v/gently.svg)](https://www.npmjs.com/package/gently)  [![Dependency Status](https","bugs":{"url":"https://github.com/felixge/node-gently/issues"},"homepage":"https://github.com/felixge/node-gently#readme","_id":"gently@0.10.0","scripts":{},"_shasum":"de4b3f0bb8b853be4b9fc2edd17f2d3c2e33bc28","_from":".","_npmVersion":"2.10.1","_nodeVersion":"0.12.4","_npmUser":{"name":"kvz","email":"kevin@vanzonneveld.net"},"maintainers":[{"name":"felixge","email":"felix@debuggable.com"},{"name":"kvz","email":"kevin@vanzonneveld.net"}],"dist":{"shasum":"de4b3f0bb8b853be4b9fc2edd17f2d3c2e33bc28","tarball":"http://registry-npm.ywwl.com/gently/download/gently-0.10.0.tgz","integrity":"sha512-bWfstBTq/A73upQJ5zaJONPlYwhpD1K7s3YwHY5kyHbcTgr2A0/SBpn0NxtEhktgRtRMGEfC9zDZ/QHPvhzQ1Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDEfW9Jp/dtoUrVAzdNGhMV+riXcClmu2ORM0QwOl/L2AIgGjMziYNl73d9AmKbaRU8n065QLPc0lYToqhgP7VxUWc="}],"size":6009,"noattachment":false,"key":"/gently/-/gently-0.10.0.tgz"},"readme":"# Gently\n\n<!-- badges/ -->\n[![Build Status](https://travis-ci.org/felixge/node-gently.svg?branch=master)](https://travis-ci.org/felixge/node-gently)\n[![npm](https://img.shields.io/npm/v/gently.svg)](https://www.npmjs.com/package/gently) \n[![Dependency Status](https://david-dm.org/felixge/node-gently.svg?theme=shields.io)](https://david-dm.org/felixge/node-gently)\n[![Development Dependency Status](https://david-dm.org/felixge/node-gently/dev-status.svg?theme=shields.io)](https://david-dm.org/felixge/node-gently#info=devDependencies)\n<!-- /badges -->\n\n## Purpose\n\nA node.js module that helps with stubbing and behavior verification. It allows you to test the most remote and nested corners of your code while keeping being fully unobtrusive.\n\n## Features\n\n* Overwrite and stub individual object functions\n* Verify that all expected calls have been made in the expected order\n* Restore stubbed functions to their original behavior\n* Detect object / class names from obj.constructor.name and obj.toString()\n* Hijack any required module function or class constructor\n\n## Installation\n\nVia [npm](http://github.com/isaacs/npm):\n\n    npm install gently@latest\n\n## Example\n\nMake sure your dog is working properly:\n```javascript\nfunction Dog() {}\n\nDog.prototype.seeCat = function() {\n  this.bark('whuf, whuf');\n  this.run();\n}\n\nDog.prototype.bark = function(bark) {\n  require('sys').puts(bark);\n}\n\nconst gently = new (require('gently'))\n  , assert = require('assert')\n  , dog = new Dog();\n\ngently.expect(dog, 'bark', function(bark) {\n  assert.equal(bark, 'whuf, whuf');\n});\ngently.expect(dog, 'run');\n\ndog.seeCat();\n```\nYou can also easily test event emitters with this, for example a simple sequence of 2 events emitted by `fs.WriteStream`:\n```javascript\nconst gently = new (require('gently'))\n  , stream = new (require('fs').WriteStream)('my_file.txt');\n\ngently.expect(stream, 'emit', function(event) {\n  assert.equal(event, 'open');\n});\n\ngently.expect(stream, 'emit', function(event) {\n  assert.equal(event, 'drain');\n});\n```\nFor a full read world example, check out this test case: [test-incoming-form.js](http://github.com/felixge/node-formidable/blob/master/test/simple/test-incoming-form.js) (in [node-formdiable](http://github.com/felixge/node-formidable)).\n\n## API\n\n### Gently\n\n#### new Gently()\n\nCreates a new gently instance. It listens to the process `'exit'` event to make sure all expectations have been verified.\n\n#### gently.expect(obj, method, [[count], stubFn])\n\nCreates an expectation for an objects method to be called. You can optionally specify the call `count` you are expecting, as well as `stubFn` function that will run instead of the original function.\n\nReturns a reference to the function that is getting overwritten.\n\n#### gently.expect([count], stubFn)\n\nReturns a function that is supposed to be executed `count` times, delegating any calls to the provided `stubFn` function. Naming your stubFn closure will help to properly diagnose errors that are being thrown:\n```javascript\nchildProcess.exec('ls', gently.expect(function lsCallback(code) {\n  assert.equal(0, code);\n}));\n```\n#### gently.restore(obj, method)\n\nRestores an object method that has been previously overwritten using `gently.expect()`.\n\n#### gently.hijack(realRequire)\n\nReturns a new require functions that catches a reference to all required modules into `gently.hijacked`.\n\nTo use this function, include a line like this in your `'my-module.js'`.\n```javascript\nif (global.GENTLY) require = GENTLY.hijack(require);\n\nconst sys = require('sys');\nexports.hello = function() {\n  sys.log('world');\n};\n```\nNow you can write a test for the module above:\n```javascript\nconst gently = global.GENTLY = new (require('gently'))\n  , myModule = require('./my-module');\n\ngently.expect(gently.hijacked.sys, 'log', function(str) {\n  assert.equal(str, 'world');\n});\n\nmyModule.hello();\n```\n#### gently.stub(location, [exportsName])\n\nReturns a stub class that will be used instead of the real class from the module at `location` with the given `exportsName`.\n\nThis allows to test an OOP version of the previous example, where `'my-module.js'`.\n```javascript\nif (global.GENTLY) require = GENTLY.hijack(require);\n\nconst World = require('./world');\n\nexports.hello = function() {\n  const world = new World();\n  world.hello();\n}\n```\nAnd `world.js` looks like this:\n```javascript\nconst sys = require('sys');\n\nfunction World() {\n\n}\nmodule.exports = World;\n\nWorld.prototype.hello = function() {\n  sys.log('world');\n};\n```\nTesting `'my-module.js'` can now easily be accomplished:\n```javascript\nconst gently = global.GENTLY = new (require('gently'))\n  , WorldStub = gently.stub('./world')\n  , myModule = require('./my-module')\n  , WORLD;\n\ngently.expect(WorldStub, 'new', function() {\n  WORLD = this;\n});\n\ngently.expect(WORLD, 'hello');\n\nmyModule.hello();\n```\n#### gently.hijacked\n\nAn object that holds the references to all hijacked modules.\n\n#### gently.verify([msg])\n\nVerifies that all expectations of this gently instance have been satisfied. If not called manually, this method is called when the process `'exit'` event is fired.\n\nIf `msg` is given, it will appear in any error that might be thrown.\n\n## License\n\nGently is licensed under the MIT license.\n","publish_time":1438613756164,"_cnpm_publish_time":1438613756164,"dist-tags":{"latest":"1.0.0"}}