Search in sources :

Example 11 with Meta

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

the class BeforeOrAfterStepBehaviour method shouldPassMetaToStepCreatorWhenCreatingStepUponOutcomeWithMeta.

@Test
public void shouldPassMetaToStepCreatorWhenCreatingStepUponOutcomeWithMeta() throws Exception {
    StepCreator stepCreator = mock(StepCreator.class);
    Method method = methodFor("aMethodWith");
    BeforeOrAfterStep beforeOrAfterStep = new BeforeOrAfterStep(Stage.AFTER, method, stepCreator);
    Meta meta = mock(Meta.class);
    beforeOrAfterStep.createStepUponOutcome(meta);
    verify(stepCreator).createAfterStepUponOutcome(method, AfterScenario.Outcome.ANY, meta);
}
Also used : Meta(org.jbehave.core.model.Meta) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 12 with Meta

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

the class PerformableTree method performableScenario.

private PerformableScenario performableScenario(RunContext context, Story story, Map<String, String> storyParameters, FilteredStory filterContext, Meta storyMeta, boolean runBeforeAndAfterScenarioSteps, Scenario scenario) {
    PerformableScenario performableScenario = new PerformableScenario(scenario, story.getPath());
    // scenario also inherits meta from story
    boolean scenarioAllowed = true;
    if (failureOccurred(context) && context.configuration().storyControls().skipScenariosAfterFailure()) {
        return performableScenario;
    }
    if (!filterContext.allowed(scenario)) {
        scenarioAllowed = false;
    }
    performableScenario.allowed(scenarioAllowed);
    if (scenarioAllowed) {
        Lifecycle lifecycle = story.getLifecycle();
        Meta storyAndScenarioMeta = scenario.getMeta().inheritFrom(storyMeta);
        NormalPerformableScenario normalScenario = normalScenario(context, lifecycle, scenario, storyAndScenarioMeta, storyParameters);
        // run before scenario steps, if allowed
        if (runBeforeAndAfterScenarioSteps) {
            normalScenario.addBeforeSteps(context.beforeOrAfterScenarioSteps(storyAndScenarioMeta, Stage.BEFORE, ScenarioType.NORMAL));
        }
        if (isParameterisedByExamples(scenario)) {
            ExamplesTable table = scenario.getExamplesTable();
            for (Map<String, String> scenarioParameters : table.getRows()) {
                Meta exampleScenarioMeta = parameterMeta(context, scenarioParameters).inheritFrom(storyAndScenarioMeta);
                boolean exampleScenarioAllowed = context.filter().allow(exampleScenarioMeta);
                if (exampleScenarioAllowed) {
                    ExamplePerformableScenario exampleScenario = exampleScenario(context, lifecycle, scenario, storyAndScenarioMeta, scenarioParameters);
                    performableScenario.addExampleScenario(exampleScenario);
                }
            }
        } else {
            // plain old scenario
            performableScenario.useNormalScenario(normalScenario);
        }
        // after scenario steps, if allowed
        if (runBeforeAndAfterScenarioSteps) {
            normalScenario.addAfterSteps(context.beforeOrAfterScenarioSteps(storyAndScenarioMeta, Stage.AFTER, ScenarioType.NORMAL));
        }
    }
    return performableScenario;
}
Also used : Meta(org.jbehave.core.model.Meta) Lifecycle(org.jbehave.core.model.Lifecycle) ExamplesTable(org.jbehave.core.model.ExamplesTable)

Example 13 with Meta

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

the class StoryRunner method runCancellable.

private void runCancellable(RunContext context, Story story, Map<String, String> storyParameters) throws Throwable {
    if (!context.givenStory()) {
        reporter.set(reporterFor(context, story));
    }
    pendingStepStrategy.set(context.configuration().pendingStepStrategy());
    failureStrategy.set(context.configuration().failureStrategy());
    resetStoryFailure(context);
    if (context.dryRun()) {
        reporter.get().dryRun();
    }
    if (context.configuration().storyControls().resetStateBeforeStory()) {
        context.resetState();
    }
    // run before story steps, if any
    reporter.get().beforeStory(story, context.givenStory());
    boolean storyAllowed = true;
    FilteredStory filterContext = context.filter(story);
    Meta storyMeta = story.getMeta();
    if (!filterContext.allowed()) {
        reporter.get().storyNotAllowed(story, context.metaFilterAsString());
        storyAllowed = false;
    }
    if (storyAllowed) {
        reporter.get().narrative(story.getNarrative());
        runBeforeOrAfterStorySteps(context, story, Stage.BEFORE);
        addMetaParameters(storyParameters, storyMeta);
        runGivenStories(story.getGivenStories(), storyParameters, context);
        // determine if before and after scenario steps should be run
        boolean runBeforeAndAfterScenarioSteps = shouldRunBeforeOrAfterScenarioSteps(context);
        reporter.get().lifecyle(story.getLifecycle());
        for (Scenario scenario : story.getScenarios()) {
            // scenario also inherits meta from story
            boolean scenarioAllowed = true;
            if (failureOccurred(context) && context.configuration().storyControls().skipScenariosAfterFailure()) {
                continue;
            }
            reporter.get().beforeScenario(scenario);
            reporter.get().beforeScenario(scenario.getTitle());
            reporter.get().scenarioMeta(scenario.getMeta());
            if (!filterContext.allowed(scenario)) {
                reporter.get().scenarioNotAllowed(scenario, context.metaFilterAsString());
                scenarioAllowed = false;
            }
            if (scenarioAllowed) {
                if (context.configuration().storyControls().resetStateBeforeScenario()) {
                    context.resetState();
                }
                Meta storyAndScenarioMeta = scenario.getMeta().inheritFrom(storyMeta);
                // run before scenario steps, if allowed
                if (runBeforeAndAfterScenarioSteps) {
                    runBeforeOrAfterScenarioSteps(context, scenario, storyAndScenarioMeta, Stage.BEFORE, ScenarioType.NORMAL);
                }
                if (isParameterisedByExamples(scenario)) {
                    // run parametrised scenarios by examples
                    runScenariosParametrisedByExamples(context, scenario, story.getLifecycle(), storyAndScenarioMeta);
                } else {
                    // run as plain old scenario
                    runStepsWithLifecycle(context, story.getLifecycle(), storyParameters, scenario, storyAndScenarioMeta);
                }
                // run after scenario steps, if allowed
                if (runBeforeAndAfterScenarioSteps) {
                    runBeforeOrAfterScenarioSteps(context, scenario, storyAndScenarioMeta, Stage.AFTER, ScenarioType.NORMAL);
                }
            }
            reporter.get().afterScenario();
        }
        // run after story steps, if any
        runBeforeOrAfterStorySteps(context, story, Stage.AFTER);
    }
    reporter.get().afterStory(context.givenStory());
    // handle any failure according to strategy
    if (!context.givenStory()) {
        handleStoryFailureByStrategy();
    }
}
Also used : Meta(org.jbehave.core.model.Meta) Scenario(org.jbehave.core.model.Scenario)

