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);
}
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));
}
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");
}
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);
}
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);
}
Aggregations