Search in sources :

Example 1 with StepFinder

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

the class ReportTransformBehaviour method runStories.

private void runStories(String... storyPaths) {
    StoryReporterBuilder storyReporterBuilder = new StoryReporterBuilder().withDefaultFormats().withCodeLocation(CodeLocations.codeLocationFromClass(ReportTransformBehaviour.class)).withFormats(Format.XML);
    Configuration configuration = new MostUsefulConfiguration().useStoryLoader(new LoadFromClasspath(this.getClass())).useStoryReporterBuilder(storyReporterBuilder).useFailureStrategy(new SilentlyAbsorbingFailure()).useStepCollector(new MarkUnmatchedStepsAsPending(new StepFinder(new ByLevenshteinDistance())));
    Embedder embedder = new Embedder();
    embedder.useEmbedderControls(new EmbedderControls().doGenerateViewAfterStories(false));
    embedder.useConfiguration(configuration);
    embedder.useCandidateSteps(new InstanceStepsFactory(configuration, new MySteps()).createCandidateSteps());
    embedder.useMetaFilters(asList("-skip true"));
    try {
        embedder.runStoriesAsPaths(asList(storyPaths));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : StoryReporterBuilder(org.jbehave.core.reporters.StoryReporterBuilder) StepFinder(org.jbehave.core.steps.StepFinder) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Embedder(org.jbehave.core.embedder.Embedder) FileNotFoundException(java.io.FileNotFoundException) SilentlyAbsorbingFailure(org.jbehave.core.failures.SilentlyAbsorbingFailure) ByLevenshteinDistance(org.jbehave.core.steps.StepFinder.ByLevenshteinDistance) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) InstanceStepsFactory(org.jbehave.core.steps.InstanceStepsFactory) EmbedderControls(org.jbehave.core.embedder.EmbedderControls) MarkUnmatchedStepsAsPending(org.jbehave.core.steps.MarkUnmatchedStepsAsPending)

Example 2 with StepFinder

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

the class ReportTransformBehaviour method runStories.

private void runStories(String... storyPaths) {
    StoryReporterBuilder storyReporterBuilder = new StoryReporterBuilder().withDefaultFormats().withCodeLocation(CodeLocations.codeLocationFromClass(ReportTransformBehaviour.class)).withFormats(Format.XML);
    Configuration configuration = new MostUsefulConfiguration().useStoryLoader(new LoadFromClasspath(this.getClass())).useStoryReporterBuilder(storyReporterBuilder).useFailureStrategy(new SilentlyAbsorbingFailure()).useStepCollector(new MarkUnmatchedStepsAsPending(new StepFinder(new ByLevenshteinDistance())));
    Embedder embedder = new Embedder();
    embedder.useEmbedderControls(new EmbedderControls().doGenerateViewAfterStories(false));
    embedder.useConfiguration(configuration);
    embedder.useCandidateSteps(new InstanceStepsFactory(configuration, new MySteps()).createCandidateSteps());
    embedder.useMetaFilters(asList("-skip true"));
    try {
        embedder.runStoriesAsPaths(asList(storyPaths));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : StoryReporterBuilder(org.jbehave.core.reporters.StoryReporterBuilder) StepFinder(org.jbehave.core.steps.StepFinder) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Embedder(org.jbehave.core.embedder.Embedder) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SilentlyAbsorbingFailure(org.jbehave.core.failures.SilentlyAbsorbingFailure) ByLevenshteinDistance(org.jbehave.core.steps.StepFinder.ByLevenshteinDistance) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) InstanceStepsFactory(org.jbehave.core.steps.InstanceStepsFactory) EmbedderControls(org.jbehave.core.embedder.EmbedderControls) MarkUnmatchedStepsAsPending(org.jbehave.core.steps.MarkUnmatchedStepsAsPending)

Example 3 with StepFinder

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

the class EmbedderBehaviour method shouldReportNoMatchingStepdocsFoundWhenNoStepsProvided.

@Test
public void shouldReportNoMatchingStepdocsFoundWhenNoStepsProvided() {
    // Given
    Embedder embedder = new Embedder();
    embedder.useCandidateSteps(asList(new CandidateSteps[] {}));
    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" + "as no steps instances are provided\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 4 with StepFinder

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

the class EmbedderBehaviour method shouldFindAndReportMatchingSteps.

@Test
public void shouldFindAndReportMatchingSteps() {
    // 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 given");
    // Then
    String expected = "Step 'Given a given' is matched by annotated patterns:\n" + "'Given a given'\n" + "org.jbehave.core.embedder.EmbedderBehaviour$MySteps.given()\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 5 with StepFinder

use of org.jbehave.core.steps.StepFinder 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)

Aggregations

StepFinder (org.jbehave.core.steps.StepFinder)8 CandidateSteps (org.jbehave.core.steps.CandidateSteps)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 OutputStream (java.io.OutputStream)4 PrintStream (java.io.PrintStream)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 InjectableEmbedder (org.jbehave.core.InjectableEmbedder)4 UsingEmbedder (org.jbehave.core.annotations.UsingEmbedder)4 PrintStreamStepdocReporter (org.jbehave.core.reporters.PrintStreamStepdocReporter)4 Test (org.junit.Test)4 Configuration (org.jbehave.core.configuration.Configuration)3 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)3 FileNotFoundException (java.io.FileNotFoundException)2 Embedder (org.jbehave.core.embedder.Embedder)2 EmbedderControls (org.jbehave.core.embedder.EmbedderControls)2 SilentlyAbsorbingFailure (org.jbehave.core.failures.SilentlyAbsorbingFailure)2 LoadFromClasspath (org.jbehave.core.io.LoadFromClasspath)2 StepdocReporter (org.jbehave.core.reporters.StepdocReporter)2 StoryReporterBuilder (org.jbehave.core.reporters.StoryReporterBuilder)2 InstanceStepsFactory (org.jbehave.core.steps.InstanceStepsFactory)2