Search in sources :

Example 26 with Story

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

the class MarkUnmatchedStepsAsPendingBehaviour method shouldInvokeBeforeOrAfterStoryWithParameterAndException.

@Test
public void shouldInvokeBeforeOrAfterStoryWithParameterAndException() throws Exception {
    BeforeOrAfterStoryWithParameterAndExceptionSteps steps = new BeforeOrAfterStoryWithParameterAndExceptionSteps();
    Story story = mock(Story.class);
    when(story.getMeta()).thenReturn(beforeAndAfterMeta());
    List<Step> beforeSteps = stepCollector.collectBeforeOrAfterStorySteps(asList((CandidateSteps) steps), story, Stage.BEFORE, false);
    UUIDExceptionWrapper failureOccurred = new UUIDExceptionWrapper();
    beforeSteps.get(0).doNotPerform(failureOccurred);
    assertThat(steps.value, equalTo("before"));
    assertThat(steps.exception, equalTo(failureOccurred));
    List<Step> afterSteps = stepCollector.collectBeforeOrAfterStorySteps(asList((CandidateSteps) steps), story, Stage.AFTER, false);
    failureOccurred = new UUIDExceptionWrapper();
    afterSteps.get(0).doNotPerform(failureOccurred);
    assertThat(steps.value, equalTo("after"));
    assertThat(steps.exception, equalTo(failureOccurred));
}
Also used : PendingStep(org.jbehave.core.steps.StepCreator.PendingStep) Story(org.jbehave.core.model.Story) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) Test(org.junit.Test)

Example 27 with Story

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

the class GherkinStoryParserBehaviour method shouldParseStoryWithTabularParameter.

@Test
public void shouldParseStoryWithTabularParameter() throws IOException {
    String storyAsText = "Feature: Hello Car\n" + "Scenario: Car can drive\n" + "Given I have a car\n" + "Then I can drive them according to:\n" + "| wheels | can_drive |\n" + "| 1 | false |\n" + "| 2 | false |\n" + "| 3 | false |\n" + "| 4 | true |\n";
    Story story = storyParser.parseStory(storyAsText);
    assertThat(story.getDescription().asString(), equalTo("Hello Car"));
    List<Scenario> scenarios = story.getScenarios();
    assertThat(scenarios.size(), equalTo(1));
    Scenario scenario = scenarios.get(0);
    List<String> steps = scenario.getSteps();
    assertThat(scenario.getTitle(), equalTo("Car can drive"));
    assertThat(steps.size(), equalTo(2));
    assertThat(steps.get(0), equalTo("Given I have a car"));
    assertThat(steps.get(1), equalTo("Then I can drive them according to:\n" + "|wheels|can_drive|\n" + "|1|false|\n" + "|2|false|\n" + "|3|false|\n" + "|4|true|"));
}
Also used : Story(org.jbehave.core.model.Story) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Example 28 with Story

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

the class GherkinStoryParserBehaviour method shouldParseStoryWithTags.

@Test
public void shouldParseStoryWithTags() throws IOException {
    String storyAsText = "@feature\n" + "Feature: Hello Car\n\n" + "Background:\n" + "Given I have a license\n\n" + "@scenario\n" + "Scenario: Car can drive\n" + "Given I have a car with 4 wheels\n" + "Then I can drive it.\n";
    Story story = storyParser.parseStory(storyAsText);
    assertThat(story.getDescription().asString(), equalTo("Hello Car"));
    assertThat(story.getMeta().hasProperty("feature"), Matchers.is(true));
    Scenario scenario = story.getScenarios().get(0);
    assertThat(scenario.getSteps().size(), equalTo(2));
    assertThat(scenario.getMeta().hasProperty("scenario"), Matchers.is(true));
}
Also used : Story(org.jbehave.core.model.Story) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Example 29 with Story

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

the class GherkinStoryParserBehaviour method shouldParseStoryWithExamples.

@Test
public void shouldParseStoryWithExamples() throws IOException {
    String storyAsText = "Feature: Hello Car\n" + "@scenarioOutline\n" + "Scenario Outline: Car can drive\n" + "Given I have a car\n" + "When I add <wheels>\n" + "Then It <can_drive>\n" + "\n" + "Examples:\n" + "| wheels | can_drive |\n" + "| 1 | false |\n" + "| 2 | false |\n" + "| 3 | false |\n" + "| 4 | true |";
    Story story = storyParser.parseStory(storyAsText);
    assertThat(story.getDescription().asString(), equalTo("Hello Car"));
    List<Scenario> scenarios = story.getScenarios();
    assertThat(scenarios.size(), equalTo(1));
    Scenario scenario = scenarios.get(0);
    List<String> steps = scenario.getSteps();
    assertThat(scenario.getTitle(), equalTo("Car can drive"));
    assertThat(scenario.getMeta().hasProperty("scenarioOutline"), Matchers.is(true));
    assertThat(steps.size(), equalTo(3));
    assertThat(steps.get(0), equalTo("Given I have a car"));
    assertThat(steps.get(1), equalTo("When I add <wheels>"));
    assertThat(steps.get(2), equalTo("Then It <can_drive>"));
    assertThat(scenario.getExamplesTable().asString(), equalTo("|wheels|can_drive|\n" + "|1|false|\n" + "|2|false|\n" + "|3|false|\n" + "|4|true|\n"));
}
Also used : Story(org.jbehave.core.model.Story) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Example 30 with Story

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

the class GherkinStoryParserBehaviour method shouldParseStoryWithNarrative.

@Test
public void shouldParseStoryWithNarrative() throws IOException {
    String storyAsText = "Feature: Hello Car\n" + "Narrative:\n" + "In order to feel safer\n" + "As a car driver\n" + "I want to drive cars on 4 wheels\n" + "Scenario: Car can drive\n" + "Given I have a car with 4 wheels\n" + "Then I can drive it.\n";
    Story story = storyParser.parseStory(storyAsText);
    assertThat(story.getDescription().asString(), equalTo("Hello Car"));
    Narrative narrative = story.getNarrative();
    assertThat(narrative.inOrderTo(), equalTo("feel safer"));
    assertThat(narrative.asA(), equalTo("car driver"));
    assertThat(narrative.iWantTo(), equalTo("drive cars on 4 wheels"));
}
Also used : Narrative(org.jbehave.core.model.Narrative) 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