diff --git a/ospec/README.md b/ospec/README.md index b0638dfe..8b160277 100644 --- a/ospec/README.md +++ b/ospec/README.md @@ -4,7 +4,7 @@ Noiseless testing framework -Version: 1.0 +Version: 1.1 License: MIT ## About @@ -117,6 +117,29 @@ o.spec("call()", function() { }) ``` +A spy can also wrap other functions, like a decorator: + +```javascript +//code to be tested +var count = 0 +function inc() { + count++ +} + +//test suite +var o = require("ospec") + +o.spec("call()", function() { + o("works", function() { + var spy = o.spy(inc) + spy() + + o(count).equals(1) + }) +}) + +``` + ### Asynchronous tests If a test body function declares a named argument, the test is assumed to be asynchronous, and the argument is a function that must be called exactly one time to signal that the test has completed. As a matter of convention, this argument is typically named `done`. @@ -336,7 +359,7 @@ Declares that only a single test should be run, instead of all of them --- -### Function o.spy() +### Function o.spy([Function fn]) Returns a function that records the number of times it gets called, and its arguments diff --git a/ospec/ospec.js b/ospec/ospec.js index 9b426d99..af0484ef 100644 --- a/ospec/ospec.js +++ b/ospec/ospec.js @@ -25,8 +25,7 @@ module.exports = new function init() { spy.args = [].slice.call(arguments) spy.callCount++ - if(fn) - return fn.apply(this, arguments) + if (fn) return fn.apply(this, arguments) } spy.args = [] spy.callCount = 0