Search in sources :

Example 66 with Story

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

the class GherkinStoryParserBehaviour method shouldParseStoryWithAlternativeNarrative.

@Test
public void shouldParseStoryWithAlternativeNarrative() throws IOException {
    String storyAsText = "Feature: Hello Car\n" + "Narrative:\n" + "As a car driver\n" + "I want to drive cars on 4 wheels\n" + "So that I can feel safer\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.asA(), equalTo("car driver"));
    assertThat(narrative.iWantTo(), equalTo("drive cars on 4 wheels"));
    assertThat(narrative.soThat(), equalTo("I can feel safer"));
}
Also used : Narrative(org.jbehave.core.model.Narrative) Story(org.jbehave.core.model.Story) Test(org.junit.Test)

Example 67 with Story

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

the class StoryManager method waitUntilAllDoneOrFailed.

public void waitUntilAllDoneOrFailed(RunContext context) {
    if (runningStories.values().isEmpty()) {
        return;
    }
    boolean allDone = false;
    boolean started = false;
    while (!allDone || !started) {
        allDone = true;
        for (RunningStory runningStory : runningStories.values()) {
            if (runningStory.isStarted()) {
                started = true;
                Story story = runningStory.getStory();
                Future<ThrowableStory> future = runningStory.getFuture();
                if (!future.isDone()) {
                    allDone = false;
                    StoryDuration duration = runningStory.getDuration();
                    runningStory.updateDuration();
                    if (duration.timedOut()) {
                        embedderMonitor.storyTimeout(story, duration);
                        context.cancelStory(story, duration);
                        future.cancel(true);
                        if (embedderControls.failOnStoryTimeout()) {
                            throw new StoryExecutionFailed(story.getPath(), new StoryTimedOut(duration));
                        }
                        continue;
                    }
                } else {
                    try {
                        ThrowableStory throwableStory = future.get();
                        Throwable throwable = throwableStory.getThrowable();
                        if (throwable != null) {
                            context.addFailure(story.getPath(), throwable);
                            if (!embedderControls.ignoreFailureInStories()) {
                                continue;
                            }
                        }
                    } catch (Throwable e) {
                        context.addFailure(story.getPath(), e);
                        if (!embedderControls.ignoreFailureInStories()) {
                            continue;
                        }
                    }
                }
            } else {
                started = false;
                allDone = false;
            }
        }
        tickTock();
    }
    writeStoryDurations(runningStories.values());
}
Also used : StoryDuration(org.jbehave.core.model.StoryDuration) Story(org.jbehave.core.model.Story)

Example 68 with Story

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

the class StoryRunner method runGivenStories.

private void runGivenStories(GivenStories givenStories, Map<String, String> parameters, RunContext context) throws Throwable {
    if (givenStories.getPaths().size() > 0) {
        reporter.get().givenStories(givenStories);
        for (GivenStory givenStory : givenStories.getStories()) {
            RunContext childContext = context.childContextFor(givenStory);
            // run given story, using any parameters provided
            Story story = storyOfPath(context.configuration(), childContext.path());
            if (givenStory.hasAnchorParameters()) {
                story = storyWithMatchingScenarios(story, givenStory.getAnchorParameters());
            }
            parameters.putAll(givenStory.getParameters());
            run(childContext, story, parameters);
        }
    }
}
Also used : GivenStory(org.jbehave.core.model.GivenStory) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story)

Example 69 with Story

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

the class Embedder method mapStoriesAsPaths.

public void mapStoriesAsPaths(List<String> storyPaths) {
    EmbedderControls embedderControls = embedderControls();
    embedderMonitor.usingControls(embedderControls);
    if (embedderControls.skip()) {
        embedderMonitor.storiesSkipped(storyPaths);
        return;
    }
    processSystemProperties();
    StoryManager storyManager = storyManager();
    for (String storyPath : storyPaths) {
        Story story = storyManager.storyOfPath(storyPath);
        embedderMonitor.mappingStory(storyPath, metaFilters());
        storyMapper.map(story, new MetaFilter("", embedderMonitor));
        for (String filter : metaFilters) {
            storyMapper.map(story, new MetaFilter(filter, embedderMonitor));
        }
    }
    generateMapsView(storyMapper.getStoryMaps());
}
Also used : Story(org.jbehave.core.model.Story)

Example 70 with Story

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

the class PerformableTree method performBeforeOrAfterStories.

public void performBeforeOrAfterStories(RunContext context, Stage stage) {
    String storyPath = StringUtils.capitalize(stage.name().toLowerCase()) + "Stories";
    context.currentPath(storyPath);
    context.reporter().beforeStory(new Story(storyPath), false);
    try {
        (stage == Stage.BEFORE ? root.beforeSteps : root.afterSteps).perform(context);
    } catch (InterruptedException e) {
        throw new UUIDExceptionWrapper(e);
    } finally {
        invokeDelayedReporters(context.reporter());
    }
    context.reporter().afterStory(false);
    invokeDelayedReporters(context.reporter());
}
Also used : GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper)

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