Search in sources :

Example 6 with CandidateSteps

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

the class SpringStepsFactoryBehaviour method annotationStepsCanBeCreated.

@Test
public void annotationStepsCanBeCreated() throws Exception {
    // Given
    ApplicationContext context = createApplicationContext(StepsAnnotationConfiguration.class.getName());
    SpringStepsFactory factory = new SpringStepsFactory(new MostUsefulConfiguration(), context);
    // When
    List<CandidateSteps> steps = factory.createCandidateSteps();
    // Then
    assertFooStepsFound(steps);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) CandidateSteps(org.jbehave.core.steps.CandidateSteps) Test(org.junit.Test)

Example 7 with CandidateSteps

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

the class NeedleAnnotationBuilderBehaviour method shouldSupplyInjectors.

@Test
public void shouldSupplyInjectors() {
    final NeedleAnnotationBuilder builderAnnotated = new NeedleAnnotationBuilder(AnnotatedWithStepsWithDependency.class);
    final List<CandidateSteps> buildCandidateSteps = builderAnnotated.buildCandidateSteps();
    assertThatStepsInstancesAre(buildCandidateSteps, FooStepsWithDependency.class);
    final ValueGetter getter = ((FooStepsWithDependency) ((Steps) buildCandidateSteps.get(0)).instance()).getGetter();
    assertThat(getter, is(notNullValue()));
    assertThat((String) getter.getValue(), is(ValueGetter.VALUE));
}
Also used : FooStepsWithDependency(org.jbehave.core.steps.needle.NeedleStepsFactoryBehaviour.FooStepsWithDependency) CandidateSteps(org.jbehave.core.steps.CandidateSteps) ValueGetter(org.jbehave.core.steps.needle.ValueGetter) Test(org.junit.Test)

Example 8 with CandidateSteps

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

the class SerenityReportingRunner method buildCandidateSteps.

private List<CandidateSteps> buildCandidateSteps() {
    List<CandidateSteps> candidateSteps;
    InjectableStepsFactory stepsFactory = configurableEmbedder.stepsFactory();
    if (stepsFactory != null) {
        candidateSteps = stepsFactory.createCandidateSteps();
    } else {
        Embedder embedder = getConfiguredEmbedder();
        candidateSteps = embedder.candidateSteps();
        if (candidateSteps == null || candidateSteps.isEmpty()) {
            candidateSteps = embedder.stepsFactory().createCandidateSteps();
        }
    }
    return candidateSteps;
}
Also used : InjectableStepsFactory(org.jbehave.core.steps.InjectableStepsFactory) CandidateSteps(org.jbehave.core.steps.CandidateSteps) ExtendedEmbedder(net.serenitybdd.jbehave.embedders.ExtendedEmbedder) Embedder(org.jbehave.core.embedder.Embedder) ConfigurableEmbedder(org.jbehave.core.ConfigurableEmbedder)

Example 9 with CandidateSteps

use of org.jbehave.core.steps.CandidateSteps 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 10 with CandidateSteps

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

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