Skip to content

Commit

Permalink
Merge pull request #1 from tandrewnichols/exclude-steps
Browse files Browse the repository at this point in the history
Add the ability to exclude steps
  • Loading branch information
NathanGRomano committed Aug 7, 2014
2 parents 1f03aee + efa9c66 commit 812ecbe
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')`.
Expand Down
19 changes: 15 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/index-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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', ->

Expand Down

0 comments on commit 812ecbe

Please sign in to comment.