Search in sources :

Example 6 with StoryReporter

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

the class StoryRunnerBehaviour method shouldRunBeforeAndAfterStorySteps.

@Test
public void shouldRunBeforeAndAfterStorySteps() throws Throwable {
    // Given
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    Step beforeStep = mockSuccessfulStep("beforeStep");
    Step afterStep = mockSuccessfulStep("secondStep");
    StepCollector collector = mock(StepCollector.class);
    FailureStrategy strategy = mock(FailureStrategy.class);
    CandidateSteps mySteps = new Steps();
    Story story = new Story();
    boolean givenStory = false;
    when(collector.collectBeforeOrAfterStorySteps(asList(mySteps), story, Stage.BEFORE, givenStory)).thenReturn(asList(beforeStep));
    when(collector.collectBeforeOrAfterStorySteps(asList(mySteps), story, Stage.AFTER, givenStory)).thenReturn(asList(afterStep));
    // When
    StoryRunner runner = new StoryRunner();
    runner.run(configurationWith(reporter, collector, strategy), asList(mySteps), story);
    // Then
    verify(beforeStep).perform(null);
    verify(afterStep).perform(null);
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) ConcurrentStoryReporter(org.jbehave.core.reporters.ConcurrentStoryReporter) AbstractStep(org.jbehave.core.steps.StepCreator.AbstractStep) Test(org.junit.Test)

Example 7 with StoryReporter

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

the class StoryRunnerBehaviour method shouldRunAfterAndBeforeScenarioSteps.

@Test
public void shouldRunAfterAndBeforeScenarioSteps() throws Throwable {
    // Given
    Scenario scenario1 = new Scenario("my title 1", Meta.EMPTY, GivenStories.EMPTY, ExamplesTable.EMPTY, asList("step"));
    Story story = new Story(new Description("my blurb"), Narrative.EMPTY, asList(scenario1));
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    StepCollector collector = mock(StepCollector.class);
    FailureStrategy failureStrategy = mock(FailureStrategy.class);
    Configuration configuration = configurationWith(reporter, collector, failureStrategy);
    configuration.storyControls().doDryRun(true);
    CandidateSteps mySteps = new Steps(configuration);
    Step firstStep = mockSuccessfulStep("step");
    when(collector.collectScenarioSteps(asList(mySteps), scenario1, new HashMap<String, String>())).thenReturn(asList(firstStep));
    boolean givenStory = false;
    givenStoryWithNoBeforeOrAfterSteps(story, givenStory, collector, mySteps);
    givenBeforeAndAfterScenarioSteps(ScenarioType.NORMAL, collector, mySteps);
    givenBeforeAndAfterScenarioSteps(ScenarioType.ANY, collector, mySteps);
    givenLifecycleSteps(collector, mySteps);
    // When
    StoryRunner runner = new StoryRunner();
    runner.run(configuration, asList(mySteps), story);
    // Then
    InOrder inOrder = inOrder(reporter, failureStrategy);
    inOrder.verify(reporter).successful(stepNameFor(Stage.BEFORE, ScenarioType.NORMAL));
    inOrder.verify(reporter).successful(stepNameFor(Stage.BEFORE, ScenarioType.ANY));
    inOrder.verify(reporter).successful(lifecycleStepNameFor(Stage.BEFORE));
    inOrder.verify(reporter).successful("step");
    inOrder.verify(reporter).successful(lifecycleStepNameFor(Stage.AFTER));
    inOrder.verify(reporter).successful(stepNameFor(Stage.AFTER, ScenarioType.ANY));
    inOrder.verify(reporter).successful(stepNameFor(Stage.AFTER, ScenarioType.NORMAL));
}
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) Test(org.junit.Test)

Example 8 with StoryReporter

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

the class StoryRunnerBehaviour method shouldNotPerformStepsAfterRestaringScenarioFailure.

