Search in sources :

Example 26 with StoryReporter

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

the class StoryRunnerBehaviour method shouldNotRunScenariosNotAllowedByFilterOnScenarioElement.

@Test
public void shouldNotRunScenariosNotAllowedByFilterOnScenarioElement() throws Throwable {
    // Given
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    StepCollector collector = mock(StepCollector.class);
    FailureStrategy strategy = mock(FailureStrategy.class);
    CandidateSteps mySteps = new Steps();
    when(collector.collectScenarioSteps(eq(asList(mySteps)), (Scenario) anyObject(), eq(parameters))).thenReturn(Arrays.<Step>asList());
    Story story = new Story("", Description.EMPTY, Meta.EMPTY, Narrative.EMPTY, asList(new Scenario("excluded_title", Meta.EMPTY, GivenStories.EMPTY, ExamplesTable.EMPTY, asList(""))));
    boolean givenStory = false;
    givenStoryWithNoBeforeOrAfterSteps(story, givenStory, collector, mySteps);
    String filterAsString = "-scenario_title excluded_title";
    MetaFilter filter = new MetaFilter(filterAsString);
    // When
    StoryRunner runner = new StoryRunner();
    Configuration configuration = configurationWith(reporter, collector, strategy);
    configuration.storyControls().useScenarioMetaPrefix("scenario_");
    runner.run(configuration, asList(mySteps), story, filter);
    // Then
    verify(reporter).beforeStory(story, givenStory);
    verify(reporter).beforeScenario("excluded_title");
    verify(reporter).scenarioNotAllowed(story.getScenarios().get(0), filterAsString);
    verify(reporter).afterScenario();
}
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) Test(org.junit.Test)

Example 27 with StoryReporter

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

the class StoryRunnerBehaviour method shouldReportStoryCancellation.

@Test
public void shouldReportStoryCancellation() {
    // Given
    Configuration configuration = mock(Configuration.class, Mockito.RETURNS_DEEP_STUBS);
    when(configuration.storyControls().dryRun()).thenReturn(false);
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    when(configuration.storyReporter(Matchers.anyString())).thenReturn(reporter);
    Story story = mock(Story.class);
    String storyPath = "story/path";
    when(story.getPath()).thenReturn(storyPath);
    RuntimeException expected = new RuntimeException();
    when(story.getMeta()).thenThrow(expected);
    InjectableStepsFactory stepsFactory = mock(InjectableStepsFactory.class);
    MetaFilter metaFilter = mock(MetaFilter.class);
    State state = mock(State.class);
    // When
    long durationInSecs = 2;
    long timeoutInSecs = 1;
    StoryDuration storyDuration = new StoryDuration(timeoutInSecs);
    try {
        StoryRunner runner = new StoryRunner();
        runner.cancelStory(story, storyDuration);
        runner.run(configuration, stepsFactory, story, metaFilter, state);
        throw new AssertionError("A exception should be thrown");
    } catch (Throwable e) {
        // Then
        assertThat(e.equals(expected), is(true));
    }
    verify(reporter).storyCancelled(story, storyDuration);
}
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) State(org.jbehave.core.embedder.StoryRunner.State) Test(org.junit.Test)

Example 28 with StoryReporter

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

the class StoryRunnerBehaviour method shouldNotRunStoriesNotAllowedByFilter.

@Test
public void shouldNotRunStoriesNotAllowedByFilter() throws Throwable {
    // Given
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    StepCollector collector = mock(StepCollector.class);
    FailureStrategy strategy = mock(FailureStrategy.class);
    CandidateSteps mySteps = new Steps();
    when(collector.collectScenarioSteps(eq(asList(mySteps)), (Scenario) anyObject(), eq(parameters))).thenReturn(Arrays.<Step>asList());
    Meta meta = new Meta(asList("some property"));
    Story story = new Story("", Description.EMPTY, meta, Narrative.EMPTY, asList(new Scenario()));
    boolean givenStory = false;
    givenStoryWithNoBeforeOrAfterSteps(story, givenStory, collector, mySteps);
    String filterAsString = "-some property";
    MetaFilter filter = new MetaFilter(filterAsString);
    // When
    StoryRunner runner = new StoryRunner();
    runner.run(configurationWith(reporter, collector, strategy), asList(mySteps), story, filter);
    // Then
    verify(reporter).beforeStory(story, givenStory);
    verify(reporter).storyNotAllowed(story, filterAsString);
    verify(reporter).afterStory(givenStory);
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) ConcurrentStoryReporter(org.jbehave.core.reporters.ConcurrentStoryReporter) Test(org.junit.Test)

Example 29 with StoryReporter

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

