Search in sources :

Example 16 with Story

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

the class RegexStoryParserBehaviour method shouldParseStoryWithAllElements.

@Test
public void shouldParseStoryWithAllElements() {
    String wholeStory = "This is just a story description" + NL + NL + "Narrative: " + NL + "In order to see what we're not delivering" + NL + NL + "As a developer" + NL + "I want to see the narrative for my story when a scenario in that story breaks" + NL + "GivenStories: path1,path2" + NL + NL + "Lifecycle: " + NL + "Before: " + NL + NL + "Given a setup step" + NL + "After: " + NL + NL + "Then a teardown step" + NL + "Scenario: A pending scenario" + NL + NL + "Given a step that's pending" + NL + "When I run the scenario" + NL + "!-- A comment between steps" + NL + "Then I should see this in the output" + NL + "Scenario: A passing scenario" + NL + "Given I'm not reporting passing stories" + NL + "When I run the scenario" + NL + "Then this should not be in the output" + NL + "Scenario: A failing scenario" + NL + "Given a step that fails" + NL + "When I run the scenario" + NL + "Then I should see this in the output" + NL + "And I should see this in the output" + NL;
    Story story = parser.parseStory(wholeStory, storyPath);
    assertThat(story.toString(), containsString("This is just a story description"));
    assertThat(story.getDescription().asString(), equalTo("This is just a story description"));
    assertThat(story.toString(), containsString("Narrative"));
    assertThat(story.getNarrative().inOrderTo(), equalTo("see what we're not delivering"));
    assertThat(story.getNarrative().asA(), equalTo("developer"));
    assertThat(story.getNarrative().iWantTo(), equalTo("see the narrative for my story when a scenario in that story breaks"));
    assertThat(story.getGivenStories().getPaths(), hasItem("path1"));
    assertThat(story.getGivenStories().getPaths(), hasItem("path2"));
    assertThat(story.toString(), containsString("Lifecycle"));
    assertThat(story.getLifecycle().getBeforeSteps().size(), equalTo(1));
    assertThat(story.getLifecycle().getBeforeSteps(), hasItem("Given a setup step"));
    assertThat(story.getLifecycle().getAfterSteps().size(), equalTo(1));
    assertThat(story.getLifecycle().getAfterSteps(), hasItem("Then a teardown step"));
    Meta storyAsMeta = story.asMeta("story_");
    assertThat(storyAsMeta.getProperty("story_path"), equalTo(story.getPath()));
    assertThat(storyAsMeta.getProperty("story_description"), equalTo(story.getDescription().asString()));
    assertThat(storyAsMeta.getProperty("story_narrative"), equalTo(story.getNarrative().toString()));
    assertThat(story.toString(), containsString("A pending scenario"));
    Scenario firstScenario = story.getScenarios().get(0);
    assertThat(firstScenario.getTitle(), equalTo("A pending scenario"));
    assertThat(firstScenario.getGivenStories().getPaths().size(), equalTo(0));
    assertThat(firstScenario.getSteps(), equalTo(asList("Given a step that's pending", "When I run the scenario", "!-- A comment between steps", "Then I should see this in the output")));
    Meta scenarioAsMeta = firstScenario.asMeta("scenario_");
    assertThat(scenarioAsMeta.getProperty("scenario_title"), equalTo(firstScenario.getTitle()));
    assertThat(scenarioAsMeta.getProperty("scenario_givenStories"), equalTo(firstScenario.getGivenStories().asString()));
    assertThat(scenarioAsMeta.getProperty("scenario_examplesTable"), equalTo(firstScenario.getExamplesTable().asString()));
    assertThat(story.toString(), containsString("A passing scenario"));
    Scenario secondScenario = story.getScenarios().get(1);
    assertThat(secondScenario.getTitle(), equalTo("A passing scenario"));
    assertThat(secondScenario.getGivenStories().getPaths().size(), equalTo(0));
    assertThat(secondScenario.getSteps(), equalTo(asList("Given I'm not reporting passing stories", "When I run the scenario", "Then this should not be in the output")));
    assertThat(story.toString(), containsString("A failing scenario"));
    Scenario thirdScenario = story.getScenarios().get(2);
    assertThat(thirdScenario.getTitle(), equalTo("A failing scenario"));
    assertThat(thirdScenario.getGivenStories().getPaths().size(), equalTo(0));
    assertThat(thirdScenario.getSteps(), equalTo(asList("Given a step that fails", "When I run the scenario", "Then I should see this in the output", "And I should see this in the output")));
}
Also used : Meta(org.jbehave.core.model.Meta) 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 17 with Story

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

the class RegexStoryParserBehaviour method shouldParseStoryWithMetaAndGivenStories.

