Search in sources :

Example 1 with Narrative

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

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

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

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

Example 5 with Narrative

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

the class RegexStoryParser method createNarrative.

private Narrative createNarrative(String narrative) {
    Matcher findingElements = findingNarrativeElements().matcher(narrative);
    if (findingElements.matches()) {
        String inOrderTo = findingElements.group(1).trim();
        String asA = findingElements.group(2).trim();
        String iWantTo = findingElements.group(3).trim();
        return new Narrative(inOrderTo, asA, iWantTo);
    }
    Matcher findingAlternativeElements = findingAlternativeNarrativeElements().matcher(narrative);
    if (findingAlternativeElements.matches()) {
        String asA = findingAlternativeElements.group(1).trim();
        String iWantTo = findingAlternativeElements.group(2).trim();
        String soThat = findingAlternativeElements.group(3).trim();
        return new Narrative("", asA, iWantTo, soThat);
    }
    return Narrative.EMPTY;
}
Also used : Matcher(java.util.regex.Matcher) Narrative(org.jbehave.core.model.Narrative)

Aggregations

Narrative (org.jbehave.core.model.Narrative)9 Story (org.jbehave.core.model.Story)8 Test (org.junit.Test)6 Description (org.jbehave.core.model.Description)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 GivenStory (org.jbehave.core.model.GivenStory)4 Scenario (org.jbehave.core.model.Scenario)3 Meta (org.jbehave.core.model.Meta)2 File (java.io.File)1 Matcher (java.util.regex.Matcher)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 OutcomesTable (org.jbehave.core.model.OutcomesTable)1 OutcomesFailed (org.jbehave.core.model.OutcomesTable.OutcomesFailed)1