Search in sources :

Example 21 with Scenario

use of org.jbehave.core.model.Scenario in project jbehave-core by jbehave.

the class RegexStoryParserBehaviour method shouldParseStoryWithScenarioContainingExamplesTable.

@Test
public void shouldParseStoryWithScenarioContainingExamplesTable() {
    String wholeStory = "Scenario: A scenario with examples table" + NL + NL + "Given a step with a <one>" + NL + "When I run the scenario of name <two>" + NL + "Then I should see <three> in the output" + NL + "Examples:" + NL + "|one|two|three|" + NL + "|11|12|13|" + NL + "|21|22|23|" + NL;
    Story story = parser.parseStory(wholeStory, storyPath);
    Scenario scenario = story.getScenarios().get(0);
    assertThat(scenario.getTitle(), equalTo("A scenario with examples table"));
    assertThat(scenario.getGivenStories().getPaths().size(), equalTo(0));
    assertThat(scenario.getSteps(), equalTo(asList("Given a step with a <one>", "When I run the scenario of name <two>", "Then I should see <three> in the output")));
    ExamplesTable table = scenario.getExamplesTable();
    assertThat(table.asString(), equalTo("|one|two|three|" + NL + "|11|12|13|" + NL + "|21|22|23|" + NL));
    assertThat(table.getRowCount(), equalTo(2));
    assertThat(table.getRow(0), not(nullValue()));
    assertThat(table.getRow(0).get("one"), equalTo("11"));
    assertThat(table.getRow(0).get("two"), equalTo("12"));
    assertThat(table.getRow(0).get("three"), equalTo("13"));
    assertThat(table.getRow(1), not(nullValue()));
    assertThat(table.getRow(1).get("one"), equalTo("21"));
    assertThat(table.getRow(1).get("two"), equalTo("22"));
    assertThat(table.getRow(1).get("three"), equalTo("23"));
}
Also used : ExamplesTable(org.jbehave.core.model.ExamplesTable) Matchers.containsString(org.hamcrest.Matchers.containsString) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Example 22 with Scenario

use of org.jbehave.core.model.Scenario in project jbehave-core by jbehave.

the class RegexStoryParserBehaviour method shouldParseStoryWithLifecycleAfterUponOutcomeAndMetaFilter.

