Search in sources :

Example 56 with Story

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

the class RegexStoryParserBehaviour method shouldParseStoryWithMultilineSteps.

@Test
public void shouldParseStoryWithMultilineSteps() {
    String wholeStory = "Given a scenario" + NL + "with this line" + NL + "When I parse it" + NL + "with another line" + NL + NL + "Then I should get steps" + NL + "without worrying about lines" + NL + "or extra white space between or after steps" + NL + NL;
    Story story = parser.parseStory(wholeStory, storyPath);
    List<String> steps = story.getScenarios().get(0).getSteps();
    assertThat(steps.get(0), equalTo("Given a scenario" + NL + "with this line"));
    assertThat(steps.get(1), equalTo("When I parse it" + NL + "with another line"));
    assertThat(steps.get(2), equalTo("Then I should get steps" + NL + "without worrying about lines" + NL + "or extra white space between or after steps"));
}
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 57 with Story

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

the class TransformingStoryParserBehaviour method shouldTransformAndParseStory.

@Test
public void shouldTransformAndParseStory() {
    StoryParser delegate = new RegexStoryParser(new LoadFromClasspath(), new TableTransformers());
    StoryTransformer transformer = new StoryTransformer() {

        @Override
        public String transform(String storyAsText) {
            return storyAsText.replaceAll(",", "|");
        }
    };
    StoryParser parser = new TransformingStoryParser(delegate, transformer);
    String storyAsText = "Scenario: a scenario " + 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 + ",Given,When,Then,And," + NL + ",Dato che,Quando,Allora,E,";
    Story story = parser.parseStory(storyAsText);
    assertThat(story.getScenarios().get(0).getExamplesTable().getRowCount(), equalTo(1));
}
Also used : LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) Story(org.jbehave.core.model.Story) TableTransformers(org.jbehave.core.model.TableTransformers) Test(org.junit.Test)

Example 58 with Story

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

the class DelegatingStoryReporterBehaviour method shouldDelegateReporterEvents.

