Search in sources :

Example 11 with CandidateSteps

use of org.jbehave.core.steps.CandidateSteps in project jbehave-core by jbehave.

the class EmbedderBehaviour method shouldReportNoMatchingStepdocsFoundWithStepProvided.

@Test
public void shouldReportNoMatchingStepdocsFoundWithStepProvided() {
    // Given
    Embedder embedder = new Embedder();
    embedder.useCandidateSteps(asList((CandidateSteps) new MySteps()));
    embedder.configuration().useStepFinder(new StepFinder());
    OutputStream out = new ByteArrayOutputStream();
    embedder.configuration().useStepdocReporter(new PrintStreamStepdocReporter(new PrintStream(out)));
    // When
    embedder.reportMatchingStepdocs("Given a non-defined step");
    // Then
    String expected = "Step 'Given a non-defined step' is not matched by any pattern\n" + "from steps instances:\n" + "org.jbehave.core.embedder.EmbedderBehaviour$MySteps\n";
    assertThat(dos2unix(out.toString()), equalTo(expected));
}
Also used : PrintStream(java.io.PrintStream) StepFinder(org.jbehave.core.steps.StepFinder) PrintStreamStepdocReporter(org.jbehave.core.reporters.PrintStreamStepdocReporter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) CandidateSteps(org.jbehave.core.steps.CandidateSteps) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 12 with CandidateSteps

use of org.jbehave.core.steps.CandidateSteps in project jbehave-core by jbehave.

the class EmbedderBehaviour method shouldReportAllStepdocs.

@Test
public void shouldReportAllStepdocs() {
    // Given
    Embedder embedder = new Embedder();
    embedder.useCandidateSteps(asList((CandidateSteps) new MySteps()));
    embedder.configuration().useStepFinder(new StepFinder());
    OutputStream out = new ByteArrayOutputStream();
    embedder.configuration().useStepdocReporter(new PrintStreamStepdocReporter(new PrintStream(out)));
    // When
    embedder.reportStepdocs();
    // Then
    String output = dos2unix(out.toString());
    assertThat(output, containsString("'Given a given'\n" + "org.jbehave.core.embedder.EmbedderBehaviour$MySteps.given()\n"));
    assertThat(output, containsString("'When a when'\n" + "org.jbehave.core.embedder.EmbedderBehaviour$MySteps.when()\n"));
    assertThat(output, containsString("'Then a then'\n" + "org.jbehave.core.embedder.EmbedderBehaviour$MySteps.then()\n"));
    assertThat(output, containsString("from steps instances:\norg.jbehave.core.embedder.EmbedderBehaviour$MySteps\n"));
}
Also used : PrintStream(java.io.PrintStream) StepFinder(org.jbehave.core.steps.StepFinder) PrintStreamStepdocReporter(org.jbehave.core.reporters.PrintStreamStepdocReporter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) CandidateSteps(org.jbehave.core.steps.CandidateSteps) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 13 with CandidateSteps

use of org.jbehave.core.steps.CandidateSteps in project jbehave-core by jbehave.

the class ConfigurableEmbedderBehaviour method shouldRunMultipleStories.

@Test
public void shouldRunMultipleStories() throws Throwable {
    // Given
    Embedder embedder = mock(Embedder.class);
    Configuration configuration = mock(Configuration.class);
    CandidateSteps steps = mock(CandidateSteps.class);
    // When
    MyStories story = new MyStories(configuration, steps);
    story.useEmbedder(embedder);
    story.run();
    // Then
    verify(embedder).runStoriesAsPaths(asList("org/jbehave/core/story1", "org/jbehave/core/story2"));
}
Also used : MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Configuration(org.jbehave.core.configuration.Configuration) Embedder(org.jbehave.core.embedder.Embedder) CandidateSteps(org.jbehave.core.steps.CandidateSteps) Test(org.junit.Test)

Example 14 with CandidateSteps

use of org.jbehave.core.steps.CandidateSteps 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));
}
Also used : StoryPathResolver(org.jbehave.core.io.StoryPathResolver) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Embedder(org.jbehave.core.embedder.Embedder) CandidateSteps(org.jbehave.core.steps.CandidateSteps) Test(org.junit.Test)

Example 15 with CandidateSteps

use of org.jbehave.core.steps.CandidateSteps in project jbehave-core by jbehave.

the class ConfigurableEmbedderBehaviour method shouldRunASingleStory.

@Test
public void shouldRunASingleStory() 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(configuration, steps);
    story.useEmbedder(embedder);
    story.run();
    // Then
    verify(embedder).useConfiguration(configuration);
    verify(embedder).useCandidateSteps(eq(asList(steps)));
    verify(embedder).runStoriesAsPaths(asList(storyPath));
}
Also used : StoryPathResolver(org.jbehave.core.io.StoryPathResolver) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Configuration(org.jbehave.core.configuration.Configuration) Embedder(org.jbehave.core.embedder.Embedder) CandidateSteps(org.jbehave.core.steps.CandidateSteps) Test(org.junit.Test)

Aggregations

CandidateSteps (org.jbehave.core.steps.CandidateSteps)29 Test (org.junit.Test)23 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)18 Configuration (org.jbehave.core.configuration.Configuration)6 ApplicationContext (org.springframework.context.ApplicationContext)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 OutputStream (java.io.OutputStream)5 PrintStream (java.io.PrintStream)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 InjectableEmbedder (org.jbehave.core.InjectableEmbedder)5 UsingEmbedder (org.jbehave.core.annotations.UsingEmbedder)5 Embedder (org.jbehave.core.embedder.Embedder)5 StepFinder (org.jbehave.core.steps.StepFinder)5 PrintStreamStepdocReporter (org.jbehave.core.reporters.PrintStreamStepdocReporter)4 StoryPathResolver (org.jbehave.core.io.StoryPathResolver)3 InjectableStepsFactory (org.jbehave.core.steps.InjectableStepsFactory)3 Steps (org.jbehave.core.steps.Steps)3 AbstractModule (com.google.inject.AbstractModule)2 Injector (com.google.inject.Injector)2 ConfigurableEmbedder (org.jbehave.core.ConfigurableEmbedder)2