@Test
public void shouldParseStoryWithLifecycleAfterUponOutcomeAndMetaFilter() {
    String wholeStory = "Lifecycle: " + NL + "After:" + NL + NL + "Outcome: ANY " + NL + "MetaFilter: +all" + NL + "Given a step after any scenario" + NL + "Outcome: SUCCESS " + NL + "MetaFilter: +happy" + NL + "Given a step after successful scenario" + NL + "Outcome: FAILURE " + NL + "MetaFilter: +sad" + NL + "Given a step after failed scenario" + NL + "Scenario:" + NL + "Given a scenario";
    Story story = parser.parseStory(wholeStory, storyPath);
    List<String> beforeSteps = story.getLifecycle().getBeforeSteps();
    assertThat(beforeSteps.isEmpty(), equalTo(true));
    Lifecycle lifecycle = story.getLifecycle();
    List<String> afterSteps = lifecycle.getAfterSteps();
    assertThat(afterSteps.get(0), equalTo("Given a step after any scenario"));
    assertThat(afterSteps.get(1), equalTo("Given a step after successful scenario"));
    assertThat(afterSteps.get(2), equalTo("Given a step after failed scenario"));
    assertThat(new ArrayList<>(lifecycle.getOutcomes()), equalTo(Arrays.asList(Outcome.ANY, Outcome.SUCCESS, Outcome.FAILURE)));
    assertThat(lifecycle.getAfterSteps(Outcome.ANY).size(), equalTo(1));
    assertThat(lifecycle.getAfterSteps(Outcome.ANY).get(0), equalTo("Given a step after any scenario"));
    assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS).size(), equalTo(1));
    assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS).get(0), equalTo("Given a step after successful scenario"));
    assertThat(lifecycle.getAfterSteps(Outcome.FAILURE).size(), equalTo(1));
    assertThat(lifecycle.getAfterSteps(Outcome.FAILURE).get(0), equalTo("Given a step after failed scenario"));
    assertThat(lifecycle.getMetaFilter(Outcome.ANY).asString(), equalTo("+all"));
    Keywords keywords = new Keywords();
    assertThat(lifecycle.getAfterSteps(Outcome.ANY, Meta.createMeta("@all", keywords)).size(), equalTo(1));
    assertThat(lifecycle.getAfterSteps(Outcome.ANY, Meta.createMeta("@all", keywords)).get(0), equalTo("Given a step after any scenario"));
    assertThat(lifecycle.getAfterSteps(Outcome.ANY, Meta.createMeta("@none", keywords)).size(), equalTo(0));
    assertThat(lifecycle.getMetaFilter(Outcome.SUCCESS).asString(), equalTo("+happy"));
    assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS, Meta.createMeta("@happy", keywords)).size(), equalTo(1));
    assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS, Meta.createMeta("@happy", keywords)).get(0), equalTo("Given a step after successful scenario"));
    assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS, Meta.createMeta("@none", keywords)).size(), equalTo(0));
    assertThat(lifecycle.getMetaFilter(Outcome.FAILURE).asString(), equalTo("+sad"));
    assertThat(lifecycle.getAfterSteps(Outcome.FAILURE, Meta.createMeta("@sad", keywords)).size(), equalTo(1));
    assertThat(lifecycle.getAfterSteps(Outcome.FAILURE, Meta.createMeta("@sad", keywords)).get(0), equalTo("Given a step after failed scenario"));
    assertThat(lifecycle.getAfterSteps(Outcome.FAILURE, Meta.createMeta("@none", keywords)).size(), equalTo(0));
    Scenario scenario = story.getScenarios().get(0);
    List<String> steps = scenario.getSteps();
    assertThat(steps.get(0), equalTo("Given a scenario"));
}
Also used : Keywords(org.jbehave.core.configuration.Keywords) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Lifecycle(org.jbehave.core.model.Lifecycle) Matchers.containsString(org.hamcrest.Matchers.containsString) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Example 23 with Scenario

use of org.jbehave.core.model.Scenario in project jbehave-core by jbehave.

the class RegexStoryParserBehaviour method shouldParseStoryWithLifecycleAfterUponOutcomeInNonEnglishLocale.

@Test
public void shouldParseStoryWithLifecycleAfterUponOutcomeInNonEnglishLocale() {
    String wholeStory = "Lebenszyklus: " + NL + "Nach:" + NL + NL + "Ergebnis: JEDES " + NL + "Gegeben im Lager sind 200 T-Shirts" + NL + "Ergebnis: ERFOLG " + NL + "Gegeben im Lager sind 300 T-Shirts" + NL + "Ergebnis: FEHLER " + NL + "Gegeben im Lager sind 400 T-Shirts" + NL + "Szenario:" + NL + "Wenn ein Kunde 20 T-Shirts bestellt";
    parser = new RegexStoryParser(new LocalizedKeywords(Locale.GERMAN), new LoadFromClasspath(), new TableTransformers());
    Story story = parser.parseStory(wholeStory, storyPath);
    List<String> beforeSteps = story.getLifecycle().getBeforeSteps();
    assertThat(beforeSteps.isEmpty(), equalTo(true));
    Lifecycle lifecycle = story.getLifecycle();
    List<String> afterSteps = lifecycle.getAfterSteps();
    assertThat(afterSteps.get(0), equalTo("Gegeben im Lager sind 200 T-Shirts"));
    assertThat(afterSteps.get(1), equalTo("Gegeben im Lager sind 300 T-Shirts"));
    assertThat(afterSteps.get(2), equalTo("Gegeben im Lager sind 400 T-Shirts"));
    assertThat(lifecycle.getAfterSteps(Outcome.ANY).size(), equalTo(1));
    assertThat(lifecycle.getAfterSteps(Outcome.ANY).get(0), equalTo("Gegeben im Lager sind 200 T-Shirts"));
    assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS).size(), equalTo(1));
    assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS).get(0), equalTo("Gegeben im Lager sind 300 T-Shirts"));
    assertThat(lifecycle.getAfterSteps(Outcome.FAILURE).size(), equalTo(1));
    assertThat(lifecycle.getAfterSteps(Outcome.FAILURE).get(0), equalTo("Gegeben im Lager sind 400 T-Shirts"));
    Scenario scenario = story.getScenarios().get(0);
    List<String> steps = scenario.getSteps();
    assertThat(steps.get(0), equalTo("Wenn ein Kunde 20 T-Shirts bestellt"));
}
Also used : LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) Lifecycle(org.jbehave.core.model.Lifecycle) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Matchers.containsString(org.hamcrest.Matchers.containsString) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) TableTransformers(org.jbehave.core.model.TableTransformers) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Example 24 with Scenario

