File: exception_in_after_block.feature

package info (click to toggle)
cucumber 1.3.17-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,296 kB
  • ctags: 1,812
  • sloc: ruby: 13,576; python: 28; sh: 10; makefile: 10; tcl: 3
file content (127 lines) | stat: -rw-r--r-- 3,876 bytes parent folder | download | duplicates (3)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
Feature: Exception in After Block
  In order to use custom assertions at the end of each scenario
  As a developer
  I want exceptions raised in After 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 does something naughty$/ do x=1
        @naughty = true
      end

      Given(/^this step works$/) do; end
      """
    And a file named "features/support/env.rb" with:
      """
      class NaughtyScenarioException < Exception; end
      After do
        if @naughty
          raise NaughtyScenarioException.new("This scenario has been very very naughty")
        end
      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: Naughty Step
          Given this step does something naughty

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

        Scenario: Naughty Step                   # features/naughty_step_in_scenario.feature:3
          Given this step does something naughty # features/step_definitions/steps.rb:1
            This scenario has been very very naughty (NaughtyScenarioException)
            ./features/support/env.rb:4:in `After'

        Scenario: Success       # features/naughty_step_in_scenario.feature:6
          Given this step works # features/step_definitions/steps.rb:5

      Failing Scenarios:
      cucumber features/naughty_step_in_scenario.feature:3 # Scenario: Naughty Step

      2 scenarios (1 failed, 1 passed)
      2 steps (2 passed)

      """

  Scenario: Handle Exception in scenario outline table row and carry on
    Given a file named "features/naughty_step_in_scenario_outline.feature" with:
      """
      Feature: Sample

        Scenario Outline: Naughty Step
          Given this step <Might Work>

          Examples:
          | Might Work             |
          | works                  |
          | does something naughty |
          | works                  |

        Scenario: Success
          Given this step works

      """
    When I run cucumber features
    Then it should fail with
      """
      Feature: Sample

        Scenario Outline: Naughty Step # features/naughty_step_in_scenario_outline.feature:3
          Given this step <Might Work> # features/step_definitions/steps.rb:5

          Examples: 
            | Might Work             |
            | works                  |
            | does something naughty |
            This scenario has been very very naughty (NaughtyScenarioException)
            ./features/support/env.rb:4:in `After'
            | works                  |

        Scenario: Success       # features/naughty_step_in_scenario_outline.feature:12
          Given this step works # features/step_definitions/steps.rb:5

      Failing Scenarios:
      cucumber features/naughty_step_in_scenario_outline.feature:3 # Scenario: Naughty Step

      4 scenarios (1 failed, 3 passed)
      4 steps (4 passed)

      """

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

        Scenario: Naughty Step
          Given this step does something naughty

        Scenario: Success
          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: Naughty Step

      2 scenarios (1 failed, 1 passed)
      2 steps (2 passed)

      """