Example 14 with Meta

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

the class StoryRunner method runScenariosParametrisedByExamples.

private void runScenariosParametrisedByExamples(RunContext context, Scenario scenario, Lifecycle lifecycle, Meta storyAndScenarioMeta) throws Throwable {
    ExamplesTable table = scenario.getExamplesTable();
    reporter.get().beforeExamples(scenario.getSteps(), table);
    Keywords keywords = context.configuration().keywords();
    for (Map<String, String> scenarioParameters : table.getRows()) {
        Meta parameterMeta = parameterMeta(keywords, scenarioParameters);
        if (!parameterMeta.isEmpty() && !context.filter.allow(parameterMeta)) {
            continue;
        }
        reporter.get().example(scenarioParameters);
        if (context.configuration().storyControls().resetStateBeforeScenario()) {
            context.resetState();
        }
        runBeforeOrAfterScenarioSteps(context, scenario, storyAndScenarioMeta, Stage.BEFORE, ScenarioType.EXAMPLE);
        runStepsWithLifecycle(context, lifecycle, scenarioParameters, scenario, storyAndScenarioMeta);
        runBeforeOrAfterScenarioSteps(context, scenario, storyAndScenarioMeta, Stage.AFTER, ScenarioType.EXAMPLE);
    }
    reporter.get().afterExamples();
}
Also used : Meta(org.jbehave.core.model.Meta) Keywords(org.jbehave.core.configuration.Keywords) ExamplesTable(org.jbehave.core.model.ExamplesTable)

Example 15 with Meta

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

the class RegexStoryParserBehaviour method shouldAllowSpacesInMetaProperties.

@Test
public void shouldAllowSpacesInMetaProperties() {
    String wholeStory = "Meta: @ theme parsing @ skip" + NL + "Scenario: " + NL + "Meta: @authors Mauro Paul" + NL + "Given a scenario " + NL + "When I parse it" + NL + "Then I should get steps";
    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(story.getScenarios().get(0).getMeta().getProperty("authors"), equalTo("Mauro Paul"));
}
Also used : Meta(org.jbehave.core.model.Meta) Matchers.containsString(org.hamcrest.Matchers.containsString) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) Test(org.junit.Test)

Aggregations

Meta (org.jbehave.core.model.Meta)32 Test (org.junit.Test)23 Story (org.jbehave.core.model.Story)11 Scenario (org.jbehave.core.model.Scenario)9 Matchers.containsString (org.hamcrest.Matchers.containsString)8 HashMap (java.util.HashMap)6 Properties (java.util.Properties)6 GivenStory (org.jbehave.core.model.GivenStory)6 RegexStepMatcher (org.jbehave.core.parsers.RegexStepMatcher)6 StepMatcher (org.jbehave.core.parsers.StepMatcher)6 Silent (org.jbehave.core.steps.AbstractStepResult.Silent)6 ParametrisedStep (org.jbehave.core.steps.StepCreator.ParametrisedStep)6 Map (java.util.Map)4 PendingStep (org.jbehave.core.steps.StepCreator.PendingStep)4 Matchers.anyString (org.mockito.Matchers.anyString)4 ScenarioType (org.jbehave.core.annotations.ScenarioType)3 ExamplesTable (org.jbehave.core.model.ExamplesTable)3 Lifecycle (org.jbehave.core.model.Lifecycle)3 BytecodeReadingParanamer (com.thoughtworks.paranamer.BytecodeReadingParanamer)2 CachingParanamer (com.thoughtworks.paranamer.CachingParanamer)2