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