Skip to content

Commit

Permalink
Add before_after_step_hooks.feature file
Browse files Browse the repository at this point in the history
  • Loading branch information
andrasmarozsi-nbcuni committed Aug 7, 2019
1 parent ed76ddd commit 4e69cdb
Showing 1 changed file with 118 additions and 0 deletions.
118 changes: 118 additions & 0 deletions features/before_after_step_hooks.feature
@@ -0,0 +1,118 @@
Feature: Before and After Step Hooks

Background:
Given a file named "features/a.feature" with:
"""
Feature: some feature
Scenario: some scenario
Given a step
"""
And a file named "features/step_definitions/cucumber_steps.js" with:
"""
import {Given} from 'cucumber'
Given(/^a step$/, function() {})
"""
And a file named "features/support/world.js" with:
"""
import {setWorldConstructor} from 'cucumber'
function WorldConstructor() {
return {
isWorld: function() { return true }
}
}
setWorldConstructor(WorldConstructor)
"""

Scenario Outline: Empty <TYPE> doesn't fail the scenario
Given a file named "features/support/hooks.js" with:
"""
import {<TYPE>} from 'cucumber'
<TYPE>(function() { })
"""
When I run cucumber-js
Then it passes

Examples:
| TYPE |
| BeforeStep |
| AfterStep |

Scenario Outline: Failing <TYPE> fails the scenario
Given a file named "features/support/hooks.js" with:
"""
import {<TYPE>} from 'cucumber'
<TYPE>(function() { throw 'Fail' })
"""
When I run cucumber-js
Then it fails

Examples:
| TYPE |
| BeforeStep |
| AfterStep |

Scenario Outline: Only run <TYPE> hooks with appropriate tags
Given a file named "features/support/hooks.js" with:
"""
import {<TYPE>} from 'cucumber'
<TYPE>('@any-tag', function() {
throw Error("Would fail if ran")
})
"""
When I run cucumber-js
Then it passes

Examples:
| TYPE |
| BeforeStep |
| AfterStep |

Scenario Outline: World is this in <TYPE> hooks
Given a file named "features/support/hooks.js" with:
"""
import {<TYPE>} from 'cucumber'
<TYPE>(function() {
if (!this.isWorld()) {
throw Error("Expected this to be world")
}
})
"""
When I run cucumber-js
Then it passes

Examples:
| TYPE |
| BeforeStep |
| AfterStep |

Scenario: BeforeStep/AfterStep hooks run appropriately before/after steps
Given a file named "features/a.feature" with:
"""
Feature: some feature
Scenario: second scenario
Given first step
Given second step
"""
Given a file named "features/support/hooks.js" with:
"""
import {BeforeStep, AfterStep, Given, When} from 'cucumber'
import {expect} from 'chai'
let beforeCounter = 0
let afterCounter = 0
BeforeStep(function() {
beforeCounter += 1
})
AfterStep(function() {
afterCounter += 1
})
When('first step', function() {
expect(beforeCounter).to.eql(1)
expect(afterCounter).to.eql(0)
})
When('second step', function() {
expect(beforeCounter).to.eql(2)
expect(afterCounter).to.eql(1)
})
"""
When I run cucumber-js
Then it passes

0 comments on commit 4e69cdb

Please sign in to comment.