From cea1ec8e2b5a1718b62d9a3602c8a742555dfa0a Mon Sep 17 00:00:00 2001 From: Andrew Nichols Date: Sat, 2 Aug 2014 22:19:42 -0400 Subject: [PATCH 1/3] Add the ability to exclude steps --- lib/index.js | 19 +++++++++++++++---- spec/lib/index-spec.coffee | 12 ++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/index.js b/lib/index.js index 8d611ff..6dba077 100644 --- a/lib/index.js +++ b/lib/index.js @@ -134,16 +134,27 @@ Stairs.prototype.run = function () { * @param {Function} fn */ -Stairs.prototype.step = function (title, fn) { - if (typeof title === 'function') { +Stairs.prototype.step = function (title, exclude, fn) { + if (arguments.length === 1) { fn = title; + exclude = false; title = 'Untitled Step ' + (this.steps().length); + } else if (arguments.length === 2) { + fn = exclude; + if (typeof title === 'boolean') { + exclude = title; + title = 'Untitled Step ' + (this.steps().length); + } else { + exclude = false; + } } if (typeof fn !== 'function') { throw new TypeError('fn must be a function'); } - fn.title = title; - this.steps().push(fn); + if (!exclude) { + fn.title = title; + this.steps().push(fn); + } return this; }; diff --git a/spec/lib/index-spec.coffee b/spec/lib/index-spec.coffee index ae3add6..49496f0 100644 --- a/spec/lib/index-spec.coffee +++ b/spec/lib/index-spec.coffee @@ -77,6 +77,18 @@ describe 'lib', -> When -> @res = @stairs.step @title, @fn Then -> expect(@fn.title).toBe @title And -> expect(@steps[0]).toBe @fn + + describe '#step(title:String,exclude:Boolean,fn:Function)', -> + + Given -> @title1 = 'Step 1' + Given -> @fn1 = -> + Given -> @title2 = 'Step 2' + Given -> @fn2 = -> + Given -> @steps = [] + Given -> spyOn(@stairs, 'steps').andReturn @steps + When -> @res = @stairs.step(@title1, true, @fn1).step(@title2, @fn2) + Then -> expect(@fn2.title).toBe @title2 + And -> expect(@steps[0]).toBe @fn2 describe '#steps', -> From 0e54d1b214aaa2692c195ecf00ddf533d842bc3f Mon Sep 17 00:00:00 2001 From: Andrew Nichols Date: Thu, 7 Aug 2014 13:20:54 -0400 Subject: [PATCH 2/3] 0.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7a6fdc0..d4fbd6e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stairs", - "version": "0.2.0", + "version": "0.3.0", "description": "Organize your application's steps into stairs.", "main": "index.js", "scripts": { From efa9c6697a2262818dc8f348253a335b85bcf036 Mon Sep 17 00:00:00 2001 From: Andrew Nichols Date: Thu, 7 Aug 2014 13:25:21 -0400 Subject: [PATCH 3/3] Update documentation --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index ac7b984..e4e6dee 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,23 @@ s.step('query api', function ($, next) { }); ``` +### Stairs#step(title:String, exclude:Boolean, fn:Function) + +Conditionally adds a step. + +```javascript +s.step('query api', options.skipQuery, function ($, next) { + http.get($.url, function (res) { + $.body = ''; + res.on('data', function (chunk) { $.body = $.body + chunk; }); + res.on('end', next); + res.on('error', next); + }); +}); +``` + +The "query api" step will not be added if `options.skipQuery` is true. + ### Stairs.Context#skip(title:String) You can skip to a particular step given the `title` of that step by calling `this.skip('skip to')`.