Search in sources :

Example 11 with StoryReporter

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

the class StoryRunnerBehaviour method shouldAllowToSkipBeforeAndAfterScenarioStepsIfGivenStory.

@Test
public void shouldAllowToSkipBeforeAndAfterScenarioStepsIfGivenStory() throws Throwable {
    // Given
    Scenario scenario1 = new Scenario("scenario 1", asList("successfulStep"));
    GivenStories givenStories = new GivenStories("/path/to/given/story1");
    Scenario scenario2 = new Scenario("scenario 2", Meta.EMPTY, givenStories, ExamplesTable.EMPTY, asList("anotherSuccessfulStep"));
    Story story1 = new Story(new Description("story 1"), Narrative.EMPTY, asList(scenario1));
    Story story2 = new Story(new Description("story 2"), Narrative.EMPTY, asList(scenario2));
    Step step = mock(Step.class);
    StepResult result = mock(StepResult.class);
    when(step.perform(null)).thenReturn(result);
    StoryParser storyParser = mock(StoryParser.class);
    StoryLoader storyLoader = mock(StoryLoader.class);
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    StepCollector collector = mock(StepCollector.class);
    CandidateSteps mySteps = new Steps();
    Step successfulStep = mockSuccessfulStep("successfulStep");
    Step anotherSuccessfulStep = mockSuccessfulStep("anotherSuccessfulStep");
    givenStoryWithNoBeforeOrAfterSteps(story1, false, collector, mySteps);
    when(collector.collectScenarioSteps(asList(mySteps), scenario1, parameters)).thenReturn(asList(successfulStep));
    givenStoryWithNoBeforeOrAfterSteps(story2, true, collector, mySteps);
    when(collector.collectScenarioSteps(asList(mySteps), scenario2, parameters)).thenReturn(asList(anotherSuccessfulStep));
    when(storyLoader.loadStoryAsText("/path/to/given/story1")).thenReturn("storyContent");
    when(storyParser.parseStory("storyContent", "/path/to/given/story1")).thenReturn(story1);
    FailureStrategy failureStrategy = mock(FailureStrategy.class);
    Step beforeStep = mockSuccessfulStep("SuccessfulBeforeScenarioStep");
    Step afterStep = mockSuccessfulStep("SuccessfulAfterScenarioStep");
    when(collector.collectBeforeOrAfterScenarioSteps(eq(asList(mySteps)), Matchers.<Meta>any(), eq(Stage.BEFORE), eq(ScenarioType.NORMAL))).thenReturn(asList(beforeStep));
    when(collector.collectBeforeOrAfterScenarioSteps(eq(asList(mySteps)), Matchers.<Meta>any(), eq(Stage.AFTER), eq(ScenarioType.NORMAL))).thenReturn(asList(afterStep));
    // When
    StoryRunner runner = new StoryRunner();
    Configuration configuration = configurationWith(storyParser, storyLoader, reporter, collector, failureStrategy);
    configuration.storyControls().doSkipBeforeAndAfterScenarioStepsIfGivenStory(true);
    runner.run(configuration, asList(mySteps), story2);
    // Then
    verify(collector).collectScenarioSteps(asList(mySteps), scenario1, parameters);
    verify(collector).collectScenarioSteps(asList(mySteps), scenario2, parameters);
    InOrder inOrder = inOrder(beforeStep, successfulStep, anotherSuccessfulStep, afterStep);
    inOrder.verify(beforeStep).perform(null);
    inOrder.verify(successfulStep).perform(null);
    inOrder.verify(anotherSuccessfulStep).perform(null);
    inOrder.verify(afterStep).perform(null);
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) ConcurrentStoryReporter(org.jbehave.core.reporters.ConcurrentStoryReporter) StoryLoader(org.jbehave.core.io.StoryLoader) InOrder(org.mockito.InOrder) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) AbstractStep(org.jbehave.core.steps.StepCreator.AbstractStep) RegexStoryParser(org.jbehave.core.parsers.RegexStoryParser) StoryParser(org.jbehave.core.parsers.StoryParser) AbstractStepResult(org.jbehave.core.steps.AbstractStepResult) Test(org.junit.Test)

Example 12 with StoryReporter

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

the class StoryRunnerBehaviour method shouldRunScenarioAndLifecycleStepsInCorrectOrderWithExamplesTable.

