Skip to content
This repository
tag: v1.1.5
Fetching contributors…

Cannot retrieve contributors at this time

file 98 lines (78 sloc) 3.0 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
Feature: Exception in Before Block
In order to know with confidence that my before blocks have run OK
As a developer
I want exceptions raised in Before blocks to be handled gracefully and reported by the formatters

Background:
Given a standard Cucumber project directory structure
And a file named "features/step_definitions/steps.rb" with:
"""
Given(/^this step works$/) do; end
"""
And a file named "features/support/env.rb" with:
"""
class SomeSetupException < Exception; end
class BadStepException < Exception; end
Before do
raise SomeSetupException.new("I cannot even start this scenario")
end
"""

Scenario: Handle Exception in standard scenario step and carry on
Given a file named "features/naughty_step_in_scenario.feature" with:
"""
Feature: Sample

Scenario: Run a good step
Given this step works
"""
When I run cucumber features
Then it should fail with
"""
Feature: Sample

Scenario: Run a good step # features/naughty_step_in_scenario.feature:3
I cannot even start this scenario (SomeSetupException)
./features/support/env.rb:4:in `Before'
Given this step works # features/step_definitions/steps.rb:1

Failing Scenarios:
cucumber features/naughty_step_in_scenario.feature:3 # Scenario: Run a good step

1 scenario (1 failed)
1 step (1 skipped)

"""

Scenario: Handle Exception in Before hook for Scenario with Background
Given a file named "features/naughty_step_in_before.feature" with:
"""
Feature: Sample

Background:
Given this step works

Scenario: Run a good step
Given this step works
"""
When I run cucumber features
Then it should fail with
"""
Feature: Sample
Background: # features/naughty_step_in_before.feature:3
I cannot even start this scenario (SomeSetupException)
./features/support/env.rb:4:in `Before'
Given this step works # features/step_definitions/steps.rb:1
Scenario: Run a good step # features/naughty_step_in_before.feature:6
Given this step works # features/step_definitions/steps.rb:1

Failing Scenarios:
cucumber features/naughty_step_in_before.feature:6 # Scenario: Run a good step

1 scenario (1 failed)
2 steps (1 skipped, 1 passed)

"""

Scenario: Handle Exception using the progress format
Given a file named "features/naughty_step_in_scenario.feature" with:
"""
Feature: Sample

Scenario: Run a good step
Given this step works
"""
When I run cucumber features --format progress
Then it should fail with
"""
F-

Failing Scenarios:
cucumber features/naughty_step_in_scenario.feature:3 # Scenario: Run a good step

1 scenario (1 failed)
1 step (1 skipped)

"""
Something went wrong with that request. Please try again.