Skip to content

Commit

Permalink
"And" function has been added
Browse files Browse the repository at this point in the history
  • Loading branch information
dex4er committed Mar 30, 2017
1 parent fc17871 commit 13cbcb7
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 46 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog

## v0.3.0 2017-03-30

* `And` function

## v0.2.0 2017-02-19

* Capital letter for functions (like for cucumber-js)
Expand Down
36 changes: 21 additions & 15 deletions README.md
Expand Up @@ -17,24 +17,29 @@ npm install tap-given
__Given__ `examples/test.js` file:

```js
/* global Feature, Scenario, Given, When, Then */
/* global Feature, Scenario, Given, When, Then, And */
const t = require('tap')
require('tap-given')(t)
require('chai').should()

Feature('Test script', () => {
Scenario('Given-When-Then scenario', function () {
Given('some property in current context', () => {
this.property = 42
Scenario('Given-When-Then scenario', () => {
let a, b, c

Given('first value', () => {
a = 2
})

And('second value', () => {
b = 21
})

When('I do something with the property in current context', () => {
this.property /= 2
When('I do multiplication operation', () => {
c = a * b
})

Then('the property in current context has correct value', done => {
this.property.should.equal(21)
done()
Then('the result is correct', () => {
c.should.equal(42)
})
})
})
Expand All @@ -52,12 +57,13 @@ __Then__ following output is produced:
examples/test.js
Feature: Test script
Scenario: Given-When-Then scenario
✓ Given some property in current context
✓ When I do something with the property in current context
✓ Then the property in current context has correct value
✓ Given first value
✓ And second value
✓ When I do multiplication operation
✓ Then the result is correct
3 passing (234.754ms)
4 passing (233.031ms)
```

### Functions
Expand All @@ -68,12 +74,12 @@ examples/test.js
context for its steps then real `function () {}` should be used instead arrow
`() => {}` notation.

`Given`, `When` and `Then` functions are aliases to `it` function.
`Given`, `When`, `Then` and `And` functions are aliases to `it` function.

`Before`, `beforeEach`, `After` and `afterEach` functions are also provided
and are optional.

All functions (except `scenario` and `...Each`) add some prefix to the
All functions except `BeforeEach` and `AfterEach` add some prefix to the
description of the step.

### License
Expand Down
25 changes: 15 additions & 10 deletions examples/test.js
@@ -1,21 +1,26 @@
/* global Feature, Scenario, Given, When, Then */
/* global Feature, Scenario, Given, When, Then, And */
const t = require('tap')
require('tap-given')(t)
require('../lib/tap-given')(t)
require('chai').should()

Feature('Test script', () => {
Scenario('Given-When-Then scenario', function () {
Given('some property in current context', () => {
this.property = 42
Scenario('Given-When-Then scenario', () => {
let a, b, c

Given('first value', () => {
a = 2
})

And('second value', () => {
b = 21
})

When('I do something with the property in current context', () => {
this.property /= 2
When('I do multiplication operation', () => {
c = a * b
})

Then('the property in current context has correct value', done => {
this.property.should.equal(21)
done()
Then('the result is correct', () => {
c.should.equal(42)
})
})
})
35 changes: 27 additions & 8 deletions lib/tap-given.js
@@ -1,14 +1,33 @@
'use strict'

module.exports = function (t) {
global.Feature = (what, how) => { return t.mocha.describe('Feature: ' + what, how) }
global.Scenario = (what, how) => { return t.mocha.context('Scenario: ' + what, how) }
global.Given = (what, how) => { return t.mocha.it('Given ' + what, how) }
global.When = (what, how) => { return t.mocha.it('When ' + what, how) }
global.Then = (what, how) => { return t.mocha.it('Then ' + what, how) }

global.Before = (what, how) => { return t.mocha.before('Before that ' + what, how) }
global.After = (what, how) => { return t.mocha.after('After that ' + what, how) }
global.Feature = (what, how) => {
return t.mocha.describe('Feature: ' + what, how)
}

global.Scenario = (what, how) => {
return t.mocha.context('Scenario: ' + what, how)
}

global.Given = (what, how) => {
return t.mocha.it('Given ' + what, how)
}
global.When = (what, how) => {
return t.mocha.it('When ' + what, how)
}
global.Then = (what, how) => {
return t.mocha.it('Then ' + what, how)
}
global.And = (what, how) => {
return t.mocha.it('And ' + what, how)
}

global.Before = (what, how) => {
return t.mocha.before('Before ' + what, how)
}
global.After = (what, how) => {
return t.mocha.after('After ' + what, how)
}

global.BeforeEach = t.mocha.beforeEach
global.AfterEach = t.mocha.beforeEach
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "tap-given",
"version": "0.2.0",
"version": "0.3.0",
"description": "Given-When-Then BDD for TAP",
"main": "lib/tap-given.js",
"repository": {
Expand Down
30 changes: 18 additions & 12 deletions test/tap-given.js
@@ -1,36 +1,42 @@
'use strict'

/* global Feature, Scenario, Given, When, Then */
/* global Feature, Scenario, Given, When, Then, And */
const t = require('tap')
require('../lib/tap-given')(t)
require('chai').should()

Feature('Test tap-given module', () => {
Scenario('Given-When-Then basic scenario', function () {
Given('some property in current context', () => {
this.property = 42
Scenario('Given-When-Then basic scenario', () => {
let a, b, c

Given('first value', () => {
a = 2
})

When('I do something with property in current context', () => {
this.property /= 2
And('second value', () => {
b = 21
})

Then('property in current context has correct value', () => {
this.property.should.equal(21)
When('I do multiplication operation', () => {
c = a * b
})

Then('the result is correct', () => {
c.should.equal(42)
})
})

/* global Before, BeforeEach, After, AfterEach */
Scenario('Given-When-Then scenario with callbacks', function () {
BeforeEach(done => {
Scenario('Given-When-Then scenario with callbacks and before/after hooks', () => {
Before('do something', done => {
done()
})

AfterEach(done => {
BeforeEach(done => {
done()
})

Before('do something', done => {
AfterEach(done => {
done()
})

Expand Down

0 comments on commit 13cbcb7

Please sign in to comment.