Search in sources :

Example 1 with Description

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

the class RegexStoryParserBehaviour method shouldParseStoryWithIncompleteNarrative.

@Test
public void shouldParseStoryWithIncompleteNarrative() {
    String wholeStory = "Story: This is free-text description" + NL + "Narrative: This is an incomplete narrative" + NL + "In order to renovate my house" + NL + "As a customer" + NL + "Scenario:  A first scenario";
    Story story = parser.parseStory(wholeStory, storyPath);
    Description description = story.getDescription();
    assertThat(description.asString(), equalTo("Story: This is free-text description"));
    Narrative narrative = story.getNarrative();
    assertThat(narrative.isEmpty(), is(true));
}
Also used : Description(org.jbehave.core.model.Description) Narrative(org.jbehave.core.model.Narrative) Matchers.containsString(org.hamcrest.Matchers.containsString) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) Test(org.junit.Test)

Example 2 with Description

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

the class PostStoryStatisticsCollectorBehaviour method narrateAnInterestingStory.

private void narrateAnInterestingStory() {
    Story story = new Story("/path/to/story", new Description("An interesting story"), new Narrative("renovate my house", "customer", "get a loan"), new ArrayList<Scenario>());
    reporter.dryRun();
    // begin story
    reporter.beforeStory(story, false);
    // 1st scenario
    reporter.beforeScenario(new Scenario("I ask for a loan", Meta.EMPTY));
    reporter.givenStories(asList("path/to/story1", "path/to/story2"));
    // 1st given story
    reporter.beforeStory(story, true);
    reporter.beforeScenario(new Scenario("a scenario without steps", Meta.EMPTY));
    reporter.afterScenario();
    reporter.afterStory(true);
    // 2nd given story
    reporter.beforeStory(story, true);
    reporter.beforeScenario(new Scenario("the bank has $300 to loan", Meta.EMPTY));
    reporter.givenStories(asList("path/to/nested/story1"));
    reporter.beforeStory(story, true);
    reporter.beforeScenario(new Scenario("initialise static", Meta.EMPTY));
    reporter.successful("the bank has customers");
    reporter.afterScenario();
    reporter.afterStory(true);
    reporter.afterScenario();
    reporter.afterStory(true);
    reporter.successful("Given I have a balance of $50");
    reporter.ignorable("!-- Then ignore me");
    reporter.comment("!-- A comment");
    reporter.successful("When I request $20");
    reporter.successful("When I ask Liz for a loan of $100");
    reporter.afterScenario();
    // 2nd scenario
    reporter.beforeScenario(new Scenario("A failing scenario", Meta.EMPTY));
    OutcomesTable outcomesTable = new OutcomesTable();
    outcomesTable.addOutcome("I don't return all", 100.0, equalTo(50.));
    try {
        outcomesTable.verify();
    } catch (UUIDExceptionWrapper e) {
        reporter.failedOutcomes("Then I don't return loan", ((OutcomesFailed) e.getCause()).outcomesTable());
    }
    reporter.notPerformed("Then I should have $20");
    ExamplesTable table = new ExamplesTable("|money|to|\n|$30|Mauro|\n|$50|Paul|\n");
    reporter.beforeExamples(asList("Given money <money>", "Then I give it to <to>"), table);
    reporter.example(table.getRow(0));
    reporter.example(table.getRow(1));
    reporter.afterExamples();
    reporter.afterScenario();
    // 3rd scenario
    reporter.beforeScenario(new Scenario("A pending scenario", Meta.EMPTY));
    reporter.pending("When I have some money");
    reporter.notPerformed("Then I should have $20");
    reporter.afterScenario();
    // end story
    reporter.afterStory(false);
}
Also used : Description(org.jbehave.core.model.Description) OutcomesFailed(org.jbehave.core.model.OutcomesTable.OutcomesFailed) Narrative(org.jbehave.core.model.Narrative) ExamplesTable(org.jbehave.core.model.ExamplesTable) Story(org.jbehave.core.model.Story) OutcomesTable(org.jbehave.core.model.OutcomesTable) Scenario(org.jbehave.core.model.Scenario) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper)

Example 3 with Description

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

