|
4 | 4 | import cucumber.api.Scenario;
|
5 | 5 | import cucumber.api.StepDefinitionReporter;
|
6 | 6 | import cucumber.runtime.formatter.CucumberJSONFormatter;
|
| 7 | +import cucumber.runtime.formatter.FormatterSpy; |
7 | 8 | import cucumber.runtime.io.ClasspathResourceLoader;
|
8 | 9 | import cucumber.runtime.io.Resource;
|
9 | 10 | import cucumber.runtime.io.ResourceLoader;
|
|
22 | 23 | import java.io.ByteArrayOutputStream;
|
23 | 24 | import java.io.IOException;
|
24 | 25 | import java.io.PrintStream;
|
| 26 | +import java.util.AbstractMap.SimpleEntry; |
25 | 27 | import java.util.Arrays;
|
26 | 28 | import java.util.Collection;
|
27 | 29 | import java.util.Collections;
|
| 30 | +import java.util.HashMap; |
28 | 31 | import java.util.List;
|
| 32 | +import java.util.Map; |
29 | 33 |
|
30 | 34 | import static cucumber.runtime.TestHelper.feature;
|
31 | 35 | import static java.util.Arrays.asList;
|
@@ -391,6 +395,136 @@ public void should_make_scenario_id_available_to_hooks() throws Throwable {
|
391 | 395 | assertEquals("feature-name;scenario-name", capturedScenario.getValue().getId());
|
392 | 396 | }
|
393 | 397 |
|
| 398 | + @Test |
| 399 | + public void should_call_formatter_for_two_scenarios_with_background() throws Throwable { |
| 400 | + CucumberFeature feature = TestHelper.feature("path/test.feature", "" + |
| 401 | + "Feature: feature name\n" + |
| 402 | + " Background: background\n" + |
| 403 | + " Given first step\n" + |
| 404 | + " Scenario: scenario_1 name\n" + |
| 405 | + " When second step\n" + |
| 406 | + " Then third step\n" + |
| 407 | + " Scenario: scenario_2 name\n" + |
| 408 | + " Then second step\n"); |
| 409 | + Map<String, String> stepsToResult = new HashMap<String, String>(); |
| 410 | + stepsToResult.put("first step", "passed"); |
| 411 | + stepsToResult.put("second step", "passed"); |
| 412 | + stepsToResult.put("third step", "passed"); |
| 413 | + |
| 414 | + String formatterOutput = runFeatureWithFormatterSpy(feature, stepsToResult); |
| 415 | + |
| 416 | + assertEquals("" + |
| 417 | + "uri\n" + |
| 418 | + "feature\n" + |
| 419 | + " startOfScenarioLifeCycle\n" + |
| 420 | + " background\n" + |
| 421 | + " step\n" + |
| 422 | + " match\n" + |
| 423 | + " result\n" + |
| 424 | + " scenario\n" + |
| 425 | + " step\n" + |
| 426 | + " step\n" + |
| 427 | + " match\n" + |
| 428 | + " result\n" + |
| 429 | + " match\n" + |
| 430 | + " result\n" + |
| 431 | + " endOfScenarioLifeCycle\n" + |
| 432 | + " startOfScenarioLifeCycle\n" + |
| 433 | + " background\n" + |
| 434 | + " step\n" + |
| 435 | + " match\n" + |
| 436 | + " result\n" + |
| 437 | + " scenario\n" + |
| 438 | + " step\n" + |
| 439 | + " match\n" + |
| 440 | + " result\n" + |
| 441 | + " endOfScenarioLifeCycle\n" + |
| 442 | + "eof\n" + |
| 443 | + "done\n" + |
| 444 | + "close\n", formatterOutput); |
| 445 | + } |
| 446 | + |
| 447 | + @Test |
| 448 | + public void should_call_formatter_for_scenario_outline_with_two_examples_table_and_background() throws Throwable { |
| 449 | + CucumberFeature feature = TestHelper.feature("path/test.feature", "" + |
| 450 | + "Feature: feature name\n" + |
| 451 | + " Background: background\n" + |
| 452 | + " Given first step\n" + |
| 453 | + " Scenario Outline: scenario outline name\n" + |
| 454 | + " When <x> step\n" + |
| 455 | + " Then <y> step\n" + |
| 456 | + " Examples: examples 1 name\n" + |
| 457 | + " | x | y |\n" + |
| 458 | + " | second | third |\n" + |
| 459 | + " | second | third |\n" + |
| 460 | + " Examples: examples 2 name\n" + |
| 461 | + " | x | y |\n" + |
| 462 | + " | second | third |\n"); |
| 463 | + Map<String, String> stepsToResult = new HashMap<String, String>(); |
| 464 | + stepsToResult.put("first step", "passed"); |
| 465 | + stepsToResult.put("second step", "passed"); |
| 466 | + stepsToResult.put("third step", "passed"); |
| 467 | + |
| 468 | + String formatterOutput = runFeatureWithFormatterSpy(feature, stepsToResult); |
| 469 | + |
| 470 | + assertEquals("" + |
| 471 | + "uri\n" + |
| 472 | + "feature\n" + |
| 473 | + " scenarioOutline\n" + |
| 474 | + " step\n" + |
| 475 | + " step\n" + |
| 476 | + " examples\n" + |
| 477 | + " startOfScenarioLifeCycle\n" + |
| 478 | + " background\n" + |
| 479 | + " step\n" + |
| 480 | + " match\n" + |
| 481 | + " result\n" + |
| 482 | + " scenario\n" + |
| 483 | + " step\n" + |
| 484 | + " step\n" + |
| 485 | + " match\n" + |
| 486 | + " result\n" + |
| 487 | + " match\n" + |
| 488 | + " result\n" + |
| 489 | + " endOfScenarioLifeCycle\n" + |
| 490 | + " startOfScenarioLifeCycle\n" + |
| 491 | + " background\n" + |
| 492 | + " step\n" + |
| 493 | + " match\n" + |
| 494 | + " result\n" + |
| 495 | + " scenario\n" + |
| 496 | + " step\n" + |
| 497 | + " step\n" + |
| 498 | + " match\n" + |
| 499 | + " result\n" + |
| 500 | + " match\n" + |
| 501 | + " result\n" + |
| 502 | + " endOfScenarioLifeCycle\n" + |
| 503 | + " examples\n" + |
| 504 | + " startOfScenarioLifeCycle\n" + |
| 505 | + " background\n" + |
| 506 | + " step\n" + |
| 507 | + " match\n" + |
| 508 | + " result\n" + |
| 509 | + " scenario\n" + |
| 510 | + " step\n" + |
| 511 | + " step\n" + |
| 512 | + " match\n" + |
| 513 | + " result\n" + |
| 514 | + " match\n" + |
| 515 | + " result\n" + |
| 516 | + " endOfScenarioLifeCycle\n" + |
| 517 | + "eof\n" + |
| 518 | + "done\n" + |
| 519 | + "close\n", formatterOutput); |
| 520 | + } |
| 521 | + |
| 522 | + private String runFeatureWithFormatterSpy(CucumberFeature feature, Map<String, String> stepsToResult) throws Throwable { |
| 523 | + FormatterSpy formatterSpy = new FormatterSpy(); |
| 524 | + TestHelper.runFeatureWithFormatter(feature, stepsToResult, Collections.<SimpleEntry<String, String>>emptyList(), 0L, formatterSpy, formatterSpy); |
| 525 | + return formatterSpy.toString(); |
| 526 | + } |
| 527 | + |
394 | 528 | private StepDefinitionMatch createExceptionThrowingMatch(Exception exception) throws Throwable {
|
395 | 529 | StepDefinitionMatch match = mock(StepDefinitionMatch.class);
|
396 | 530 | doThrow(exception).when(match).runStep((I18n) any());
|
|
0 commit comments