use of org.jbehave.core.model.ExamplesTable 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.ExamplesTable 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.ExamplesTable in project jbehave-core by jbehave.
the class RegexStoryParserBehaviour method shouldParseStoryWithScenarioContainingExamplesTable.
@Test
public void shouldParseStoryWithScenarioContainingExamplesTable() {
String wholeStory = "Scenario: A scenario with examples table" + NL + NL + "Given a step with a <one>" + NL + "When I run the scenario of name <two>" + NL + "Then I should see <three> in the output" + NL + "Examples:" + NL + "|one|two|three|" + NL + "|11|12|13|" + NL + "|21|22|23|" + NL;
Story story = parser.parseStory(wholeStory, storyPath);
Scenario scenario = story.getScenarios().get(0);
assertThat(scenario.getTitle(), equalTo("A scenario with examples table"));
assertThat(scenario.getGivenStories().getPaths().size(), equalTo(0));
assertThat(scenario.getSteps(), equalTo(asList("Given a step with a <one>", "When I run the scenario of name <two>", "Then I should see <three> in the output")));
ExamplesTable table = scenario.getExamplesTable();
assertThat(table.asString(), equalTo("|one|two|three|" + NL + "|11|12|13|" + NL + "|21|22|23|" + NL));
assertThat(table.getRowCount(), equalTo(2));
assertThat(table.getRow(0), not(nullValue()));
assertThat(table.getRow(0).get("one"), equalTo("11"));
assertThat(table.getRow(0).get("two"), equalTo("12"));
assertThat(table.getRow(0).get("three"), equalTo("13"));
assertThat(table.getRow(1), not(nullValue()));
assertThat(table.getRow(1).get("one"), equalTo("21"));
assertThat(table.getRow(1).get("two"), equalTo("22"));
assertThat(table.getRow(1).get("three"), equalTo("23"));
}
use of org.jbehave.core.model.ExamplesTable 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);
}
use of org.jbehave.core.model.ExamplesTable in project jbehave-core by jbehave.
the class RegexStoryParser method parseScenario.
private Scenario parseScenario(String scenarioAsText) {
String title = findScenarioTitle(scenarioAsText);
String scenarioWithoutKeyword = removeStart(scenarioAsText, keywords.scenario()).trim();
String scenarioWithoutTitle = removeStart(scenarioWithoutKeyword, title);
scenarioWithoutTitle = startingWithNL(scenarioWithoutTitle);
Meta meta = findScenarioMeta(scenarioWithoutTitle);
ExamplesTable examplesTable = findExamplesTable(scenarioWithoutTitle);
GivenStories givenStories = findScenarioGivenStories(scenarioWithoutTitle);
if (givenStories.requireParameters()) {
givenStories.useExamplesTable(examplesTable);
}
List<String> steps = findSteps(scenarioWithoutTitle);
return new Scenario(title, meta, givenStories, examplesTable, steps);
}
Aggregations