use of org.jbehave.core.Embeddable in project jbehave-core by jbehave.
the class EmbedderBehaviour method shouldThrowExceptionUponFailingStoriesAsEmbeddablesInBatchIfIgnoreFailureInStoriesFlagIsNotSet.
@Test(expected = RunningEmbeddablesFailed.class)
public void shouldThrowExceptionUponFailingStoriesAsEmbeddablesInBatchIfIgnoreFailureInStoriesFlagIsNotSet() throws Throwable {
// Given
PerformableTree performableTree = mock(PerformableTree.class);
EmbedderControls embedderControls = new EmbedderControls().doBatch(true);
OutputStream out = new ByteArrayOutputStream();
EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
String myStoryName = MyStory.class.getName();
String myOtherStoryName = MyOtherEmbeddable.class.getName();
List<String> classNames = asList(myStoryName, myOtherStoryName);
Embeddable myStory = new MyFailingEmbeddable();
Embeddable myOtherStory = new MyOtherEmbeddable();
EmbedderClassLoader classLoader = mock(EmbedderClassLoader.class);
when(classLoader.newInstance(Embeddable.class, myStoryName)).thenReturn(myStory);
when(classLoader.newInstance(Embeddable.class, myOtherStoryName)).thenReturn(myOtherStory);
// When
Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
embedder.useClassLoader(classLoader);
embedder.runAsEmbeddables(classNames);
// Then fail as expected
}
use of org.jbehave.core.Embeddable in project jbehave-core by jbehave.
the class EmbedderBehaviour method shouldRunStoriesAsEmbeddables.
@Test
public void shouldRunStoriesAsEmbeddables() throws Throwable {
// Given
PerformableTree performableTree = mock(PerformableTree.class);
EmbedderControls embedderControls = new EmbedderControls();
OutputStream out = new ByteArrayOutputStream();
EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
String myEmbeddableName = MyEmbeddable.class.getName();
String myOtherEmbeddableName = MyOtherEmbeddable.class.getName();
List<String> classNames = asList(myEmbeddableName, myOtherEmbeddableName);
Embeddable myEmbeddable = new MyEmbeddable();
Embeddable myOtherEmbeddable = new MyOtherEmbeddable();
List<Embeddable> embeddables = asList(myEmbeddable, myOtherEmbeddable);
EmbedderClassLoader classLoader = mock(EmbedderClassLoader.class);
when(classLoader.newInstance(Embeddable.class, myEmbeddableName)).thenReturn(myEmbeddable);
when(classLoader.newInstance(Embeddable.class, myOtherEmbeddableName)).thenReturn(myOtherEmbeddable);
// When
Configuration configuration = new MostUsefulConfiguration();
CandidateSteps steps = mock(CandidateSteps.class);
Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
embedder.useClassLoader(classLoader);
embedder.useConfiguration(configuration);
embedder.useCandidateSteps(asList(steps));
embedder.runAsEmbeddables(classNames);
// Then
for (Embeddable embeddable : embeddables) {
assertThat(out.toString(), containsString("Running embeddable " + embeddable.getClass().getName()));
}
}
use of org.jbehave.core.Embeddable in project jbehave-core by jbehave.
the class Embedder method reportStepdocsAsEmbeddables.
public void reportStepdocsAsEmbeddables(List<String> classNames) {
EmbedderControls embedderControls = embedderControls();
if (embedderControls.skip()) {
embedderMonitor.embeddablesSkipped(classNames);
return;
}
for (Embeddable embeddable : embeddables(classNames, classLoader())) {
if (embeddable instanceof ConfigurableEmbedder) {
ConfigurableEmbedder configurableEmbedder = (ConfigurableEmbedder) embeddable;
Embedder configuredEmbedder = configurableEmbedder.configuredEmbedder();
List<CandidateSteps> steps = configuredEmbedder.candidateSteps();
if (steps.isEmpty()) {
steps = configuredEmbedder.stepsFactory().createCandidateSteps();
}
reportStepdocs(configuredEmbedder.configuration(), steps);
} else {
embedderMonitor.embeddableNotConfigurable(embeddable.getClass().getName());
}
}
}
use of org.jbehave.core.Embeddable in project jbehave-core by jbehave.
the class EmbedderBehaviour method shouldNotThrowExceptionUponFailingStoriesAsEmbeddablesIfIgnoreFailureFlagsAreSet.
@Test
public void shouldNotThrowExceptionUponFailingStoriesAsEmbeddablesIfIgnoreFailureFlagsAreSet() throws Throwable {
// Given
PerformableTree performableTree = mock(PerformableTree.class);
EmbedderControls embedderControls = new EmbedderControls().doIgnoreFailureInStories(true).doIgnoreFailureInView(true);
OutputStream out = new ByteArrayOutputStream();
EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
String myEmbeddableName = MyFailingEmbeddable.class.getName();
String myOtherEmbeddableName = MyOtherEmbeddable.class.getName();
List<String> classNames = asList(myEmbeddableName, myOtherEmbeddableName);
Embeddable myEmbeddable = new MyFailingEmbeddable();
Embeddable myOtherEmbeddable = new MyOtherEmbeddable();
EmbedderClassLoader classLoader = mock(EmbedderClassLoader.class);
when(classLoader.newInstance(Embeddable.class, myEmbeddableName)).thenReturn(myEmbeddable);
when(classLoader.newInstance(Embeddable.class, myOtherEmbeddableName)).thenReturn(myOtherEmbeddable);
// When
Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
embedder.useClassLoader(classLoader);
embedder.runAsEmbeddables(classNames);
// Then
assertThat(out.toString(), containsString("Running embeddable " + myEmbeddableName));
assertThat(out.toString(), containsString("Failed to run embeddable " + myEmbeddableName));
assertThat(out.toString(), containsString("Running embeddable " + myOtherEmbeddableName));
assertThat(out.toString(), not(containsString("Failed to run embeddable " + myOtherEmbeddableName)));
}
use of org.jbehave.core.Embeddable in project jbehave-core by jbehave.
the class EmbedderBehaviour method shouldNotGenerateViewWhenRunningStoriesAsEmbeddablesIfGenerateViewAfterStoriesFlagIsNotSet.
@Test
public void shouldNotGenerateViewWhenRunningStoriesAsEmbeddablesIfGenerateViewAfterStoriesFlagIsNotSet() throws Throwable {
// Given
PerformableTree performableTree = mock(PerformableTree.class);
EmbedderControls embedderControls = new EmbedderControls().doGenerateViewAfterStories(false);
OutputStream out = new ByteArrayOutputStream();
EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
String myEmbeddableName = MyEmbeddable.class.getName();
String myOtherEmbeddableName = MyOtherEmbeddable.class.getName();
List<String> classNames = asList(myEmbeddableName, myOtherEmbeddableName);
Embeddable myEmbeddable = new MyEmbeddable();
Embeddable myOtherEmbeddable = new MyOtherEmbeddable();
List<Embeddable> embeddables = asList(myEmbeddable, myOtherEmbeddable);
EmbedderClassLoader classLoader = mock(EmbedderClassLoader.class);
when(classLoader.newInstance(Embeddable.class, myEmbeddableName)).thenReturn(myEmbeddable);
when(classLoader.newInstance(Embeddable.class, myOtherEmbeddableName)).thenReturn(myOtherEmbeddable);
// When
Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
embedder.useClassLoader(classLoader);
embedder.runAsEmbeddables(classNames);
// Then
for (Embeddable embeddable : embeddables) {
assertThat(out.toString(), containsString("Running embeddable " + embeddable.getClass().getName()));
}
assertThat(out.toString(), not(containsString("Generating stories view")));
}
Aggregations