File: exception_in_after_step_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 (104 lines) | stat: -rw-r--r-- 3,484 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
Feature: Exception in AfterStep Block
  In order to use custom assertions at the end of each step
  As a developer
  I want exceptions raised in AfterStep 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 NaughtyStepException < Exception; end
      AfterStep do
        if @naughty
          raise NaughtyStepException.new("This step 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 step has been very very naughty (NaughtyStepException)
            ./features/support/env.rb:4:in `AfterStep'
            features/naughty_step_in_scenario.feature:4:in `Given this step does something naughty'

        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 (1 failed, 1 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 step has been very very naughty (NaughtyStepException)
            ./features/support/env.rb:4:in `AfterStep'
            features/naughty_step_in_scenario_outline.feature:4:in `Given this step <Might Work>'
            | 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 (1 failed, 3 passed)

      """