use of org.jbehave.core.model.Scenario in project jbehave-core by jbehave.

the class RegexStoryParserBehaviour method shouldParseStoryWithScenarioTitleGivenStoriesAndStepsContainingKeywordsNotAtStartOfLine.

@Test
public void shouldParseStoryWithScenarioTitleGivenStoriesAndStepsContainingKeywordsNotAtStartOfLine() {
    String wholeStory = "Scenario: Show that we have Given/When/Then as part of description or step content" + NL + "GivenStories: GivenAStoryContainingAKeyword" + NL + "Given a scenario Given" + NL + "When I parse it to When" + NL + "And I parse it to And" + NL + "!-- And ignore me too" + NL + "Then I should get steps Then" + NL + "Examples:" + NL + "|Given|When|Then|And|" + NL + "|Dato che|Quando|Allora|E|" + NL + "|Dado que|Quando|Então|E|" + NL;
    Story story = parser.parseStory(wholeStory, storyPath);
    Scenario scenario = story.getScenarios().get(0);
    assertThat(scenario.getTitle(), equalTo("Show that we have Given/When/Then as part of description or step content"));
    assertThat(scenario.getGivenStories().getPaths(), equalTo(asList("GivenAStoryContainingAKeyword")));
    List<String> steps = scenario.getSteps();
    assertThat(steps.get(0), equalTo("Given a scenario Given"));
    assertThat(steps.get(1), equalTo("When I parse it to When"));
    assertThat(steps.get(2), equalTo("And I parse it to And"));
    assertThat(steps.get(3), equalTo("!-- And ignore me too"));
    assertThat(steps.get(4), equalTo("Then I should get steps Then"));
    assertThat(story.getScenarios().get(0).getExamplesTable().asString(), equalTo("|Given|When|Then|And|" + NL + "|Dato che|Quando|Allora|E|" + NL + "|Dado que|Quando|Então|E|" + NL));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Example 25 with Scenario

use of org.jbehave.core.model.Scenario in project jbehave-core by jbehave.

the class RegexStoryParserBehaviour method shouldParseStoryWithScenarioContainingParametrisedGivenStories.

@Test
public void shouldParseStoryWithScenarioContainingParametrisedGivenStories() {
    String wholeStory = "GivenStories: path/to/one#{0}, path/to/two#{1}, path/to/three#{2}, path/to/four#{a}, path/to/five" + NL + NL + "Given a step" + NL + "Examples:" + NL + "|one|two|" + NL + "|11|12|" + NL + "|21|22|";
    Story story = parser.parseStory(wholeStory, storyPath);
    Scenario scenario = story.getScenarios().get(0);
    GivenStories givenStories = scenario.getGivenStories();
    assertThat(givenStories.asString(), equalTo("path/to/one#{0}, path/to/two#{1}, path/to/three#{2}, path/to/four#{a}, path/to/five"));
    assertThat(givenStories.toString(), containsString(givenStories.asString()));
    assertThat(givenStories.getPaths(), equalTo(asList(// matches first parameters row
    "path/to/one#{0}", // matches second parameters row
    "path/to/two#{1}", // does not match any parameters row
    "path/to/three#{2}", // does not use valid anchor (an int)
    "path/to/four#{a}", // does not require parameters
    "path/to/five")));
    assertThat(givenStories.requireParameters(), equalTo(true));
    GivenStory givenStory1 = givenStories.getStories().get(0);
    assertThat(givenStory1.hasAnchor(), equalTo(true));
    assertThat(givenStory1.getAnchor(), equalTo("0"));
    assertThat(givenStory1.getPath(), equalTo("path/to/one"));
    assertThat(givenStory1.getParameters().get("one"), equalTo("11"));
    assertThat(givenStory1.getParameters().get("two"), equalTo("12"));
    GivenStory givenStory2 = givenStories.getStories().get(1);
    assertThat(givenStory2.hasAnchor(), equalTo(true));
    assertThat(givenStory2.getAnchor(), equalTo("1"));
    assertThat(givenStory2.getPath(), equalTo("path/to/two"));
    assertThat(givenStory2.getParameters().get("one"), equalTo("21"));
    assertThat(givenStory2.getParameters().get("two"), equalTo("22"));
    GivenStory givenStory3 = givenStories.getStories().get(2);
    assertThat(givenStory3.hasAnchor(), equalTo(true));
    assertThat(givenStory3.getAnchor(), equalTo("2"));
    assertThat(givenStory3.getPath(), equalTo("path/to/three"));
    assertThat(givenStory3.getParameters().size(), equalTo(0));
    GivenStory givenStory4 = givenStories.getStories().get(3);
    assertThat(givenStory4.hasAnchor(), equalTo(true));
    assertThat(givenStory4.getAnchor(), equalTo("a"));
    assertThat(givenStory4.getPath(), equalTo("path/to/four"));
    assertThat(givenStory4.getParameters().size(), equalTo(0));
    GivenStory givenStory5 = givenStories.getStories().get(4);
    assertThat(givenStory5.hasAnchor(), equalTo(false));
    assertThat(givenStory5.getAnchor(), equalTo(EMPTY));
    assertThat(givenStory5.getPath(), equalTo("path/to/five"));
    assertThat(givenStory5.getParameters().size(), equalTo(0));
}
Also used : GivenStories(org.jbehave.core.model.GivenStories) GivenStory(org.jbehave.core.model.GivenStory) Matchers.containsString(org.hamcrest.Matchers.containsString) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Aggregations

Scenario (org.jbehave.core.model.Scenario)35 Story (org.jbehave.core.model.Story)29 Test (org.junit.Test)27 Matchers.containsString (org.hamcrest.Matchers.containsString)20 GivenStory (org.jbehave.core.model.GivenStory)20 Meta (org.jbehave.core.model.Meta)9 ExamplesTable (org.jbehave.core.model.ExamplesTable)5 GivenStories (org.jbehave.core.model.GivenStories)5 Lifecycle (org.jbehave.core.model.Lifecycle)5 UUIDExceptionWrapper (org.jbehave.core.failures.UUIDExceptionWrapper)4 LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)3 Narrative (org.jbehave.core.model.Narrative)3 InOrder (org.mockito.InOrder)3 HashMap (java.util.HashMap)2 ExamplePerformableScenario (org.jbehave.core.embedder.PerformableTree.ExamplePerformableScenario)2 PerformableScenario (org.jbehave.core.embedder.PerformableTree.PerformableScenario)2 Description (org.jbehave.core.model.Description)2 OutcomesTable (org.jbehave.core.model.OutcomesTable)2 Description (org.junit.runner.Description)2 File (java.io.File)1