forked from Behat/Behat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
result_types.feature
497 lines (413 loc) · 15 KB
/
result_types.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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
Feature: Different result types
In order to differentiate feature statuses
As a feature writer
I need to be able to see different types of test results
Scenario: Undefined steps
Given a file named "features/coffee.feature" with:
"""
Feature: Undefined coffee machine actions
In order to make clients happy
As a coffee machine factory
We need to be able to tell customers
about what coffee type is supported
Background:
Given I have magically created 10$
Scenario: Buy incredible coffee
When I have chose "coffee with turkey" in coffee machine
Then I should have "turkey with coffee sauce"
Scenario: Buy incredible tea
When I have chose "pizza tea" in coffee machine
Then I should have "pizza tea"
"""
And a file named "features/bootstrap/FeatureContext.php" with:
"""
<?php
use Behat\Behat\Context\Context,
Behat\Behat\Tester\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode;
class FeatureContext implements Context {}
"""
When I run "behat --no-colors -f progress features/coffee.feature --snippets-for=FeatureContext --snippets-type=regex"
Then it should pass with:
"""
UUUUUU
2 scenarios (2 undefined)
6 steps (6 undefined)
--- FeatureContext has missing steps. Define them with these snippets:
/**
* @Given /^I have magically created (\d+)\$$/
*/
public function iHaveMagicallyCreated($arg1)
{
throw new PendingException();
}
/**
* @When /^I have chose "([^"]*)" in coffee machine$/
*/
public function iHaveChoseInCoffeeMachine($arg1)
{
throw new PendingException();
}
/**
* @Then /^I should have "([^"]*)"$/
*/
public function iShouldHave($arg1)
{
throw new PendingException();
}
"""
When I run "behat --no-colors --strict -f progress features/coffee.feature --snippets-for=FeatureContext --snippets-type=regex"
Then it should fail with:
"""
UUUUUU
2 scenarios (2 undefined)
6 steps (6 undefined)
--- FeatureContext has missing steps. Define them with these snippets:
/**
* @Given /^I have magically created (\d+)\$$/
*/
public function iHaveMagicallyCreated($arg1)
{
throw new PendingException();
}
/**
* @When /^I have chose "([^"]*)" in coffee machine$/
*/
public function iHaveChoseInCoffeeMachine($arg1)
{
throw new PendingException();
}
/**
* @Then /^I should have "([^"]*)"$/
*/
public function iShouldHave($arg1)
{
throw new PendingException();
}
"""
Scenario: Pending steps
Given a file named "features/coffee.feature" with:
"""
Feature: Pending coffee machine actions
In order to make some long making drinks
As a coffee machine
I need to be able to make pending actions
Background:
Given human have ordered very very very hot "coffee"
Scenario: When the coffee ready
When the coffee will be ready
Then I should say "Take your cup!"
"""
And a file named "features/bootstrap/FeatureContext.php" with:
"""
<?php
use Behat\Behat\Context\Context,
Behat\Behat\Tester\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode;
class FeatureContext implements Context
{
/**
* @Given /^human have ordered very very very hot "([^"]*)"$/
*/
public function humanOrdered($arg1) {
throw new PendingException;
}
/**
* @When the coffee will be ready
*/
public function theCoffeeWillBeReady() {
throw new PendingException;
}
}
"""
When I run "behat --no-colors -f progress features/coffee.feature --snippets-for=FeatureContext --snippets-type=regex"
Then it should pass with:
"""
P-U
--- Pending steps:
001 Scenario: When the coffee ready # features/coffee.feature:9
Given human have ordered very very very hot "coffee" # FeatureContext::humanOrdered()
TODO: write pending definition
1 scenario (1 undefined)
3 steps (1 undefined, 1 pending, 1 skipped)
--- FeatureContext has missing steps. Define them with these snippets:
/**
* @Then /^I should say "([^"]*)"$/
*/
public function iShouldSay($arg1)
{
throw new PendingException();
}
"""
When I run "behat --no-colors --strict -f progress features/coffee.feature --snippets-for=FeatureContext --snippets-type=regex"
Then it should fail with:
"""
P-U
--- Pending steps:
001 Scenario: When the coffee ready # features/coffee.feature:9
Given human have ordered very very very hot "coffee" # FeatureContext::humanOrdered()
TODO: write pending definition
1 scenario (1 undefined)
3 steps (1 undefined, 1 pending, 1 skipped)
--- FeatureContext has missing steps. Define them with these snippets:
/**
* @Then /^I should say "([^"]*)"$/
*/
public function iShouldSay($arg1)
{
throw new PendingException();
}
"""
Scenario: Failed steps
Given a file named "features/coffee.feature" with:
"""
Feature: Failed coffee machine actions
In order to know about coffee machine failures
As a coffee buyer
I need to be able to know about failed actions
Background:
Given I have thrown 10$ into machine
Scenario: Check thrown amount
Then I should see 12$ on the screen
Scenario: Additional throws
Given I have thrown 20$ into machine
Then I should see 31$ on the screen
And I should see 33$ on the screen
"""
And a file named "features/bootstrap/FeatureContext.php" with:
"""
<?php
use Behat\Behat\Context\Context,
Behat\Behat\Tester\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode;
class FeatureContext implements Context
{
private $money = 0;
/**
* @Given /^I have thrown (\d+)\$ into machine$/
*/
public function pay($money) {
$this->money += $money;
}
/**
* @Then /^I should see (\d+)\$ on the screen$/
*/
public function iShouldSee($money) {
PHPUnit\Framework\Assert::assertEquals($money, $this->money);
}
}
"""
When I run "behat --no-colors -f progress features/coffee.feature"
Then it should fail with:
"""
.F..F-
--- Failed steps:
001 Scenario: Check thrown amount # features/coffee.feature:9
Then I should see 12$ on the screen # features/coffee.feature:10
Failed asserting that 10 matches expected '12'.
002 Scenario: Additional throws # features/coffee.feature:12
Then I should see 31$ on the screen # features/coffee.feature:14
Failed asserting that 30 matches expected '31'.
2 scenarios (2 failed)
6 steps (3 passed, 2 failed, 1 skipped)
"""
Scenario: Skipped steps
Given a file named "features/coffee.feature" with:
"""
Feature: Skipped coffee machine actions
In order to tell clients about failures faster
As a coffee machine
I need to be able to skip unneeded steps
Background:
Given human bought coffee
Scenario: I have no water
Given I have no water
And I have electricity
When I boil water
Then the coffee should be almost done
Scenario: I have no electricity
Given I have water
And I have no electricity
When I boil water
Then the coffee should be almost done
"""
And a file named "features/bootstrap/FeatureContext.php" with:
"""
<?php
use Behat\Behat\Context\Context,
Behat\Behat\Tester\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode;
class FeatureContext implements Context
{
private $money = 0;
/** @Given /^human bought coffee$/ */
public function humanBoughtCoffee() {}
/** @Given /^I have water$/ */
public function water() {}
/** @Given /^I have no water$/ */
public function noWater() {
throw new Exception('NO water in coffee machine!!!');
}
/** @Given /^I have electricity$/ */
public function haveElectricity() {}
/** @Given /^I have no electricity$/ */
public function haveNoElectricity() {
throw new Exception('NO electricity in coffee machine!!!');
}
/** @When /^I boil water$/ */
public function boilWater() {}
/** @Then /^the coffee should be almost done$/ */
public function coffeeAlmostDone() {}
/**
* @Then /^I should see (\d+)\$ on the screen$/
*/
public function iShouldSee($money) {
PHPUnit\Framework\Assert::assertEquals($money, $this->money);
}
}
"""
When I run "behat --no-colors -f progress features/coffee.feature"
Then it should fail with:
"""
.F---..F--
--- Failed steps:
001 Scenario: I have no water # features/coffee.feature:9
Given I have no water # features/coffee.feature:10
NO water in coffee machine!!! (Exception)
002 Scenario: I have no electricity # features/coffee.feature:15
And I have no electricity # features/coffee.feature:17
NO electricity in coffee machine!!! (Exception)
2 scenarios (2 failed)
10 steps (3 passed, 2 failed, 5 skipped)
"""
Scenario: Ambiguous steps
Given a file named "features/coffee.feature" with:
"""
Feature: Ambiguous orders in coffee menu
In order to be able to chose concrete coffee type
As a coffee buyer
I need to be able to know about ambiguous decisions
Scenario: Ambiguous coffee type
Given human have chosen "Latte"
Then I should make him "Latte"
"""
And a file named "features/bootstrap/FeatureContext.php" with:
"""
<?php
use Behat\Behat\Context\Context,
Behat\Behat\Tester\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode;
class FeatureContext implements Context
{
/** @Given /^human have chosen "([^"]*)"$/ */
public function chosen($arg1) {
throw new PendingException;
}
/** @Given /^human have chosen "Latte"$/ */
public function chosenLatte() {
throw new PendingException;
}
/**
* @Then /^I should make him "([^"]*)"$/
*/
public function iShouldSee($money) {
throw new PendingException;
}
}
"""
When I run "behat --no-colors -f progress features/coffee.feature"
Then it should fail with:
"""
F-
--- Failed steps:
001 Scenario: Ambiguous coffee type # features/coffee.feature:6
Given human have chosen "Latte" # features/coffee.feature:7
Ambiguous match of "human have chosen "Latte"":
to `/^human have chosen "([^"]*)"$/` from FeatureContext::chosen()
to `/^human have chosen "Latte"$/` from FeatureContext::chosenLatte()
1 scenario (1 failed)
2 steps (1 failed, 1 skipped)
"""
Scenario: Redundant steps
Given a file named "features/coffee.feature" with:
"""
Feature: Redundant actions
In order to be able to know about errors in definitions as soon as possible
As a coffee machine mechanic
I need to be able to know about redundant menu definitions
Scenario: Redundant menu
Given customer bought coffee
And customer bought another one coffee
"""
And 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
{
/** @Given /^customer bought coffee$/ */
public function chosen($arg1) {
// do something
}
/** @Given /^customer bought coffee$/ */
public function chosenLatte() {
// do something else
}
}
"""
When I run "behat --no-colors -f progress features/coffee.feature"
Then it should fail
And the output should contain:
"""
Step "/^customer bought coffee$/" is already defined in FeatureContext::chosen()
"""
Scenario: Error-containing steps
Given a file named "features/coffee.feature" with:
"""
Feature: Redundant actions
In order to be able to know about errors in definitions as soon as possible
As a coffee machine mechanic
I need to be able to know about redundant menu definitions
Scenario: Redundant menu
Given customer bought coffee
And customer bought another one coffee
"""
And a file named "features/bootstrap/FeatureContext.php" with:
"""
<?php
use Behat\Behat\Context\Context,
Behat\Behat\Tester\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode;
class FeatureContext implements Context
{
/** @Given /^customer bought coffee$/ */
public function chosen() {
trigger_error("some error", E_USER_ERROR);
}
/** @Given /^customer bought another one coffee$/ */
public function chosenLatte() {
// do something else
}
}
"""
When I run "behat --no-colors -f progress features/coffee.feature"
Then it should fail
And the output should contain:
"""
F-
--- Failed steps:
001 Scenario: Redundant menu # features/coffee.feature:6
Given customer bought coffee # features/coffee.feature:7
User Error: some error in features/bootstrap/FeatureContext.php line 12
1 scenario (1 failed)
2 steps (1 failed, 1 skipped)
"""