Пример #1
0
  @Test
  public void shouldRunStepsInStoryAndReportResultsToReporter() 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));
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    StepCollector collector = mock(StepCollector.class);
    CandidateSteps mySteps = new Steps();
    UUIDExceptionWrapper failure = new UUIDExceptionWrapper(new IllegalArgumentException());
    Step pendingStep = mock(Step.class, "pendingStep");
    Step successfulStep = mock(Step.class, "successfulStep");
    Step failingStep = mock(Step.class, "failingStep");
    when(successfulStep.perform(Matchers.<UUIDExceptionWrapper>any()))
        .thenReturn(successful("successfulStep"));
    when(successfulStep.doNotPerform(failure)).thenReturn(notPerformed("successfulStep"));
    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));
    givenStoryWithNoBeforeOrAfterSteps(story, false, collector, mySteps);

    // When
    FailureStrategy failureStrategy = mock(FailureStrategy.class);
    StoryRunner runner = new StoryRunner();
    runner.run(configurationWith(reporter, collector, failureStrategy), asList(mySteps), story);

    // Then
    InOrder inOrder = inOrder(reporter, failureStrategy);
    inOrder.verify(reporter).beforeStory(story, false);
    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(false);
    inOrder.verify(failureStrategy).handleFailure(failure);
  }
Пример #2
0
  @Test
  public void shouldReportFailuresInStepsBeforeAndAfterStories() throws Throwable {
    // Given
    Step beforeStep = mock(Step.class, "beforeStep");
    StepResult beforeResult = mock(StepResult.class, "beforeStep");
    when(beforeStep.perform(null)).thenReturn(beforeResult);
    UUIDExceptionWrapper failure = new UUIDExceptionWrapper("failed");
    when(beforeResult.getFailure()).thenReturn(failure);
    Step afterStep = mock(Step.class, "afterStep");
    StepResult afterResult = mock(StepResult.class);
    when(afterStep.doNotPerform(failure)).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).doNotPerform(failure);
  }
Пример #3
0
 private Step mockSuccessfulStep(String result) {
   Step step = mock(Step.class, result);
   when(step.perform(Matchers.<UUIDExceptionWrapper>any())).thenReturn(successful(result));
   when(step.doNotPerform(Matchers.<UUIDExceptionWrapper>any()))
       .thenReturn(notPerformed("successfulStep"));
   return step;
 }
Пример #4
0
  @Test
  public void shouldNotPerformStepsAfterFailedOrPendingSteps() throws Throwable {
    // Given
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    Step firstStepNormal = mockSuccessfulStep("Given I succeed");
    Step secondStepPending = mock(Step.class, "secondStepPending");
    Step thirdStepNormal = mock(Step.class, "thirdStepNormal");
    Step fourthStepAlsoPending = mock(Step.class, "fourthStepAlsoPending");
    StepCollector collector = mock(StepCollector.class);
    CandidateSteps mySteps = new Steps();
    Scenario scenario = new Scenario();
    when(collector.collectScenarioSteps(eq(asList(mySteps)), eq(scenario), eq(parameters)))
        .thenReturn(
            asList(firstStepNormal, secondStepPending, thirdStepNormal, fourthStepAlsoPending));
    when(secondStepPending.perform(null)).thenReturn(pending("When I am pending"));
    when(thirdStepNormal.doNotPerform(Matchers.<UUIDExceptionWrapper>any()))
        .thenReturn(notPerformed("Then I should not be performed"));
    when(fourthStepAlsoPending.doNotPerform(Matchers.<UUIDExceptionWrapper>any()))
        .thenReturn(notPerformed("Then I should not be performed either"));
    Story story = new Story(asList(scenario));
    givenStoryWithNoBeforeOrAfterSteps(story, false, collector, mySteps);

    // When
    StoryRunner runner = new StoryRunner();
    runner.run(configurationWith(reporter, collector), asList(mySteps), story);

    // Then
    verify(firstStepNormal).perform(null);
    verify(secondStepPending).perform(null);
    verify(thirdStepNormal).doNotPerform(Matchers.<UUIDExceptionWrapper>any());
    verify(fourthStepAlsoPending).doNotPerform(Matchers.<UUIDExceptionWrapper>any());

    verify(reporter).successful("Given I succeed");
    verify(reporter).pending("When I am pending");
    verify(reporter).notPerformed("Then I should not be performed");
    verify(reporter).notPerformed("Then I should not be performed either");
  }
Пример #5
0
  @Test
  public void shouldReportAnyFailuresAndHandleThemAfterStory() throws Throwable {
    // Given
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    Step firstStepExceptional = mock(Step.class);
    Step secondStepNotPerformed = mock(Step.class);
    StepResult failed =
        failed("When I fail", new UUIDExceptionWrapper(new IllegalStateException()));
    StepResult notPerformed = notPerformed("Then I should not be performed");
    when(firstStepExceptional.perform(null)).thenReturn(failed);
    when(secondStepNotPerformed.doNotPerform(Matchers.<UUIDExceptionWrapper>any()))
        .thenReturn(notPerformed);
    FailureStrategy failureStrategy = mock(FailureStrategy.class);
    StepCollector collector = mock(StepCollector.class);
    CandidateSteps mySteps = new Steps();
    Scenario scenario = new Scenario();
    when(collector.collectScenarioSteps(eq(asList(mySteps)), eq(scenario), eq(parameters)))
        .thenReturn(asList(firstStepExceptional, secondStepNotPerformed));
    Story story = new Story(asList(scenario));
    boolean givenStory = false;
    givenStoryWithNoBeforeOrAfterSteps(story, givenStory, collector, mySteps);

    // When
    StoryRunner runner = new StoryRunner();
    runner.run(configurationWith(reporter, collector, failureStrategy), asList(mySteps), story);

    // Then
    verify(firstStepExceptional).perform(null);
    verify(secondStepNotPerformed).doNotPerform(Matchers.<UUIDExceptionWrapper>any());

    InOrder inOrder = inOrder(reporter, failureStrategy);
    inOrder.verify(reporter).beforeStory((Story) anyObject(), eq(givenStory));
    inOrder.verify(reporter).beforeScenario((String) anyObject());
    inOrder.verify(reporter).failed("When I fail", failed.getFailure());
    inOrder.verify(reporter).notPerformed("Then I should not be performed");
    inOrder.verify(reporter).afterScenario();
    inOrder.verify(reporter).afterStory(givenStory);
    inOrder.verify(failureStrategy).handleFailure(failed.getFailure());
  }
Пример #6
0
 public State run(Step step) {
   StepResult result = step.doNotPerform(scenarioFailure);
   result.describeTo(reporter.get());
   return this;
 }