-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add before_after_step_hooks.feature file
- Loading branch information
1 parent
ed76ddd
commit 4e69cdb
Showing
1 changed file
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |