From 4e69cdbaafe3a294d0a33c6580c86460ed9bc1a7 Mon Sep 17 00:00:00 2001 From: Andras Marozsi Date: Wed, 7 Aug 2019 11:41:39 -0400 Subject: [PATCH] Add before_after_step_hooks.feature file --- features/before_after_step_hooks.feature | 118 +++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 features/before_after_step_hooks.feature diff --git a/features/before_after_step_hooks.feature b/features/before_after_step_hooks.feature new file mode 100644 index 0000000000..4012a172bc --- /dev/null +++ b/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 doesn't fail the scenario + Given a file named "features/support/hooks.js" with: + """ + import {} from 'cucumber' + (function() { }) + """ + When I run cucumber-js + Then it passes + + Examples: + | TYPE | + | BeforeStep | + | AfterStep | + + Scenario Outline: Failing fails the scenario + Given a file named "features/support/hooks.js" with: + """ + import {} from 'cucumber' + (function() { throw 'Fail' }) + """ + When I run cucumber-js + Then it fails + + Examples: + | TYPE | + | BeforeStep | + | AfterStep | + + Scenario Outline: Only run hooks with appropriate tags + Given a file named "features/support/hooks.js" with: + """ + import {} from 'cucumber' + ('@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 hooks + Given a file named "features/support/hooks.js" with: + """ + import {} from 'cucumber' + (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