Search in sources :

Example 46 with Configuration

use of org.jbehave.core.configuration.Configuration 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)

Example 47 with Configuration

use of org.jbehave.core.configuration.Configuration in project jbehave-core by jbehave.

the class StepsBehaviour method shouldListCandidateStepsFromAnnotatedMethodsInPojo.

@Test
public void shouldListCandidateStepsFromAnnotatedMethodsInPojo() {
    PojoSteps steps = new PojoSteps();
    Configuration configuration = new MostUsefulConfiguration();
    List<StepCandidate> candidates = new InstanceStepsFactory(configuration, steps).createCandidateSteps().get(0).listCandidates();
    assertThat(candidates.size(), equalTo(6));
    findCandidate(candidates, "GIVEN a given").createMatchedStep("Given a given", tableRow).perform(null);
    findCandidate(candidates, "GIVEN a given alias").createMatchedStep("Given a given alias", tableRow).perform(null);
    findCandidate(candidates, "WHEN a when").createMatchedStep("When a when", tableRow).perform(null);
    findCandidate(candidates, "WHEN a when alias").createMatchedStep("When a when alias", tableRow).perform(null);
    findCandidate(candidates, "THEN a then").createMatchedStep("Then a then", tableRow).perform(null);
    findCandidate(candidates, "THEN a then alias").createMatchedStep("Then a then alias", tableRow).perform(null);
    assertThat(steps.givens, equalTo(2));
    assertThat(steps.whens, equalTo(2));
    assertThat(steps.thens, equalTo(2));
}
Also used : MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Test(org.junit.Test)

Example 48 with Configuration

use of org.jbehave.core.configuration.Configuration in project jbehave-core by jbehave.

the class StepsBehaviour method shouldNotCreateStepIfStartingWordNotFound.

@Test(expected = StartingWordNotFound.class)
public void shouldNotCreateStepIfStartingWordNotFound() {
    Configuration configuration = new MostUsefulConfiguration();
    configuration.useKeywords(new LocalizedKeywords(new Locale("it")));
    LocalizedSteps steps = new LocalizedSteps(configuration);
    List<StepCandidate> candidates = steps.listCandidates();
    assertThat(candidates.size(), equalTo(3));
    // misspelled starting word
    candidates.get(0).createMatchedStep("Dado che un dato che", tableRow);
}
Also used : Locale(java.util.Locale) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Test(org.junit.Test)

Example 49 with Configuration

use of org.jbehave.core.configuration.Configuration in project jbehave-core by jbehave.

the class StepCandidateBehaviour method shouldPerformStepsInDryRunMode.

@Test
public void shouldPerformStepsInDryRunMode() {
    Configuration configuration = new MostUsefulConfiguration();
    configuration.storyControls().doDryRun(true);
    NamedTypeSteps steps = new NamedTypeSteps(configuration);
    List<StepCandidate> candidates = steps.listCandidates();
    assertThat(candidates.size(), equalTo(2));
    StepCandidate step0 = candidateMatchingStep(candidates, "Given foo named $name");
    step0.createMatchedStep("Given foo named xyz", namedParameters).perform(null);
    step0.createMatchedStep("And foo named xyz", namedParameters).perform(null);
    StepCandidate step1 = candidateMatchingStep(candidates, "When foo named $name");
    step1.createMatchedStep("When foo named Bar", namedParameters).perform(null);
    step1.createMatchedStep("And foo named Bar", namedParameters).perform(null);
    assertThat(steps.givenName, nullValue());
    assertThat(steps.givenTimes, equalTo(0));
    assertThat(steps.whenName, nullValue());
    assertThat(steps.whenTimes, equalTo(0));
}
Also used : Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Test(org.junit.Test)

Example 50 with Configuration

use of org.jbehave.core.configuration.Configuration in project jbehave-core by jbehave.

the class GroovyAnnotationBuilderBehaviour method shouldBuildCandidateStepsFromAnnotationsUsingGroovy.

@Test
public void shouldBuildCandidateStepsFromAnnotationsUsingGroovy() {
    GroovyAnnotationBuilder builderAnnotated = new GroovyAnnotationBuilder(AnnotatedUsingGroovy.class);
    Configuration configuration = builderAnnotated.buildConfiguration();
    assertThatStepsInstancesAre(builderAnnotated.buildCandidateSteps(configuration), "FooSteps");
}
Also used : MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Configuration(org.jbehave.core.configuration.Configuration) Test(org.junit.Test)

Aggregations

Configuration (org.jbehave.core.configuration.Configuration)64 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)61 Test (org.junit.Test)55 AnnotationBuilder (org.jbehave.core.configuration.AnnotationBuilder)18 StoryReporter (org.jbehave.core.reporters.StoryReporter)15 ConcurrentStoryReporter (org.jbehave.core.reporters.ConcurrentStoryReporter)13 StoryPathResolver (org.jbehave.core.io.StoryPathResolver)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 OutputStream (java.io.OutputStream)10 PrintStream (java.io.PrintStream)10 Matchers.containsString (org.hamcrest.Matchers.containsString)10 InjectableEmbedder (org.jbehave.core.InjectableEmbedder)10 UsingEmbedder (org.jbehave.core.annotations.UsingEmbedder)10 AbstractStep (org.jbehave.core.steps.StepCreator.AbstractStep)10 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 JUnitStory (org.jbehave.core.junit.JUnitStory)8 Story (org.jbehave.core.model.Story)8 SimpleDateFormat (java.text.SimpleDateFormat)7 RunContext (org.jbehave.core.embedder.PerformableTree.RunContext)7