@Test
public void shouldRunScenarioAndLifecycleStepsInCorrectOrderWithExamplesTable() throws Throwable {
    // Given
    ExamplesTable examplesTable = new ExamplesTable("|one|two|\n|1|2|\n|3|4|\n");
    Map<String, String> tableRow1 = examplesTable.getRow(0);
    Map<String, String> tableRow2 = examplesTable.getRow(1);
    Scenario scenario1 = new Scenario("my title 1", Meta.EMPTY, GivenStories.EMPTY, examplesTable, asList("step <one>", "step <two>"));
    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 <one>");
    Step secondStep = mockSuccessfulStep("step <two>");
    when(collector.collectScenarioSteps(asList(mySteps), scenario1, tableRow1)).thenReturn(asList(firstStep, secondStep));
    when(collector.collectScenarioSteps(asList(mySteps), scenario1, tableRow2)).thenReturn(asList(firstStep, secondStep));
    boolean givenStory = false;
    givenStoryWithNoBeforeOrAfterSteps(story, givenStory, collector, mySteps);
    givenBeforeAndAfterScenarioSteps(ScenarioType.NORMAL, collector, mySteps);
    givenBeforeAndAfterScenarioSteps(ScenarioType.ANY, collector, mySteps);
    givenBeforeAndAfterScenarioSteps(ScenarioType.EXAMPLE, 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.EXAMPLE));
    inOrder.verify(reporter).successful(stepNameFor(Stage.BEFORE, ScenarioType.ANY));
    inOrder.verify(reporter).successful(lifecycleStepNameFor(Stage.BEFORE));
    inOrder.verify(reporter).successful("step <one>");
    inOrder.verify(reporter).successful("step <two>");
    inOrder.verify(reporter).successful(lifecycleStepNameFor(Stage.AFTER));
    inOrder.verify(reporter).successful(stepNameFor(Stage.AFTER, ScenarioType.ANY));
    inOrder.verify(reporter).successful(stepNameFor(Stage.AFTER, ScenarioType.EXAMPLE));
    inOrder.verify(reporter).successful(stepNameFor(Stage.BEFORE, ScenarioType.EXAMPLE));
    inOrder.verify(reporter).successful(stepNameFor(Stage.BEFORE, ScenarioType.ANY));
    inOrder.verify(reporter).successful(lifecycleStepNameFor(Stage.BEFORE));
    inOrder.verify(reporter).successful("step <one>");
    inOrder.verify(reporter).successful("step <two>");
    inOrder.verify(reporter).successful(lifecycleStepNameFor(Stage.AFTER));
    inOrder.verify(reporter).successful(stepNameFor(Stage.AFTER, ScenarioType.ANY));
    inOrder.verify(reporter).successful(stepNameFor(Stage.AFTER, ScenarioType.EXAMPLE));
    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 13 with StoryReporter

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

the class StoryRunnerBehaviour method shouldFailWithFailingUpongPendingStepsStrategy.

@Test(expected = PendingStepFound.class)
public void shouldFailWithFailingUpongPendingStepsStrategy() throws Throwable {
    // Given
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    Step pendingStep = mock(Step.class);
    StepResult pendingResult = pending("My step isn't defined!");
    when(pendingStep.perform(null)).thenReturn(pendingResult);
    PendingStepStrategy strategy = new FailingUponPendingStep();
    StepCollector collector = mock(StepCollector.class);
    CandidateSteps mySteps = new Steps();
    when(collector.collectScenarioSteps(eq(asList(mySteps)), (Scenario) anyObject(), eq(parameters))).thenReturn(asList(pendingStep));
    Story story = new Story(asList(new Scenario()));
    givenStoryWithNoBeforeOrAfterSteps(story, false, collector, mySteps);
    // When
    StoryRunner runner = new StoryRunner();
    runner.run(configurationWithPendingStrategy(collector, reporter, strategy), asList(mySteps), story);
// Then ... fail as expected
}
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)

Example 14 with StoryReporter

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

the class StoryRunnerBehaviour method shouldHandlePendingStepsAccordingToStrategy.

@Test
public void shouldHandlePendingStepsAccordingToStrategy() throws Throwable {
    // Given
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    Step pendingStep = mock(Step.class);
    StepResult pendingResult = pending("My step isn't defined!");
    when(pendingStep.perform(null)).thenReturn(pendingResult);
    PendingStepStrategy strategy = mock(PendingStepStrategy.class);
    StepCollector collector = mock(StepCollector.class);
    CandidateSteps mySteps = new Steps();
    when(collector.collectScenarioSteps(eq(asList(mySteps)), (Scenario) anyObject(), eq(parameters))).thenReturn(asList(pendingStep));
    Story story = new Story(asList(new Scenario()));
    givenStoryWithNoBeforeOrAfterSteps(story, false, collector, mySteps);
    // When
    StoryRunner runner = new StoryRunner();
    runner.run(configurationWithPendingStrategy(collector, reporter, strategy), asList(mySteps), story);
    // Then
    verify(strategy).handleFailure(pendingResult.getFailure());
}
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)

Example 15 with StoryReporter

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

the class StoryRunnerBehaviour method shouldRunScenarioWithExamplesTable.

@Test
public void shouldRunScenarioWithExamplesTable() throws Throwable {
    // Given
    ExamplesTable examplesTable = new ExamplesTable("|one|two|\n|1|2|\n");
    Map<String, String> tableRow = examplesTable.getRow(0);
    Scenario scenario1 = new Scenario("my title 1", Meta.EMPTY, GivenStories.EMPTY, examplesTable, asList("step <one>", "step <two>"));
    Story story = new Story(new Description("my blurb"), Narrative.EMPTY, asList(scenario1));
    Step step = mock(Step.class);
    StepResult result = mock(StepResult.class);
    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.storyControls().doDryRun(true);
    CandidateSteps mySteps = new Steps(configuration);
    Step firstStep = mockSuccessfulStep("step <one>");
    Step secondStep = mockSuccessfulStep("step <two>");
    when(collector.collectScenarioSteps(asList(mySteps), scenario1, tableRow)).thenReturn(asList(firstStep, secondStep));
    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).successful("step <one>");
    inOrder.verify(reporter).successful("step <two>");
    inOrder.verify(reporter).afterScenario();
    inOrder.verify(reporter).afterStory(givenStory);
}
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)

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