@Test
public void shouldParseStoryWithMetaAndGivenStories() {
    String wholeStory = "Meta: @skip @theme parsing" + NL + "GivenStories: path1,path2 " + NL + "Scenario: A scenario" + NL + "Meta: @author Mauro" + NL + "Given a step " + NL + "Scenario: Another scenario" + NL + "Meta: @author Paul" + NL + "Given another step ";
    Story story = parser.parseStory(wholeStory, storyPath);
    assertThat(story.getPath(), equalTo(storyPath));
    Meta storyMeta = story.getMeta();
    assertThat(storyMeta.getProperty("theme"), equalTo("parsing"));
    assertThat(storyMeta.getProperty("skip"), equalTo(EMPTY));
    assertThat(storyMeta.getProperty("unknown"), equalTo(EMPTY));
    assertThat(story.getGivenStories().getPaths(), equalTo(asList("path1", "path2")));
    List<Scenario> scenarios = story.getScenarios();
    assertThat(scenarios.get(0).getTitle(), equalTo("A scenario"));
    assertThat(scenarios.get(0).getMeta().getProperty("author"), equalTo("Mauro"));
    assertThat(scenarios.get(1).getTitle(), equalTo("Another scenario"));
    assertThat(scenarios.get(1).getMeta().getProperty("author"), equalTo("Paul"));
}
Also used : Meta(org.jbehave.core.model.Meta) 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 18 with Story

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

the class RegexStoryParserBehaviour method shouldParseWithMultipleScenarios.

@Test
public void shouldParseWithMultipleScenarios() {
    String wholeStory = "Scenario: the first scenario " + NL + NL + "Given my scenario" + NL + NL + "Scenario: the second scenario" + NL + NL + "Given my second scenario";
    Story story = parser.parseStory(wholeStory, storyPath);
    assertThat(story.getScenarios().get(0).getTitle(), equalTo("the first scenario"));
    assertThat(story.getScenarios().get(0).getSteps(), equalTo(asList("Given my scenario")));
    assertThat(story.getScenarios().get(1).getTitle(), equalTo("the second scenario"));
    assertThat(story.getScenarios().get(1).getSteps(), equalTo(asList("Given my second scenario")));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) Test(org.junit.Test)

Example 19 with Story

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

the class RegexStoryParserBehaviour method shouldParseStoryWithSimpleSteps.

@Test
public void shouldParseStoryWithSimpleSteps() {
    String wholeStory = "Given a scenario" + NL + "!-- ignore me" + NL + "When I parse it" + NL + "Then I should get steps";
    Story story = parser.parseStory(wholeStory, storyPath);
    assertThat(story.getPath(), equalTo(storyPath));
    List<String> steps = story.getScenarios().get(0).getSteps();
    assertThat(steps.get(0), equalTo("Given a scenario"));
    assertThat(steps.get(1), equalTo("!-- ignore me"));
    assertThat(steps.get(2), equalTo("When I parse it"));
    assertThat(steps.get(3), equalTo("Then I should get steps"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) Test(org.junit.Test)

Example 20 with Story

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

the class RegexStoryParserBehaviour method shouldParseStoryWithSynonymsOfStartingWords.

@Test
public void shouldParseStoryWithSynonymsOfStartingWords() {
    StoryParser parser = new RegexStoryParser(new LocalizedKeywords(new Locale("sy")));
    String wholeStory = "Given a scenario" + NL + "When I parse it" + NL + "And I parse it again" + NL + "With another parse as well" + NL + "!-- ignore me" + NL + "Giveth another scenario" + NL + "With a merry go round";
    Story story = parser.parseStory(wholeStory, storyPath);
    List<String> steps = story.getScenarios().get(0).getSteps();
    assertThat(steps.get(0), equalTo("Given a scenario"));
    assertThat(steps.get(1), equalTo("When I parse it"));
    assertThat(steps.get(2), equalTo("And I parse it again"));
    assertThat(steps.get(3), equalTo("With another parse as well"));
    assertThat(steps.get(4), equalTo("!-- ignore me"));
    assertThat(steps.get(5), equalTo("Giveth another scenario"));
    assertThat(steps.get(6), equalTo("With a merry go round"));
}
Also used : Locale(java.util.Locale) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Matchers.containsString(org.hamcrest.Matchers.containsString) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) Test(org.junit.Test)

Aggregations

Story (org.jbehave.core.model.Story)71 Test (org.junit.Test)58 Matchers.containsString (org.hamcrest.Matchers.containsString)41 GivenStory (org.jbehave.core.model.GivenStory)39 Scenario (org.jbehave.core.model.Scenario)29 Meta (org.jbehave.core.model.Meta)11 HashMap (java.util.HashMap)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 PrintStream (java.io.PrintStream)9 ArrayList (java.util.ArrayList)9 JUnitStory (org.jbehave.core.junit.JUnitStory)9 OutputStream (java.io.OutputStream)8 InjectableEmbedder (org.jbehave.core.InjectableEmbedder)8 UsingEmbedder (org.jbehave.core.annotations.UsingEmbedder)8 Configuration (org.jbehave.core.configuration.Configuration)8 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)8 BatchFailures (org.jbehave.core.failures.BatchFailures)8 StoryPathResolver (org.jbehave.core.io.StoryPathResolver)8 Narrative (org.jbehave.core.model.Narrative)8 RunContext (org.jbehave.core.embedder.PerformableTree.RunContext)7