the class StoryRunnerBehaviour method shouldRunStepsInDryRunMode.

@Test
public void shouldRunStepsInDryRunMode() throws Throwable {
    // Given
    Scenario scenario1 = new Scenario("my title 1", asList("failingStep", "successfulStep"));
    Scenario scenario2 = new Scenario("my title 2", asList("successfulStep"));
    Scenario scenario3 = new Scenario("my title 3", asList("successfulStep", "pendingStep"));
    Story story = new Story(new Description("my blurb"), Narrative.EMPTY, asList(scenario1, scenario2, scenario3));
    Step step = mock(Step.class);
    StepResult result = mock(StepResult.class, "result");
    when(step.perform(null)).thenReturn(result);
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    StepCollector collector = mock(StepCollector.class);
    FailureStrategy failureStrategy = mock(FailureStrategy.class);
    Configuration configuration = configurationWith(reporter, collector, failureStrategy);
    configuration.doDryRun(true);
    CandidateSteps mySteps = new Steps(configuration);
    UUIDExceptionWrapper failure = new UUIDExceptionWrapper(new IllegalArgumentException());
    Step successfulStep = mockSuccessfulStep("successfulStep");
    Step pendingStep = mock(Step.class, "pendingStep");
    Step failingStep = mock(Step.class, "failingStep");
    when(pendingStep.perform(Matchers.<UUIDExceptionWrapper>any())).thenReturn(pending("pendingStep"));
    when(pendingStep.doNotPerform(failure)).thenReturn(pending("pendingStep"));
    when(failingStep.perform(Matchers.<UUIDExceptionWrapper>any())).thenReturn(failed("failingStep", failure));
    when(collector.collectScenarioSteps(asList(mySteps), scenario1, parameters)).thenReturn(asList(failingStep, successfulStep));
    when(collector.collectScenarioSteps(asList(mySteps), scenario2, parameters)).thenReturn(asList(successfulStep));
    when(collector.collectScenarioSteps(asList(mySteps), scenario3, parameters)).thenReturn(asList(successfulStep, pendingStep));
    boolean givenStory = false;
    givenStoryWithNoBeforeOrAfterSteps(story, givenStory, collector, mySteps);
    // When
    StoryRunner runner = new StoryRunner();
    runner.run(configuration, asList(mySteps), story);
    // Then
    InOrder inOrder = inOrder(reporter, failureStrategy);
    inOrder.verify(reporter).beforeStory(story, givenStory);
    inOrder.verify(reporter).beforeScenario("my title 1");
    inOrder.verify(reporter).failed("failingStep", failure);
    inOrder.verify(reporter).notPerformed("successfulStep");
    inOrder.verify(reporter).afterScenario();
    inOrder.verify(reporter).beforeScenario("my title 2");
    inOrder.verify(reporter).successful("successfulStep");
    inOrder.verify(reporter).afterScenario();
    inOrder.verify(reporter).beforeScenario("my title 3");
    inOrder.verify(reporter).successful("successfulStep");
    inOrder.verify(reporter).pending("pendingStep");
    inOrder.verify(reporter).afterScenario();
    inOrder.verify(reporter).afterStory(givenStory);
    inOrder.verify(failureStrategy).handleFailure(failure);
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) ConcurrentStoryReporter(org.jbehave.core.reporters.ConcurrentStoryReporter) InOrder(org.mockito.InOrder) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) AbstractStep(org.jbehave.core.steps.StepCreator.AbstractStep) AbstractStepResult(org.jbehave.core.steps.AbstractStepResult) Test(org.junit.Test)

Example 30 with StoryReporter

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

the class StepCreatorBehaviour method shouldDescribeStepToReporterBeforeExecutingParametrisedStep.

@Test
public void shouldDescribeStepToReporterBeforeExecutingParametrisedStep() throws IntrospectionException {
    // Given
    SomeSteps stepsInstance = new SomeSteps();
    InjectableStepsFactory stepsFactory = new InstanceStepsFactory(new MostUsefulConfiguration(), stepsInstance);
    StepCreator stepCreator = new StepCreator(stepsInstance.getClass(), stepsFactory, stepsContext, null, new ParameterControls(), null, new SilentStepMonitor());
    StoryReporter storyReporter = mock(StoryReporter.class);
    // When
    Method method = SomeSteps.methodFor("aMethod");
    ((ParametrisedStep) stepCreator.createParametrisedStep(method, "When I run", "I run", null)).describeTo(storyReporter);
    // Then
    verify(storyReporter).beforeStep("When I run");
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) ParametrisedStep(org.jbehave.core.steps.StepCreator.ParametrisedStep) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Method(java.lang.reflect.Method) 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