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);
}
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;
}
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();
}
}
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();
}
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"));
}
Aggregations