use of org.jbehave.core.configuration.MostUsefulConfiguration in project jbehave-core by jbehave.
the class EmbedderBehaviour method shouldRunStoriesAsPaths.
@SuppressWarnings("unchecked")
@Test
public void shouldRunStoriesAsPaths() throws Throwable {
// Given
PerformableTree performableTree = mock(PerformableTree.class);
EmbedderControls embedderControls = new EmbedderControls();
EmbedderMonitor embedderMonitor = mock(EmbedderMonitor.class);
OutputStream out = new ByteArrayOutputStream();
EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
List<? extends Class<? extends Embeddable>> embeddables = asList(MyStory.class, MyOtherEmbeddable.class);
Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
InjectableStepsFactory stepsFactory = embedder.stepsFactory();
MetaFilter filter = embedder.metaFilter();
final StoryReporter storyReporter = mock(StoryReporter.class);
MostUsefulConfiguration configuration = new MostUsefulConfiguration() {
@Override
public StoryReporter storyReporter(String storyPath) {
return storyReporter;
}
};
embedder.useConfiguration(configuration);
StoryPathResolver resolver = configuration.storyPathResolver();
List<String> storyPaths = new ArrayList<>();
Map<String, Story> stories = new HashMap<>();
for (Class<? extends Embeddable> embeddable : embeddables) {
String storyPath = resolver.resolve(embeddable);
storyPaths.add(storyPath);
Story story = mockStory(Meta.EMPTY);
stories.put(storyPath, story);
when(performableTree.storyOfPath(configuration, storyPath)).thenReturn(story);
when(story.getPath()).thenReturn(storyPath);
assertThat(configuration.storyReporter(storyPath), sameInstance(storyReporter));
}
RunContext runContext = new RunContext(configuration, stepsFactory, embedderMonitor, filter, new BatchFailures());
when(performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(EmbedderMonitor.class), isA(MetaFilter.class), isA(BatchFailures.class))).thenReturn(runContext);
// When
embedder.runStoriesAsPaths(storyPaths);
// Then
for (String storyPath : storyPaths) {
verify(performableTree).perform(Matchers.isA(RunContext.class), Matchers.eq(stories.get(storyPath)));
assertThat(out.toString(), containsString("Running story " + storyPath));
}
assertThatReportsViewGenerated(out);
}
use of org.jbehave.core.configuration.MostUsefulConfiguration in project jbehave-core by jbehave.
the class StoryManagerBehaviour method shouldEnsureStoryReportOutputDirectoryExistsWhenWritingStoryDurations.
@Test
public void shouldEnsureStoryReportOutputDirectoryExistsWhenWritingStoryDurations() throws IOException {
Configuration configuration = new MostUsefulConfiguration();
configuration.storyReporterBuilder().withRelativeDirectory("inexistent");
File outputDirectory = configuration.storyReporterBuilder().outputDirectory();
FileUtils.deleteDirectory(outputDirectory);
assertThat(outputDirectory.exists(), is(false));
StoryManager manager = new StoryManager(configuration, stepsFactory, embedderControls, embedderMonitor, executorService, performableTree);
Collection<RunningStory> runningStories = new ArrayList<>();
manager.writeStoryDurations(runningStories);
assertThat(outputDirectory.exists(), is(true));
}
use of org.jbehave.core.configuration.MostUsefulConfiguration in project jbehave-core by jbehave.
the class ConfigurableEmbedderBehaviour method shouldAllowOverrideOfDefaultConfiguration.
@Test
public void shouldAllowOverrideOfDefaultConfiguration() throws Throwable {
// Given
Embedder embedder = mock(Embedder.class);
Configuration configuration = mock(Configuration.class);
StoryPathResolver pathResolver = mock(StoryPathResolver.class);
when(embedder.configuration()).thenReturn(configuration);
when(configuration.storyPathResolver()).thenReturn(pathResolver);
Class<MyStory> storyClass = MyStory.class;
String storyPath = "/path/to/story";
when(pathResolver.resolve(storyClass)).thenReturn(storyPath);
CandidateSteps steps = mock(CandidateSteps.class);
// When
MyStory story = new MyStory(new MostUsefulConfiguration(), steps);
assertThat(story.configuration(), is(not(sameInstance(configuration))));
story.useConfiguration(configuration);
assertThat(story.configuration(), is(sameInstance(configuration)));
story.useEmbedder(embedder);
story.run();
// Then
verify(embedder).useConfiguration(configuration);
verify(embedder).useCandidateSteps(Mockito.eq(Arrays.asList(steps)));
verify(embedder).runStoriesAsPaths(asList(storyPath));
}
use of org.jbehave.core.configuration.MostUsefulConfiguration in project jbehave-core by jbehave.
the class StepCreatorBehaviour method shouldHandleTargetInvocationFailureInBeforeOrAfterStep.
@Test
public void shouldHandleTargetInvocationFailureInBeforeOrAfterStep() throws IntrospectionException {
// Given
SomeSteps stepsInstance = new SomeSteps();
MostUsefulConfiguration configuration = new MostUsefulConfiguration();
InjectableStepsFactory stepsFactory = new InstanceStepsFactory(configuration, stepsInstance);
StepCreator stepCreator = new StepCreator(stepsInstance.getClass(), stepsFactory, stepsContext, configuration.parameterConverters(), new ParameterControls(), null, new SilentStepMonitor());
// When
Method method = SomeSteps.methodFor("aFailingBeforeScenarioMethod");
StepResult stepResult = stepCreator.createBeforeOrAfterStep(method, Meta.EMPTY).perform(null);
// Then
assertThat(stepResult, instanceOf(Failed.class));
assertThat(stepResult.getFailure(), instanceOf(UUIDExceptionWrapper.class));
Throwable cause = stepResult.getFailure().getCause();
assertThat(cause, instanceOf(BeforeOrAfterFailed.class));
assertThat(cause.getMessage(), org.hamcrest.Matchers.equalTo("Method aFailingBeforeScenarioMethod (annotated with @BeforeScenario in class org.jbehave.core.steps.SomeSteps) failed: java.lang.RuntimeException"));
}
use of org.jbehave.core.configuration.MostUsefulConfiguration in project jbehave-core by jbehave.
the class StepCreatorBehaviour method shouldDescribeStepToReporterBeforeExecutingParametrisedStep.
@Test
public void shouldDescribeStepToReporterBeforeExecutingParametrisedStep() throws IntrospectionException {
// Given
SomeSteps stepsInstance = new SomeSteps();
InjectableStepsFactory stepsFactory = new InstanceStepsFactory(new MostUsefulConfiguration(), stepsInstance);
StepCreator stepCreator = new StepCreator(stepsInstance.getClass(), stepsFactory, stepsContext, null, new ParameterControls(), null, new SilentStepMonitor());
StoryReporter storyReporter = mock(StoryReporter.class);
// When
Method method = SomeSteps.methodFor("aMethod");
((ParametrisedStep) stepCreator.createParametrisedStep(method, "When I run", "I run", null)).describeTo(storyReporter);
// Then
verify(storyReporter).beforeStep("When I run");
}
Aggregations