use of org.jbehave.core.model.Story 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"));
}
use of org.jbehave.core.model.Story 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));
}
use of org.jbehave.core.model.Story 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));
}
use of org.jbehave.core.model.Story in project jbehave-core by jbehave.
the class RegexStoryParserBehaviour method shouldParseStoryWithGivenStoriesAtStoryAndScenarioLevel.
@Test
public void shouldParseStoryWithGivenStoriesAtStoryAndScenarioLevel() {
String wholeStory = "GivenStories: GivenAPreconditionToStory" + NL + "Scenario:" + NL + "GivenStories: GivenAPreconditionToScenario" + NL + "Given a scenario Given";
Story story = parser.parseStory(wholeStory, storyPath);
assertThat(story.getGivenStories().getPaths(), equalTo(asList("GivenAPreconditionToStory")));
Scenario scenario = story.getScenarios().get(0);
assertThat(scenario.getGivenStories().getPaths(), equalTo(asList("GivenAPreconditionToScenario")));
List<String> steps = scenario.getSteps();
assertThat(steps.get(0), equalTo("Given a scenario Given"));
}
use of org.jbehave.core.model.Story in project jbehave-core by jbehave.
the class RegexStoryParserBehaviour method shouldParseStoryWithDescriptionAndNarrative.
@Test
public void shouldParseStoryWithDescriptionAndNarrative() {
String wholeStory = "Story: This is free-text description" + NL + "Narrative: This bit of text is ignored" + NL + "In order to renovate my house" + NL + "As a customer" + NL + "I want to get a loan" + NL + "Scenario: A first scenario";
Story story = parser.parseStory(wholeStory, storyPath);
Description description = story.getDescription();
assertThat(description.asString(), equalTo("Story: This is free-text description"));
Narrative narrative = story.getNarrative();
assertThat(narrative.isEmpty(), not(true));
assertThat(narrative.inOrderTo().toString(), equalTo("renovate my house"));
assertThat(narrative.asA().toString(), equalTo("customer"));
assertThat(narrative.iWantTo().toString(), equalTo("get a loan"));
}
Aggregations