@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);
  }
Beispiel #2
0
    public State run(Step step) {
      if (step instanceof ParameterisedStep) {
        ((ParameterisedStep) step).describeTo(reporter.get());
      }
      UUIDExceptionWrapper storyFailureIfItHappened = storyFailure.get();
      StepResult result = step.perform(storyFailureIfItHappened);
      result.describeTo(reporter.get());
      UUIDExceptionWrapper stepFailure = result.getFailure();
      if (stepFailure == null) {
        return this;
      }

      storyFailure.set(mostImportantOf(storyFailureIfItHappened, stepFailure));
      currentStrategy.set(strategyFor(storyFailure.get()));
      return new SomethingHappened(stepFailure);
    }
  @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());
  }
  @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());
  }
Beispiel #5
0
 public State run(Step step) {
   StepResult result = step.doNotPerform(scenarioFailure);
   result.describeTo(reporter.get());
   return this;
 }