@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); }
@Test public void shouldAllowToNotResetStateBeforeStory() throws Throwable { // Given StoryReporter reporter = mock(ConcurrentStoryReporter.class); Step failedStep = mock(Step.class, "failedStep"); when(failedStep.perform(null)) .thenReturn( failed( "before stories", new UUIDExceptionWrapper(new RuntimeException("BeforeStories fail")))); Step pendingStep = mock(Step.class, "pendingStep"); when(pendingStep.perform(null)).thenReturn(pending("pendingStep")); StepCollector collector = mock(StepCollector.class); CandidateSteps mySteps = new Steps(); Scenario scenario1 = new Scenario(); List<CandidateSteps> candidateSteps = asList(mySteps); when(collector.collectBeforeOrAfterStoriesSteps(candidateSteps, Stage.BEFORE)) .thenReturn(asList(failedStep)); when(collector.collectScenarioSteps(candidateSteps, scenario1, parameters)) .thenReturn(asList(pendingStep)); Story story = new Story(asList(scenario1)); givenStoryWithNoBeforeOrAfterSteps(story, false, collector, mySteps); // When StoryRunner runner = new StoryRunner(); Configuration configuration = configurationWith(reporter, collector); configuration.storyControls().doResetStateBeforeStory(false).doResetStateBeforeScenario(false); runner.runBeforeOrAfterStories(configuration, candidateSteps, Stage.BEFORE); runner.run(configuration, candidateSteps, story); // Then verify(failedStep).perform(Matchers.<UUIDExceptionWrapper>any()); verify(pendingStep).perform(Matchers.<UUIDExceptionWrapper>any()); }