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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
|
Feature: Around hooks
In order to support transactional scenarios for database libraries
that provide only a block syntax for transactions, Cucumber should
permit definition of Around hooks.
Scenario: A single Around hook
Given a standard Cucumber project directory structure
And a file named "features/step_definitions/steps.rb" with:
"""
Then /^the hook is called$/ do
$hook_called.should == true
end
"""
And a file named "features/support/hooks.rb" with:
"""
Around do |scenario, block|
$hook_called = true
block.call
end
"""
And a file named "features/f.feature" with:
"""
Feature: Around hooks
Scenario: using hook
Then the hook is called
"""
When I run cucumber features/f.feature
Then it should pass with
"""
Feature: Around hooks
Scenario: using hook # features/f.feature:2
Then the hook is called # features/step_definitions/steps.rb:1
1 scenario (1 passed)
1 step (1 passed)
"""
Scenario: Multiple Around hooks
Given a standard Cucumber project directory structure
And a file named "features/step_definitions/steps.rb" with:
"""
Then /^the hooks are called in the correct order$/ do
$hooks_called.should == ['A', 'B', 'C']
end
"""
And a file named "features/support/hooks.rb" with:
"""
Around do |scenario, block|
$hooks_called ||= []
$hooks_called << 'A'
block.call
end
Around do |scenario, block|
$hooks_called ||= []
$hooks_called << 'B'
block.call
end
Around do |scenario, block|
$hooks_called ||= []
$hooks_called << 'C'
block.call
end
"""
And a file named "features/f.feature" with:
"""
Feature: Around hooks
Scenario: using multiple hooks
Then the hooks are called in the correct order
"""
When I run cucumber features/f.feature
Then it should pass with
"""
Feature: Around hooks
Scenario: using multiple hooks # features/f.feature:2
Then the hooks are called in the correct order # features/step_definitions/steps.rb:1
1 scenario (1 passed)
1 step (1 passed)
"""
Scenario: Mixing Around, Before, and After hooks
Given a standard Cucumber project directory structure
And a file named "features/step_definitions/steps.rb" with:
"""
Then /^the Around hook is called around Before and After hooks$/ do
$hooks_called.should == ['Around', 'Before']
end
"""
And a file named "features/support/hooks.rb" with:
"""
Around do |scenario, block|
$hooks_called ||= []
$hooks_called << 'Around'
block.call
$hooks_called << 'Around'
$hooks_called.should == ['Around', 'Before', 'After', 'Around']
end
Before do |scenario|
$hooks_called ||= []
$hooks_called << 'Before'
end
After do |scenario|
$hooks_called ||= []
$hooks_called << 'After'
$hooks_called.should == ['Around', 'Before', 'After']
end
"""
And a file named "features/f.feature" with:
"""
Feature: Around hooks
Scenario: Mixing Around, Before, and After hooks
Then the Around hook is called around Before and After hooks
"""
When I run cucumber features/f.feature
Then it should pass with
"""
Feature: Around hooks
Scenario: Mixing Around, Before, and After hooks # features/f.feature:2
Then the Around hook is called around Before and After hooks # features/step_definitions/steps.rb:1
1 scenario (1 passed)
1 step (1 passed)
"""
Scenario: Around hooks with tags
Given a standard Cucumber project directory structure
And a file named "features/step_definitions/steps.rb" with:
"""
Then /^the Around hooks with matching tags are called$/ do
$hooks_called.should == ['one', 'one or two']
end
"""
And a file named "features/support/hooks.rb" with:
"""
Around('@one') do |scenario, block|
$hooks_called ||= []
$hooks_called << 'one'
block.call
end
Around('@one,@two') do |scenario, block|
$hooks_called ||= []
$hooks_called << 'one or two'
block.call
end
Around('@one', '@two') do |scenario, block|
$hooks_called ||= []
$hooks_called << 'one and two'
block.call
end
Around('@two') do |scenario, block|
$hooks_called ||= []
$hooks_called << 'two'
block.call
end
"""
And a file named "features/f.feature" with:
"""
Feature: Around hooks
@one
Scenario: Around hooks with tags
Then the Around hooks with matching tags are called
"""
When I run cucumber -q -t @one features/f.feature
Then it should pass with
"""
Feature: Around hooks
@one
Scenario: Around hooks with tags
Then the Around hooks with matching tags are called
1 scenario (1 passed)
1 step (1 passed)
"""
Scenario: Around hooks with scenario outlines
Given a standard Cucumber project directory structure
And a file named "features/step_definitions/steps.rb" with:
"""
Then /^the hook is called$/ do
$hook_called.should == true
end
"""
And a file named "features/support/hooks.rb" with:
"""
Around do |scenario, block|
$hook_called = true
block.call
end
"""
And a file named "features/f.feature" with:
"""
Feature: Around hooks with scenario outlines
Scenario Outline: using hook
Then the hook is called
Examples:
| Number |
| one |
| two |
"""
When I run cucumber features/f.feature
Then it should pass with
"""
Feature: Around hooks with scenario outlines
Scenario Outline: using hook # features/f.feature:2
Then the hook is called # features/step_definitions/steps.rb:1
Examples:
| Number |
| one |
| two |
2 scenarios (2 passed)
2 steps (2 passed)
"""
|