Search in sources :

Example 16 with StoryReporter

use of org.jbehave.core.reporters.StoryReporter in project jbehave-core by jbehave.

the class StepCandidateBehaviour method shouldCreatePerformableStepWithResultThatDescribesTheStepPerformed.

@Test
public void shouldCreatePerformableStepWithResultThatDescribesTheStepPerformed() throws Exception {
    StoryReporter reporter = mock(StoryReporter.class);
    SomeSteps someSteps = new SomeSteps();
    Method method = SomeSteps.class.getMethod("aMethodWith", String.class);
    StepCandidate candidate = candidateWith("I live on the $nth floor", THEN, method, someSteps);
    StepResult result = candidate.createMatchedStep("Then I live on the 1st floor", namedParameters).perform(null);
    result.describeTo(reporter);
    verify(reporter).successful("Then I live on the " + PARAMETER_VALUE_START + "1st" + PARAMETER_VALUE_END + " floor");
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 17 with StoryReporter

use of org.jbehave.core.reporters.StoryReporter in project jbehave-core by jbehave.

the class StepCandidateBehaviour method shouldCreateStepFromTableValuesViaAnnotations.

@Test
public void shouldCreateStepFromTableValuesViaAnnotations() throws Exception {
    StoryReporter reporter = mock(StoryReporter.class);
    AnnotationNamedParameterSteps steps = new AnnotationNamedParameterSteps();
    namedParameters.put("ith", "first");
    namedParameters.put("nth", "ground");
    String patternAsString = "I live on the ith floor but some call it the nth";
    Method method = stepMethodFor("methodWithNamedParametersInNaturalOrder", AnnotationNamedParameterSteps.class);
    StepCandidate candidate = candidateWith(patternAsString, WHEN, method, steps);
    StepResult result = candidate.createMatchedStep("When I live on the <ith> floor but some call it the <nth>", namedParameters).perform(null);
    assertThat(steps.ith, equalTo("first"));
    assertThat(steps.nth, equalTo("ground"));
    result.describeTo(reporter);
    verify(reporter).successful("When I live on the " + PARAMETER_VALUE_START + "first" + PARAMETER_VALUE_END + " floor but some call it the " + PARAMETER_VALUE_START + "ground" + PARAMETER_VALUE_END);
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 18 with StoryReporter

use of org.jbehave.core.reporters.StoryReporter in project jbehave-core by jbehave.

the class StepResultBehaviour method shouldDescribeResultToReporterWithParameterValuesWhenAvailable.

@Test
public void shouldDescribeResultToReporterWithParameterValuesWhenAvailable() {
    // Given
    StoryReporter reporter = mock(StoryReporter.class);
    // When
    String successful = "Given that a step is pending or failing";
    successful("Given that a step is $pending or $failing").withParameterValues(successful).describeTo(reporter);
    String pending = "When a step is performed";
    pending("When a step is $performed").withParameterValues(pending).describeTo(reporter);
    String notPerformed = "Then the step should describe itself properly to reporters";
    notPerformed("Then the step should $describe itself properly to reporters").withParameterValues(notPerformed).describeTo(reporter);
    String failed = "And any errors should appear at the end of the story";
    UUIDExceptionWrapper cause = new UUIDExceptionWrapper(new IllegalStateException());
    failed("And any errors should $appear at the end of the story", cause).withParameterValues(failed).describeTo(reporter);
    // Then
    verify(reporter).successful(successful);
    verify(reporter).pending(pending);
    verify(reporter).notPerformed(notPerformed);
    verify(reporter).failed(failed, cause);
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) Matchers.containsString(org.hamcrest.Matchers.containsString) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) Test(org.junit.Test)

Example 19 with StoryReporter

use of org.jbehave.core.reporters.StoryReporter in project jbehave-core by jbehave.

the class EmbedderBehaviour method shouldRunStoriesAsPaths.

@SuppressWarnings("unchecked")
@Test
public void shouldRunStoriesAsPaths() throws Throwable {
    // Given
    PerformableTree performableTree = mock(PerformableTree.class);
    EmbedderControls embedderControls = new EmbedderControls();
    EmbedderMonitor embedderMonitor = mock(EmbedderMonitor.class);
    OutputStream out = new ByteArrayOutputStream();
    EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
    List<? extends Class<? extends Embeddable>> embeddables = asList(MyStory.class, MyOtherEmbeddable.class);
    Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
    InjectableStepsFactory stepsFactory = embedder.stepsFactory();
    MetaFilter filter = embedder.metaFilter();
    final StoryReporter storyReporter = mock(StoryReporter.class);
    MostUsefulConfiguration configuration = new MostUsefulConfiguration() {

        @Override
        public StoryReporter storyReporter(String storyPath) {
            return storyReporter;
        }
    };
    embedder.useConfiguration(configuration);
    StoryPathResolver resolver = configuration.storyPathResolver();
    List<String> storyPaths = new ArrayList<>();
    Map<String, Story> stories = new HashMap<>();
    for (Class<? extends Embeddable> embeddable : embeddables) {
        String storyPath = resolver.resolve(embeddable);
        storyPaths.add(storyPath);
        Story story = mockStory(Meta.EMPTY);
        stories.put(storyPath, story);
        when(performableTree.storyOfPath(configuration, storyPath)).thenReturn(story);
        when(story.getPath()).thenReturn(storyPath);
        assertThat(configuration.storyReporter(storyPath), sameInstance(storyReporter));
    }
    RunContext runContext = new RunContext(configuration, stepsFactory, embedderMonitor, filter, new BatchFailures());
    when(performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(EmbedderMonitor.class), isA(MetaFilter.class), isA(BatchFailures.class))).thenReturn(runContext);
    // When
    embedder.runStoriesAsPaths(storyPaths);
    // Then
    for (String storyPath : storyPaths) {
        verify(performableTree).perform(Matchers.isA(RunContext.class), Matchers.eq(stories.get(storyPath)));
        assertThat(out.toString(), containsString("Running story " + storyPath));
    }
    assertThatReportsViewGenerated(out);
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) PrintStream(java.io.PrintStream) InjectableStepsFactory(org.jbehave.core.steps.InjectableStepsFactory) StoryPathResolver(org.jbehave.core.io.StoryPathResolver) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) HashMap(java.util.HashMap) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) BatchFailures(org.jbehave.core.failures.BatchFailures) RunContext(org.jbehave.core.embedder.PerformableTree.RunContext) JUnitStory(org.jbehave.core.junit.JUnitStory) Story(org.jbehave.core.model.Story) Test(org.junit.Test)

