Search in sources :

Example 6 with Story

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

the class RegexStoryParserBehaviour method shouldParseLongStory.

@Test
public void shouldParseLongStory() {
    String aGivenWhenThen = "Given a step" + NL + "When I run it" + NL + "Then I should seen an output" + NL;
    StringBuffer aScenario = new StringBuffer();
    aScenario.append("Scenario: A long scenario").append(NL);
    int numberOfGivenWhenThensPerScenario = 50;
    for (int i = 0; i < numberOfGivenWhenThensPerScenario; i++) {
        aScenario.append(aGivenWhenThen);
    }
    int numberOfScenarios = 100;
    StringBuffer wholeStory = new StringBuffer();
    wholeStory.append("Story: A very long story").append(NL);
    for (int i = 0; i < numberOfScenarios; i++) {
        wholeStory.append(aScenario).append(NL);
    }
    Story story = parser.parseStory(wholeStory.toString(), null);
    assertThat(story.getScenarios().size(), equalTo(numberOfScenarios));
    for (Scenario scenario : story.getScenarios()) {
        assertThat(scenario.getSteps().size(), equalTo(numberOfGivenWhenThensPerScenario * 3));
    }
}
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 7 with Story

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

the class RegexStoryParserBehaviour method shouldParseStoryWithLifecycleAfterUponOutcome.

@Test
public void shouldParseStoryWithLifecycleAfterUponOutcome() {
    String wholeStory = "Lifecycle: " + NL + "After:" + NL + NL + "Outcome: ANY " + NL + "Given a step after any scenario" + NL + "Outcome: SUCCESS " + NL + "Given a step after successful scenario" + NL + "Outcome: FAILURE " + 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(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"));
    Scenario scenario = story.getScenarios().get(0);
    List<String> steps = scenario.getSteps();
    assertThat(steps.get(0), equalTo("Given a scenario"));
}
Also used : 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 8 with Story

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

the class RegexStoryParserBehaviour method shouldParseStoryWithMetaAndNarrative.

@Test
public void shouldParseStoryWithMetaAndNarrative() {
    String wholeStory = "Meta: @skip @theme parsing" + 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 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));
    Narrative narrative = story.getNarrative();
    assertThat(narrative.isEmpty(), not(true));
    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) Narrative(org.jbehave.core.model.Narrative) 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 9 with Story

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

the class RegexStoryParserBehaviour method shouldParseStoryWithMultilineScenarioTitle.

@Test
public void shouldParseStoryWithMultilineScenarioTitle() {
    String wholeStory = "Scenario: A title\n that is spread across\n multiple lines" + NL + NL + "Given a step that's pending" + NL + "When I run the scenario" + NL + "Then I should see this in the output";
    Story story = parser.parseStory(wholeStory, null);
    assertThat(story.getScenarios().get(0).getTitle(), equalTo("A title\n that is spread across\n multiple lines"));
}
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 10 with Story

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

the class RegexStoryParserBehaviour method shouldParseStoryWithLifecycleBeforeOnly.

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

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