use of org.jbehave.core.model.Story in project jbehave-core by jbehave.
the class RegexStoryParserBehaviour method shouldParseStoryWithMultilineSteps.
@Test
public void shouldParseStoryWithMultilineSteps() {
String wholeStory = "Given a scenario" + NL + "with this line" + NL + "When I parse it" + NL + "with another line" + NL + NL + "Then I should get steps" + NL + "without worrying about lines" + NL + "or extra white space between or after steps" + NL + NL;
Story story = parser.parseStory(wholeStory, storyPath);
List<String> steps = story.getScenarios().get(0).getSteps();
assertThat(steps.get(0), equalTo("Given a scenario" + NL + "with this line"));
assertThat(steps.get(1), equalTo("When I parse it" + NL + "with another line"));
assertThat(steps.get(2), equalTo("Then I should get steps" + NL + "without worrying about lines" + NL + "or extra white space between or after steps"));
}
use of org.jbehave.core.model.Story in project jbehave-core by jbehave.
the class TransformingStoryParserBehaviour method shouldTransformAndParseStory.
@Test
public void shouldTransformAndParseStory() {
StoryParser delegate = new RegexStoryParser(new LoadFromClasspath(), new TableTransformers());
StoryTransformer transformer = new StoryTransformer() {
@Override
public String transform(String storyAsText) {
return storyAsText.replaceAll(",", "|");
}
};
StoryParser parser = new TransformingStoryParser(delegate, transformer);
String storyAsText = "Scenario: a scenario " + NL + "Given a scenario Given" + NL + "When I parse it to When" + NL + "And I parse it to And" + NL + "!-- And ignore me too" + NL + "Then I should get steps Then" + NL + "Examples:" + NL + ",Given,When,Then,And," + NL + ",Dato che,Quando,Allora,E,";
Story story = parser.parseStory(storyAsText);
assertThat(story.getScenarios().get(0).getExamplesTable().getRowCount(), equalTo(1));
}
use of org.jbehave.core.model.Story 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.Story 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.Story 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;
}
Aggregations