Example 20 with StoryReporter

use of org.jbehave.core.reporters.StoryReporter in project jbehave-core by jbehave.

the class StoryRunnerBehaviour method shouldAllowToNotResetStateBeforeScenario.

@Test
public void shouldAllowToNotResetStateBeforeScenario() throws Throwable {
    // Given
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    Step pendingStep = mock(Step.class);
    when(pendingStep.perform(null)).thenReturn(pending("pendingStep"));
    Step secondStep = mockSuccessfulStep("secondStep");
    StepCollector collector = mock(StepCollector.class);
    CandidateSteps mySteps = new Steps();
    Scenario scenario1 = new Scenario();
    Scenario scenario2 = new Scenario();
    when(collector.collectScenarioSteps(asList(mySteps), scenario1, parameters)).thenReturn(asList(pendingStep));
    when(collector.collectScenarioSteps(asList(mySteps), scenario2, parameters)).thenReturn(asList(secondStep));
    Story story = new Story(asList(scenario1, scenario2));
    givenStoryWithNoBeforeOrAfterSteps(story, false, collector, mySteps);
    // When
    StoryRunner runner = new StoryRunner();
    Configuration configuration = configurationWith(reporter, collector);
    configuration.storyControls().doResetStateBeforeScenario(false);
    runner.run(configuration, asList(mySteps), story);
    // Then
    verify(pendingStep).perform(Matchers.<UUIDExceptionWrapper>any());
    verify(secondStep).doNotPerform(Matchers.<UUIDExceptionWrapper>any());
    verify(secondStep, never()).perform(Matchers.<UUIDExceptionWrapper>any());
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) ConcurrentStoryReporter(org.jbehave.core.reporters.ConcurrentStoryReporter) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) AbstractStep(org.jbehave.core.steps.StepCreator.AbstractStep) Test(org.junit.Test)

Aggregations

StoryReporter (org.jbehave.core.reporters.StoryReporter)32 Test (org.junit.Test)32 ConcurrentStoryReporter (org.jbehave.core.reporters.ConcurrentStoryReporter)24 AbstractStep (org.jbehave.core.steps.StepCreator.AbstractStep)19 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)16 Configuration (org.jbehave.core.configuration.Configuration)15 AbstractStepResult (org.jbehave.core.steps.AbstractStepResult)10 InOrder (org.mockito.InOrder)8 Method (java.lang.reflect.Method)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStream (java.io.OutputStream)2 PrintStream (java.io.PrintStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 InjectableEmbedder (org.jbehave.core.InjectableEmbedder)2 UsingEmbedder (org.jbehave.core.annotations.UsingEmbedder)2 RunContext (org.jbehave.core.embedder.PerformableTree.RunContext)2 BatchFailures (org.jbehave.core.failures.BatchFailures)2 UUIDExceptionWrapper (org.jbehave.core.failures.UUIDExceptionWrapper)2