@Test
public void shouldDelegateReporterEvents() {
    // Given
    StoryReporter delegate = mock(StoryReporter.class);
    DelegatingStoryReporter delegator = new DelegatingStoryReporter(delegate);
    List<String> givenStoryPaths = asList("path/to/story1", "path/to/story2");
    GivenStories givenStories = new GivenStories(StringUtils.join(givenStoryPaths, ","));
    ExamplesTable examplesTable = new ExamplesTable("|one|two|\n|1|2|\n");
    UUIDExceptionWrapper anException = new UUIDExceptionWrapper(new IllegalArgumentException());
    Story story = new Story();
    boolean givenStory = false;
    Scenario scenario = new Scenario();
    String filter = "-some property";
    // When
    delegator.dryRun();
    delegator.beforeStory(story, givenStory);
    delegator.storyNotAllowed(story, filter);
    delegator.beforeScenario(scenario);
    delegator.beforeScenario("My scenario 1");
    delegator.scenarioNotAllowed(scenario, filter);
    delegator.scenarioMeta(Meta.EMPTY);
    delegator.givenStories(givenStoryPaths);
    delegator.givenStories(givenStories);
    delegator.successful("Given step 1.1");
    delegator.ignorable("!-- Then ignore me");
    delegator.comment("!-- comment");
    delegator.pending("When step 1.2");
    delegator.notPerformed("Then step 1.3");
    delegator.beforeExamples(asList("Given step <one>", "Then step <two>"), examplesTable);
    delegator.example(examplesTable.getRow(0));
    delegator.afterExamples();
    delegator.afterScenario();
    delegator.beforeScenario("My scenario 2");
    delegator.successful("Given step 2.1");
    delegator.successful("When step 2.2");
    delegator.failed("Then step 2.3", anException);
    delegator.afterScenario();
    delegator.afterStory(givenStory);
    // Then
    assertThat(delegator.toString(), containsString(delegate.toString()));
    InOrder inOrder = inOrder(delegate);
    inOrder.verify(delegate).dryRun();
    inOrder.verify(delegate).beforeStory(story, givenStory);
    inOrder.verify(delegate).storyNotAllowed(story, filter);
    inOrder.verify(delegate).beforeScenario(scenario);
    inOrder.verify(delegate).beforeScenario("My scenario 1");
    inOrder.verify(delegate).scenarioNotAllowed(scenario, filter);
    inOrder.verify(delegate).scenarioMeta(Meta.EMPTY);
    inOrder.verify(delegate).givenStories(givenStoryPaths);
    inOrder.verify(delegate).givenStories(givenStories);
    inOrder.verify(delegate).successful("Given step 1.1");
    inOrder.verify(delegate).ignorable("!-- Then ignore me");
    inOrder.verify(delegate).comment("!-- comment");
    inOrder.verify(delegate).pending("When step 1.2");
    inOrder.verify(delegate).notPerformed("Then step 1.3");
    inOrder.verify(delegate).beforeExamples(asList("Given step <one>", "Then step <two>"), examplesTable);
    inOrder.verify(delegate).example(examplesTable.getRow(0));
    inOrder.verify(delegate).afterExamples();
    inOrder.verify(delegate).afterScenario();
    inOrder.verify(delegate).beforeScenario("My scenario 2");
    inOrder.verify(delegate).successful("Given step 2.1");
    inOrder.verify(delegate).successful("When step 2.2");
    inOrder.verify(delegate).failed("Then step 2.3", anException);
    inOrder.verify(delegate).afterScenario();
    inOrder.verify(delegate).afterStory(givenStory);
}
Also used : GivenStories(org.jbehave.core.model.GivenStories) InOrder(org.mockito.InOrder) ExamplesTable(org.jbehave.core.model.ExamplesTable) Matchers.containsString(org.hamcrest.Matchers.containsString) Story(org.jbehave.core.model.Story) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Example 59 with Story

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

the class StoryMapperBehaviour method shouldMapStoriesAllowedByFilter.

@Test
public void shouldMapStoriesAllowedByFilter() throws Throwable {
    // Given
    Meta meta1 = mock(Meta.class, "meta1");
    Story story1 = new Story("/path/to/story1", Description.EMPTY, meta1, Narrative.EMPTY, asList(new Scenario("scenario1", meta1)));
    Meta meta2 = mock(Meta.class, "meta2");
    Story story2 = new Story("/path/to/story2", Description.EMPTY, meta2, Narrative.EMPTY, asList(new Scenario("scenario2", meta2)));
    MetaFilter filter = mock(MetaFilter.class);
    String filterAsString = "-some property";
    // When
    StoryMapper mapper = new StoryMapper();
    when(meta1.inheritFrom(meta1)).thenReturn(meta1);
    when(meta2.inheritFrom(meta2)).thenReturn(meta2);
    when(filter.allow(meta1)).thenReturn(false);
    when(filter.allow(meta2)).thenReturn(true);
    when(filter.asString()).thenReturn(filterAsString);
    mapper.map(story1, filter);
    mapper.map(story2, filter);
    // Then
    StoryMaps storyMaps = mapper.getStoryMaps();
    assertThat(storyMaps.getMaps().size(), equalTo(1));
    StoryMap storyMap = storyMaps.getMap(filterAsString);
    assertThat(storyMap.getMetaFilter(), equalTo(filterAsString));
    assertThat(storyMap.getStories().get(0).getPath(), equalTo(story2.getPath()));
    assertThat(storyMap.getStoryPaths(), equalTo(asList(story2.getPath())));
}
Also used : Meta(org.jbehave.core.model.Meta) StoryMap(org.jbehave.core.model.StoryMap) Story(org.jbehave.core.model.Story) StoryMaps(org.jbehave.core.model.StoryMaps) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Example 60 with Story

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

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