Search in sources :

Example 51 with Story

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

the class RegexStoryParserBehaviour method shouldParseStoryWithMetaAndLifecycle.

@Test
public void shouldParseStoryWithMetaAndLifecycle() {
    String wholeStory = "Meta: @skip @theme parsing" + NL + "Lifecycle:" + NL + "Before:" + NL + "Given a step before each scenario" + NL + "And another before step" + 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));
    Lifecycle lifecycle = story.getLifecycle();
    assertThat(lifecycle.getBeforeSteps().size(), equalTo(2));
    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) 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 52 with Story

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

the class RegexStoryParserBehaviour method shouldParseStoryWithLifecycleAndMultipleScopes.

@Test
public void shouldParseStoryWithLifecycleAndMultipleScopes() {
    String wholeStory = "Lifecycle: " + NL + "Before:" + NL + NL + "Scope: SCENARIO" + NL + "Given a step before each scenario" + NL + "And another before scenario" + NL + "Scope: STORY" + NL + "Given a step before each story" + NL + "And another before story" + NL + "After:" + NL + NL + "Scope: STORY" + NL + "Given a step after each story" + NL + "And another after story" + NL + "Scope: SCENARIO" + NL + "Given a step after each scenario" + NL + "And another after scenario" + NL + "Scenario:" + NL + "Given a scenario";
    Story story = parser.parseStory(wholeStory, storyPath);
    assertThat(story.getLifecycle().hasBeforeSteps(), is(true));
    List<String> beforeStorySteps = story.getLifecycle().getBeforeSteps(Scope.STORY);
    assertThat(beforeStorySteps.get(0), equalTo("Given a step before each story"));
    assertThat(beforeStorySteps.get(1), equalTo("And another before story"));
    List<String> beforeScenarioSteps = story.getLifecycle().getBeforeSteps(Scope.SCENARIO);
    assertThat(beforeScenarioSteps.get(0), equalTo("Given a step before each scenario"));
    assertThat(beforeScenarioSteps.get(1), equalTo("And another before scenario"));
    assertThat(story.getLifecycle().hasAfterSteps(), is(true));
    List<String> afterStorySteps = story.getLifecycle().getAfterSteps(Scope.STORY);
    assertThat(afterStorySteps.get(0), equalTo("Given a step after each story"));
    assertThat(afterStorySteps.get(1), equalTo("And another after story"));
    List<String> afterScenarioSteps = story.getLifecycle().getAfterSteps(Scope.SCENARIO);
    assertThat(afterScenarioSteps.get(0), equalTo("Given a step after each scenario"));
    assertThat(afterScenarioSteps.get(1), equalTo("And another after scenario"));
    Scenario scenario = story.getScenarios().get(0);
    List<String> steps = scenario.getSteps();
    assertThat(steps.get(0), equalTo("Given a scenario"));
}
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 53 with Story

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

the class RegexStoryParserBehaviour method shouldParseStoryAndProvideNameFromPath.

@Test
public void shouldParseStoryAndProvideNameFromPath() {
    Story story = parser.parseStory(EMPTY, storyPath);
    assertThat(story.getPath(), equalTo(storyPath));
    assertThat(story.getName(), equalTo(new File(storyPath).getName()));
}
Also used : GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) File(java.io.File) Test(org.junit.Test)

Example 54 with Story

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

the class RegexStoryParserBehaviour method shouldParseStoryWithLifecycleAfterOnly.

@Test
public void shouldParseStoryWithLifecycleAfterOnly() {
    String wholeStory = "Lifecycle: " + NL + "After:" + NL + NL + "Given a step after each scenario" + NL + "And another after step" + NL + "Scenario:" + NL + "Given a scenario";
    Story story = parser.parseStory(wholeStory, storyPath);
    List<String> beforeSteps = story.getLifecycle().getBeforeSteps();
    assertThat(beforeSteps.isEmpty(), equalTo(true));
    List<String> afterSteps = story.getLifecycle().getAfterSteps();
    assertThat(afterSteps.get(0), equalTo("Given a step after each scenario"));
    assertThat(afterSteps.get(1), equalTo("And another after step"));
    Scenario scenario = story.getScenarios().get(0);
    List<String> steps = scenario.getSteps();
    assertThat(steps.get(0), equalTo("Given a scenario"));
}
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 55 with Story

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

the class RegexStoryParserBehaviour method shouldParseStoryWithGivenStoriesWithAnchorParameters.

@Test
public void shouldParseStoryWithGivenStoriesWithAnchorParameters() {
    String wholeStory = "GivenStories: path1#{id1:scenario1;id2:scenario2}" + NL + "Scenario: A scenario" + NL + "Given a step";
    Story story = parser.parseStory(wholeStory, storyPath);
    assertThat(story.getPath(), equalTo(storyPath));
    assertThat(story.getGivenStories().getStories().size(), equalTo(1));
    GivenStory givenStory = story.getGivenStories().getStories().get(0);
    assertThat(givenStory.hasAnchorParameters(), equalTo(true));
    Map<String, String> anchorParameters = givenStory.getAnchorParameters();
    assertThat(anchorParameters.size(), equalTo(2));
    assertThat(anchorParameters.get("id1"), equalTo("scenario1"));
    assertThat(anchorParameters.get("id2"), equalTo("scenario2"));
}
Also used : GivenStory(org.jbehave.core.model.GivenStory) 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