@Test
public void shouldNotPerformStepsAfterRestaringScenarioFailure() throws Throwable {
    // Given
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    Step firstStepNormal = mockSuccessfulStep("Given I succeed");
    final RestartingScenarioFailure hi = new RestartingScenarioFailure("hi");
    Step restartStep = new AbstractStep() {

        private int count = 0;

        public StepResult perform(UUIDExceptionWrapper storyFailureIfItHappened) {
            if (count == 0) {
                count++;
                throw hi;
            }
            return new AbstractStepResult.Successful("When happened on second attempt");
        }

        public StepResult doNotPerform(UUIDExceptionWrapper storyFailureIfItHappened) {
            return null;
        }

        @Override
        public String toString() {
            return "<fooStep>";
        }
    };
    Step lastStepNormal = mockSuccessfulStep("Then I succeeded");
    StepCollector collector = mock(StepCollector.class);
    FailureStrategy strategy = mock(FailureStrategy.class);
    CandidateSteps mySteps = new Steps();
    Scenario scenario = new Scenario();
    when(collector.collectScenarioSteps(eq(asList(mySteps)), eq(scenario), eq(parameters))).thenReturn(asList(firstStepNormal, restartStep, lastStepNormal));
    Story story = new Story(asList(scenario));
    givenStoryWithNoBeforeOrAfterSteps(story, false, collector, mySteps);
    // When
    StoryRunner runner = new StoryRunner();
    runner.run(configurationWith(reporter, collector, strategy), asList(mySteps), story);
    verify(reporter, times(2)).successful("Given I succeed");
    verify(reporter).restarted(eq("<fooStep>"), isA(RestartingScenarioFailure.class));
    verify(reporter).successful("When happened on second attempt");
    verify(reporter).successful("Then I succeeded");
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) ConcurrentStoryReporter(org.jbehave.core.reporters.ConcurrentStoryReporter) AbstractStep(org.jbehave.core.steps.StepCreator.AbstractStep) AbstractStep(org.jbehave.core.steps.StepCreator.AbstractStep) Test(org.junit.Test)

Example 9 with StoryReporter

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

the class StoryRunnerBehaviour method shouldNotRunStoriesNotAllowedByFilterOnStoryElement.

@Test
public void shouldNotRunStoriesNotAllowedByFilterOnStoryElement() 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("excluded_path", Description.EMPTY, Meta.EMPTY, Narrative.EMPTY, asList(new Scenario()));
    boolean givenStory = false;
    givenStoryWithNoBeforeOrAfterSteps(story, givenStory, collector, mySteps);
    String filterAsString = "-story_path excluded_path";
    MetaFilter filter = new MetaFilter(filterAsString);
    // When
    StoryRunner runner = new StoryRunner();
    Configuration configuration = configurationWith(reporter, collector, strategy);
    configuration.storyControls().useStoryMetaPrefix("story_");
    runner.run(configuration, 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) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Test(org.junit.Test)

Example 10 with StoryReporter

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

the class StoryRunnerBehaviour method shouldRunStepsBeforeAndAfterStories.

@Test
public void shouldRunStepsBeforeAndAfterStories() throws Throwable {
    // Given
    Step beforeStep = mock(Step.class, "beforeStep");
    StepResult beforeResult = mock(StepResult.class);
    when(beforeStep.perform(null)).thenReturn(beforeResult);
    Step afterStep = mock(Step.class, "afterStep");
    StepResult afterResult = mock(StepResult.class);
    when(afterStep.perform(null)).thenReturn(afterResult);
    StepCollector collector = mock(StepCollector.class);
    CandidateSteps mySteps = new Steps();
    StoryReporter reporter = mock(StoryReporter.class);
    FailureStrategy failureStrategy = mock(FailureStrategy.class);
    // When
    StoryRunner runner = new StoryRunner();
    when(collector.collectBeforeOrAfterStoriesSteps(asList(mySteps), Stage.BEFORE)).thenReturn(asList(beforeStep));
    runner.runBeforeOrAfterStories(configurationWith(reporter, collector, failureStrategy), asList(mySteps), Stage.BEFORE);
    when(collector.collectBeforeOrAfterStoriesSteps(asList(mySteps), Stage.AFTER)).thenReturn(asList(afterStep));
    runner.runBeforeOrAfterStories(configurationWith(reporter, collector, failureStrategy), asList(mySteps), Stage.AFTER);
    // Then
    verify(beforeStep).perform(null);
    verify(afterStep).perform(null);
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) ConcurrentStoryReporter(org.jbehave.core.reporters.ConcurrentStoryReporter) AbstractStep(org.jbehave.core.steps.StepCreator.AbstractStep) AbstractStepResult(org.jbehave.core.steps.AbstractStepResult) 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