{"dist":{"shasum":"531ceec035acad3579f35fdaefe7b7601a1927ff","tarball":"https://registry.npmjs.org/macgyver/-/macgyver-1.7.0.tgz","integrity":"sha512-bewAC2qZ0klA13+tS6Fihex5yBbBjR2mNo3GNkCIEJDSA/IzjfTyRqrjPOQvJy5ENX3o74Apmt7TFI9B/2BV4A==","signatures":[{"sig":"MEYCIQD8SB9rceylxSEpP1JEAuqKsE83C0+MVf/urqPkzRNG8QIhANmKALUU8gKcycL2DZtBS1Gg+98HbTdyQQdgEz6BoSp2","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"name":"macgyver","author":{"url":"http://bit.ly/dominictarr","name":"Dominic Tarr","email":"dominic.tarr@gmail.com"},"readme":"# macgyver\n\n[![build status](https://secure.travis-ci.org/dominictarr/macgyver.png)](http://travis-ci.org/dominictarr/macgyver)\n\ndeclarative assertion framework for invocation ordering.\n\nwhen evented code really gets _mission critical_ there is one man you send in...\n\nuseful for testing streams, and other complex evented modules.\n\n## example\n\n``` js\n\nvar macgyver = require('macgyver')\n\n//create a context\nvar mac = macgyver()\n\n//wrap a function...\n\nfunction hello () {\n  console.log('hello')\n}\n\nfunction goodbye () {\n  console.log('goodbye')\n}\n\nvar hi = mac(hello)\n\n//declare it's behaviours\n\nhi.isCalled(1, 7) //must be called between 1 and 7 times.\n\nvar bye = mac(goodbye).once() //must be called strictly once.\n\nhi.before(bye) //hi must be called strictly before bye is called\n\nhi(); hi(); bye()\n\n/*\n  //this will produce an error!\n  hi(); hi(); bye(); hi()\n*/\n\nmac.validate()\n```\n\nhere is a real life example: [dominictarr/event-stream/test/spec.js](https://github.com/dominictarr/event-stream/blob/3f4f5cb57fb61144751ab5fe643b8974ab9007aa/test/spec.js#L14-56)\n\n## API\n\ncreate a `maggyver` context.\n\n``` js\nvar macgyver = require('macgyver')\nvar mac = macgyver()\n\n```\n\nwrap a function \n\n``` js\n\nfunction doSomething() {}\n\nvar _doSomething = mac(doSomething)\n\n```\n\nnow, we can make declairations about how the wrapped function must be called.\n\n### isCalled(min, max)\nassert that the function is called at least `min` times, and at most `max` times.\nif `min`, or `max` is null, then that bound is not checked. i.e. `mac(fun).isCalled(null, 10)`\nwill assert that `fun` is called not more than 10 times.\n\n### once()\nalias for `isCalled (1, 1)`\n\n### times(n)\nalias for `isCalled (n, n)`\n\n### eventually()\nalias for `isCalled (null, 1)`\n\n### never()\nalias for `isCalled (0, 0)`\n\n### maybeOnce()\nalias for `isCalled (null, 1)`\n\n### atMost(max)\nalias for `isCalled (null, max)`\n\n### atLeast(min)\nalias for `isCalled (min, null)`\n\n### again (inc=1)\nincrements the number of times a function may be called.\n(inc may be negative)\n\n### before (other)\n\nassert that a function is called before another function.\nthe `other` must also be a wrapped function.\n`mac(first).before(second = mac(second))`\n\n`before` does not check wether the second function is eventually called or not. use `isCalled` or an alias.\n\n### beforeReturns (other)\n\njust like `before` but checks that the function is called before the other function returns, so that it is possible for the first function to be called by the other.\n\n### returns (value)\n\nassert that a function returns a value.\nif value is a function, it will be called with the return value.\n``` js\n//assert that fun returns a string.\nmac(fun).returns(function (val) {\n  assert.equal(typeof val, 'string')\n})\n\n```\n\nthe function should throw if the return value was not valid.\n\n### isPassed (args)\n\nassert that a function is passed the correct arguments.\nif `args` is a function, that function is called as in returns.\n\n### throws (test)\n\nassert that a function throws. test may be a value or a function. `test` is optional. \n\nif supplyed `test` is called on every call.\n\n``` js \nmac(fun).throws(function (err, threw) {\n  if(threw) {\n    assert.equal(err.code,'ERRCODE') //check correct error\n  } else {\n    //what to do if there was no error?\n  }\n})\n```\nthis is useful for checking conditions about when the error should be thrown. example [stream\\#write](https://github.com/dominictarr/event-stream/blob/3f4f5cb57fb61144751ab5fe643b8974ab9007aa/test/spec.js#L32-36)\n\n### validate ()\n\ncheck all rules passed. must be called once you are sure all calls are finished.\nfor example `process.on('exit', mac.validate)` is a good time. `validate` in necessary\nto check that lower bounds of `isCalled` and aliases where met.\n\n## more coming!\n\n## license\n\nMIT / Apachce2\n","scripts":{"test":"synct test/*.js"},"homepage":"http://github.com/dominictarr/macgyver","keywords":["spec","test","order","eventually","before","critical"],"repository":{"url":"https://github.com/dominictarr/macgyver.git","type":"git"},"description":"[![build status](https://secure.travis-ci.org/dominictarr/macgyver.png)](http://travis-ci.org/dominictarr/macgyver)","directories":{},"maintainers":[{"name":"dominictarr","email":"dominic.tarr@gmail.com"}],"dependencies":{"assertions":"2.3"},"devDependencies":{"synct":"~1.0.0"},"_id":"macgyver@1.7.0","version":"1.7.0"}