use of org.jbehave.core.model.Scenario 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())));
}
use of org.jbehave.core.model.Scenario 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);
}
use of org.jbehave.core.model.Scenario 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;
}
use of org.jbehave.core.model.Scenario in project jbehave-core by jbehave.
the class SilentSuccessFilterBehaviour method shouldNotPassSilentlyOutputNotAllowedByMetaFilter.
@Test
public void shouldNotPassSilentlyOutputNotAllowedByMetaFilter() {
// Given
Story story = new Story();
Scenario scenario = new Scenario();
String metaFilter = "";
// When
filter.storyNotAllowed(story, metaFilter);
filter.scenarioNotAllowed(scenario, metaFilter);
// Then
InOrder inOrder = inOrder(delegate);
inOrder.verify(delegate).storyNotAllowed(story, metaFilter);
inOrder.verify(delegate).scenarioNotAllowed(scenario, metaFilter);
}
use of org.jbehave.core.model.Scenario in project jbehave-core by jbehave.
the class PerformableTree method performableStory.
private PerformableStory performableStory(RunContext context, Story story, Map<String, String> storyParameters) {
PerformableStory performableStory = new PerformableStory(story, context.configuration().keywords(), context.givenStory());
// determine if story is allowed
boolean storyAllowed = true;
FilteredStory filteredStory = context.filter(story);
Meta storyMeta = story.getMeta();
if (!filteredStory.allowed()) {
storyAllowed = false;
}
performableStory.allowed(storyAllowed);
if (storyAllowed) {
performableStory.addBeforeSteps(context.beforeOrAfterStorySteps(story, Stage.BEFORE));
performableStory.addBeforeSteps(context.lifecycleSteps(story.getLifecycle(), storyMeta, Stage.BEFORE, Scope.STORY));
// determine if before and after scenario steps should be run
boolean runBeforeAndAfterScenarioSteps = shouldRunBeforeOrAfterScenarioSteps(context);
for (Scenario scenario : story.getScenarios()) {
Map<String, String> scenarioParameters = new HashMap<>(storyParameters);
PerformableScenario performableScenario = performableScenario(context, story, scenarioParameters, filteredStory, storyMeta, runBeforeAndAfterScenarioSteps, scenario);
if (performableScenario.hasNormalScenario() || performableScenario.hasExamples()) {
performableStory.add(performableScenario);
}
}
// Add Given stories only if story contains scenarios
if (!performableStory.getScenarios().isEmpty()) {
Map<String, String> givenStoryParameters = new HashMap<>(storyParameters);
addMetaParameters(givenStoryParameters, storyMeta);
if (story.hasGivenStories()) {
performableStory.addGivenStories(performableGivenStories(context, story.getGivenStories(), givenStoryParameters));
}
}
performableStory.addAfterSteps(context.lifecycleSteps(story.getLifecycle(), storyMeta, Stage.AFTER, Scope.STORY));
performableStory.addAfterSteps(context.beforeOrAfterStorySteps(story, Stage.AFTER));
}
return performableStory;
}
Aggregations