the class RegexStoryParserBehaviour method shouldParseStoryWithAlternativeNarrative.

@Test
public void shouldParseStoryWithAlternativeNarrative() {
    String wholeStory = "Story: This is free-text description" + NL + "Narrative: This is an alternative narrative" + NL + "As a customer" + NL + "I want to get a loan" + NL + "So that I can renovate my house" + NL + "Scenario:  A first scenario";
    Story story = parser.parseStory(wholeStory, storyPath);
    Description description = story.getDescription();
    assertThat(description.asString(), equalTo("Story: This is free-text description"));
    Narrative narrative = story.getNarrative();
    assertThat(narrative.isEmpty(), not(true));
    assertThat(narrative.asA().toString(), equalTo("customer"));
    assertThat(narrative.iWantTo().toString(), equalTo("get a loan"));
    assertThat(narrative.soThat().toString(), equalTo("I can renovate my house"));
}
Also used : Description(org.jbehave.core.model.Description) Narrative(org.jbehave.core.model.Narrative) Matchers.containsString(org.hamcrest.Matchers.containsString) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) Test(org.junit.Test)

Example 4 with Description

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

the class RegexStoryParserBehaviour method shouldParseStoryWithDescriptionAndNarrative.

@Test
public void shouldParseStoryWithDescriptionAndNarrative() {
    String wholeStory = "Story: This is free-text description" + 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 first scenario";
    Story story = parser.parseStory(wholeStory, storyPath);
    Description description = story.getDescription();
    assertThat(description.asString(), equalTo("Story: This is free-text description"));
    Narrative narrative = story.getNarrative();
    assertThat(narrative.isEmpty(), not(true));
    assertThat(narrative.inOrderTo().toString(), equalTo("renovate my house"));
    assertThat(narrative.asA().toString(), equalTo("customer"));
    assertThat(narrative.iWantTo().toString(), equalTo("get a loan"));
}
Also used : Description(org.jbehave.core.model.Description) Narrative(org.jbehave.core.model.Narrative) Matchers.containsString(org.hamcrest.Matchers.containsString) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) Test(org.junit.Test)

Example 5 with Description

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

the class RegexStoryParser method parseStory.

public Story parseStory(String storyAsText, String storyPath) {
    Description description = parseDescriptionFrom(storyAsText);
    Meta meta = parseStoryMetaFrom(storyAsText);
    Narrative narrative = parseNarrativeFrom(storyAsText);
    GivenStories givenStories = parseGivenStories(storyAsText);
    Lifecycle lifecycle = parseLifecycle(storyAsText);
    List<Scenario> scenarios = parseScenariosFrom(storyAsText);
    Story story = new Story(storyPath, description, meta, narrative, givenStories, lifecycle, scenarios);
    if (storyPath != null) {
        story.namedAs(new File(storyPath).getName());
    }
    return story;
}
Also used : GivenStories(org.jbehave.core.model.GivenStories) Meta(org.jbehave.core.model.Meta) Description(org.jbehave.core.model.Description) Narrative(org.jbehave.core.model.Narrative) Lifecycle(org.jbehave.core.model.Lifecycle) Story(org.jbehave.core.model.Story) File(java.io.File) Scenario(org.jbehave.core.model.Scenario)

Aggregations

Description (org.jbehave.core.model.Description)5 Narrative (org.jbehave.core.model.Narrative)5 Story (org.jbehave.core.model.Story)5 Matchers.containsString (org.hamcrest.Matchers.containsString)3 GivenStory (org.jbehave.core.model.GivenStory)3 Test (org.junit.Test)3 Scenario (org.jbehave.core.model.Scenario)2 File (java.io.File)1 UUIDExceptionWrapper (org.jbehave.core.failures.UUIDExceptionWrapper)1 ExamplesTable (org.jbehave.core.model.ExamplesTable)1 GivenStories (org.jbehave.core.model.GivenStories)1 Lifecycle (org.jbehave.core.model.Lifecycle)1 Meta (org.jbehave.core.model.Meta)1 OutcomesTable (org.jbehave.core.model.OutcomesTable)1 OutcomesFailed (org.jbehave.core.model.OutcomesTable.OutcomesFailed)1