Skip to content

Commit

Permalink
extended tests to emulate new intended order of execution
Browse files Browse the repository at this point in the history
  • Loading branch information
SierraGolf committed Sep 26, 2013
1 parent 5ad8e17 commit 681bcef
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions java/src/test/java/gherkin/formatter/JSONFormatterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public void testAllStepsFirstOrderingOfCalls() {

jsonFormatter.uri(uri());
jsonFormatter.feature(feature);
jsonFormatter.startOfScenarioLifeCycle(scenario);
jsonFormatter.before(match(), result("passed"));
jsonFormatter.scenario(scenario);

Expand All @@ -97,6 +98,7 @@ public void testAllStepsFirstOrderingOfCalls() {
jsonFormatter.write(text2);
jsonFormatter.embedding("mime-type-2", data2);
jsonFormatter.result(step2Result);
jsonFormatter.endOfScenarioLifeCycle(scenario);

jsonFormatter.eof();
jsonFormatter.done();
Expand Down Expand Up @@ -138,6 +140,7 @@ public void testOneStepAtTheTimeOrderingOfCalls() {

jsonFormatter.uri(uri());
jsonFormatter.feature(feature);
jsonFormatter.startOfScenarioLifeCycle(scenario);
jsonFormatter.before(match(), result("passed"));
jsonFormatter.scenario(scenario);

Expand All @@ -152,6 +155,7 @@ public void testOneStepAtTheTimeOrderingOfCalls() {
jsonFormatter.write(text2);
jsonFormatter.embedding("mime-type-2", data2);
jsonFormatter.result(step2Result);
jsonFormatter.endOfScenarioLifeCycle(scenario);

jsonFormatter.eof();
jsonFormatter.done();
Expand Down Expand Up @@ -187,11 +191,15 @@ public void testBeforeHooks() {
jsonFormatter.uri(uri());
jsonFormatter.feature(feature);

jsonFormatter.startOfScenarioLifeCycle(scenario1);
jsonFormatter.before(match(), result("passed"));
jsonFormatter.scenario(scenario1);
jsonFormatter.endOfScenarioLifeCycle(scenario1);

jsonFormatter.startOfScenarioLifeCycle(scenario2);
jsonFormatter.before(match(), result("passed"));
jsonFormatter.scenario(scenario2);
jsonFormatter.endOfScenarioLifeCycle(scenario2);

jsonFormatter.eof();
jsonFormatter.done();
Expand Down
16 changes: 16 additions & 0 deletions java/src/test/java/gherkin/formatter/PrettyFormatterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public void shouldHandleAllStepCallsBeforeAnyMatchResultCalls() throws Exception
PrettyFormatter formatter = createMonochromePrettyFormatter(baos);
formatter.uri("test/resources/cucumber/examples/java/helloworld/helloworld.feature");
callFeature(formatter, "Hello World", 1);
callStartOfScenarioLifecycle(formatter, "Say hello", 3);
callScenario(formatter, "Say hello", 3);
callStep(formatter, "Given ", "I have a hello app with \"Howdy\"", 4);
callStep(formatter, "When ", "I ask it to say hi", 5);
Expand All @@ -163,6 +164,7 @@ public void shouldHandleAllStepCallsBeforeAnyMatchResultCalls() throws Exception
callResult(formatter, "passed");
callMatch(formatter, "HelloStepdefs.it_should_answer_with(String)", "Howdy World", 23);
callResult(formatter, "passed");
callEndOfScenarioLifecycle(formatter, "Say hello", 3);
formatter.eof();
formatter.done();
formatter.close();
Expand All @@ -184,6 +186,7 @@ public void shouldHandleInterleavedStepMatchResultCallsForScenario() throws Exce
PrettyFormatter formatter = createMonochromePrettyFormatter(baos);
formatter.uri("test/resources/cucumber/examples/java/helloworld/helloworld.feature");
callFeature(formatter, "Hello World", 1);
callStartOfScenarioLifecycle(formatter, "Say hello", 3);
callScenario(formatter, "Say hello", 3);
callStep(formatter, "Given ", "I have a hello app with \"Howdy\"", 4);
callMatch(formatter, "HelloStepdefs.I_have_a_hello_app_with(String)", "Howdy", 25);
Expand All @@ -194,6 +197,7 @@ public void shouldHandleInterleavedStepMatchResultCallsForScenario() throws Exce
callStep(formatter, "Then ", "it should answer with \"Howdy World\"", 6);
callMatch(formatter, "HelloStepdefs.it_should_answer_with(String)", "Howdy World", 23);
callResult(formatter, "passed");
callEndOfScenarioLifecycle(formatter, "Say hello", 3);
formatter.eof();
formatter.done();
formatter.close();
Expand All @@ -215,11 +219,13 @@ public void shouldTreatStepWithMatchCallsWithoutResultAsSkipped() throws Excepti
PrettyFormatter formatter = createColorPrettyFormatter(baos);
formatter.uri("path/name.feature");
callFeature(formatter, "A Feature", 1);
callStartOfScenarioLifecycle(formatter, "A Scenario", 3);
callScenario(formatter, "A Scenario", 3);
callStep(formatter, "* ", "First step", 4);
callMatch(formatter, "Stepdefs.First_step()");
callStep(formatter, "* ", "Second step", 5);
callMatch(formatter, "Stepdefs.Second_step()");
callEndOfScenarioLifecycle(formatter, "A Scenario", 3);
formatter.eof();
formatter.done();
formatter.close();
Expand All @@ -240,11 +246,13 @@ public void shouldHandleResultCallsWithoutMatchForScenario() throws Exception {
PrettyFormatter formatter = createColorPrettyFormatter(baos);
formatter.uri("path/name.feature");
callFeature(formatter, "A Feature", 1);
callStartOfScenarioLifecycle(formatter, "A Scenario", 3);
callScenario(formatter, "A Scenario", 3);
callStep(formatter, "* ", "First step", 4);
callResult(formatter, "undefined");
callStep(formatter, "* ", "Second step", 5);
callResult(formatter, "skipped");
callEndOfScenarioLifecycle(formatter, "A Scenario", 3);
formatter.eof();
formatter.done();
formatter.close();
Expand Down Expand Up @@ -337,6 +345,10 @@ private void callFeature(PrettyFormatter formatter, String name, int line) {
formatter.feature(new Feature(Collections.<Comment>emptyList(), Collections.<Tag>emptyList(), "Feature", name, "", line, ""));
}

private void callStartOfScenarioLifecycle(PrettyFormatter formatter, String name, int line) {
formatter.startOfScenarioLifeCycle(new Scenario(Collections.<Comment>emptyList(), Collections.<Tag>emptyList(), "Scenario", name, "", line, ""));
}

private void callScenario(PrettyFormatter formatter, String name, int line) {
formatter.scenario(new Scenario(Collections.<Comment>emptyList(), Collections.<Tag>emptyList(), "Scenario", name, "", line, ""));
}
Expand Down Expand Up @@ -364,6 +376,10 @@ private void callResult(PrettyFormatter formatter, String status, String errorMe
formatter.result(new Result(status, 0l, errorMessage));
}

private void callEndOfScenarioLifecycle(PrettyFormatter formatter, String name, int line) {
formatter.startOfScenarioLifeCycle(new Scenario(Collections.<Comment>emptyList(), Collections.<Tag>emptyList(), "Scenario", name, "", line, ""));
}

private void assertLineHasStatus(String line, String status) {
if ("undefined".equalsIgnoreCase(status)) {
assertThat(line, containsString(AnsiEscapes.YELLOW.toString()));
Expand Down

0 comments on commit 681bcef

Please sign in to comment.