Search in sources :

Example 6 with Scenario

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

the class RegexStoryParserBehaviour method shouldParseStoryWithoutAPath.

@Test
public void shouldParseStoryWithoutAPath() {
    String wholeStory = "Given a step" + NL + "When I run it" + NL + "Then I should an output";
    Story story = parser.parseStory(wholeStory);
    assertThat(story.getPath(), equalTo(EMPTY));
    Scenario scenario = story.getScenarios().get(0);
    assertThat(scenario.getSteps(), equalTo(asList("Given a step", "When I run it", "Then I should an output")));
}
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 Scenario

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

the class RegexStoryParserBehaviour method parseStoryWithGivenStories.

private void parseStoryWithGivenStories(String wholeStory) {
    Story story = parser.parseStory(wholeStory, storyPath);
    Scenario scenario = story.getScenarios().get(0);
    assertThat(scenario.getGivenStories().getPaths(), equalTo(asList("path/to/one", "path/to/two")));
    assertThat(scenario.getSteps(), equalTo(asList("Given a step")));
}
Also used : GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) Scenario(org.jbehave.core.model.Scenario)

Example 8 with Scenario

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

the class RegexStoryParserBehaviour method shouldParseStoryWithGivenStoriesAndExamplesCommentedOut.

@Test
public void shouldParseStoryWithGivenStoriesAndExamplesCommentedOut() {
    String wholeStory = "Scenario: Show that we can comment out GivenStories and Examples portions of a scenario" + NL + "!-- GivenStories: AGivenStoryToBeCommented" + 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 + "|Comment|Me|Out|" + NL + "|yes|we|can|" + NL;
    Story story = parser.parseStory(wholeStory, storyPath);
    Scenario scenario = story.getScenarios().get(0);
    assertThat(scenario.getTitle(), equalTo("Show that we can comment out GivenStories and Examples portions of a scenario"));
    assertThat(scenario.getGivenStories().getPaths(), equalTo(Arrays.<String>asList()));
    List<String> steps = scenario.getSteps();
    assertThat(steps.get(0), equalTo("!-- GivenStories: AGivenStoryToBeCommented"));
    assertThat(steps.get(1), equalTo("Given a scenario Given"));
    assertThat(steps.get(2), equalTo("When I parse it to When"));
    assertThat(steps.get(3), equalTo("And I parse it to And"));
    assertThat(steps.get(4), equalTo("!-- And ignore me too"));
    assertThat(steps.get(5), equalTo("Then I should get steps Then"));
    assertThat(steps.get(6), equalTo("!-- Examples:" + NL + "|Comment|Me|Out|" + NL + "|yes|we|can|"));
    assertThat(scenario.getExamplesTable().asString(), equalTo(EMPTY));
}
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 9 with Scenario

use of org.jbehave.core.model.Scenario 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 10 with Scenario

use of org.jbehave.core.model.Scenario 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)

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