forked from Behat/Behat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
outlines.feature
269 lines (229 loc) · 7.53 KB
/
outlines.feature
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
Feature: Scenario Outlines
In order to write complex features
As a features writer
I want to write scenario outlines
Background:
Given a file named "features/bootstrap/FeatureContext.php" with:
"""
<?php
use Behat\Behat\Context\Context,
Behat\Behat\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode;
class FeatureContext implements Context
{
private $result;
private $numbers;
/**
* @Given /^I have basic calculator$/
*/
public function iHaveBasicCalculator() {
$this->result = 0;
$this->numbers = array();
}
/**
* @Given /^I have entered (\d+)$/
*/
public function iHaveEntered($number) {
$this->numbers[] = intval($number);
}
/**
* @When /^I add$/
*/
public function iAdd() {
foreach ($this->numbers as $number) {
$this->result += $number;
}
$this->numbers = array();
}
/**
* @When /^I sub$/
*/
public function iSub() {
$this->result = array_shift($this->numbers);
foreach ($this->numbers as $number) {
$this->result -= $number;
}
$this->numbers = array();
}
/**
* @When /^I multiply$/
*/
public function iMultiply() {
$this->result = array_shift($this->numbers);
foreach ($this->numbers as $number) {
$this->result *= $number;
}
$this->numbers = array();
}
/**
* @When /^I div$/
*/
public function iDiv() {
$this->result = array_shift($this->numbers);
foreach ($this->numbers as $number) {
$this->result /= $number;
}
$this->numbers = array();
}
/**
* @Then /^The result should be (\d+)$/
*/
public function theResultShouldBe($result) {
PHPUnit\Framework\Assert::assertEquals(intval($result), $this->result);
}
}
"""
Scenario: Basic scenario outline
Given a file named "features/math.feature" with:
"""
Feature: Math
Background:
Given I have basic calculator
Scenario Outline:
Given I have entered <number1>
And I have entered <number2>
When I add
Then The result should be <result>
Examples:
| number1 | number2 | result |
| 10 | 12 | 22 |
| 5 | 3 | 8 |
| 5 | 5 | 10 |
"""
When I run "behat --no-colors -f progress features/math.feature"
Then it should pass with:
"""
...............
3 scenarios (3 passed)
15 steps (15 passed)
"""
Scenario: Multiple scenario outlines
Given a file named "features/math.feature" with:
"""
Feature: Math
Background:
Given I have basic calculator
Scenario Outline:
Given I have entered <number1>
And I have entered <number2>
When I multiply
Then The result should be <result>
Examples:
| number1 | number2 | result |
| 10 | 12 | 120 |
| 5 | 3 | 15 |
Scenario:
Given I have entered 10
And I have entered 3
When I sub
Then The result should be 7
Scenario Outline:
Given I have entered <number1>
And I have entered <number2>
When I div
Then The result should be <result>
Examples:
| number1 | number2 | result |
| 10 | 2 | 5 |
| 50 | 5 | 10 |
"""
When I run "behat --no-colors -f progress features/math.feature"
Then it should pass with:
"""
.........................
5 scenarios (5 passed)
25 steps (25 passed)
"""
Scenario: Multiple scenario outlines with failing steps
Given a file named "features/math.feature" with:
"""
Feature: Math
Background:
Given I have basic calculator
Scenario Outline:
Given I have entered <number1>
And I have entered <number2>
When I multiply
Then The result should be <result>
Examples:
| number1 | number2 | result |
| 10 | 12 | 120 |
| 5 | 4 | 15 |
Scenario:
Given I have entered 10
And I have entered 4
When I sub
Then The result should be 7
Scenario Outline:
Given I have entered <number1>
And I have entered <number2>
When I div
Then The result should be <result>
Examples:
| number1 | number2 | result |
| 10 | 2 | 5 |
| 50 | 10 | 2 |
| 50 | 10 | 4 |
"""
When I run "behat --no-colors -f progress features/math.feature"
Then it should fail with:
"""
.........F....F.........F....F
--- Failed steps:
001 Example: | 5 | 4 | 15 | # features/math.feature:14
Then The result should be 15 # features/math.feature:9
Failed asserting that 20 matches expected 15.
002 Scenario: # features/math.feature:16
Then The result should be 7 # features/math.feature:20
Failed asserting that 6 matches expected 7.
003 Example: | 50 | 10 | 2 | # features/math.feature:31
Then The result should be 2 # features/math.feature:26
Failed asserting that 5 matches expected 2.
004 Example: | 50 | 10 | 4 | # features/math.feature:32
Then The result should be 4 # features/math.feature:26
Failed asserting that 5 matches expected 4.
6 scenarios (2 passed, 4 failed)
30 steps (26 passed, 4 failed)
"""
Scenario: Scenario outline examples isolation
Given a file named "features/bootstrap/FeatureContext.php" with:
"""
<?php
use Behat\Behat\Context\Context;
class FeatureContext implements Context
{
private $number = 0;
/**
* @When I add :number
*/
public function iAdd($number) {
$this->number += intval($number);
}
/**
* @Then the result should be :result
*/
public function theResultShouldBe($result) {
PHPUnit\Framework\Assert::assertEquals(intval($result), $this->number);
}
}
"""
And a file named "features/math.feature" with:
"""
Feature: Math
Scenario Outline:
When I add <add>
Then the result should be <result>
Examples:
| add | result |
| 12 | 12 |
| 3 | 3 |
| 5 | 5 |
"""
When I run "behat --no-colors -f progress features/math.feature"
Then it should pass with:
"""
......
3 scenarios (3 passed)
6 steps (6 passed)
"""