use of org.jbehave.core.reporters.StoryReporter in project jbehave-core by jbehave.
the class StoryRunnerBehaviour method shouldNotRunScenariosNotAllowedByFilterOnScenarioElement.
@Test
public void shouldNotRunScenariosNotAllowedByFilterOnScenarioElement() 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("", Description.EMPTY, Meta.EMPTY, Narrative.EMPTY, asList(new Scenario("excluded_title", Meta.EMPTY, GivenStories.EMPTY, ExamplesTable.EMPTY, asList(""))));
boolean givenStory = false;
givenStoryWithNoBeforeOrAfterSteps(story, givenStory, collector, mySteps);
String filterAsString = "-scenario_title excluded_title";
MetaFilter filter = new MetaFilter(filterAsString);
// When
StoryRunner runner = new StoryRunner();
Configuration configuration = configurationWith(reporter, collector, strategy);
configuration.storyControls().useScenarioMetaPrefix("scenario_");
runner.run(configuration, asList(mySteps), story, filter);
// Then
verify(reporter).beforeStory(story, givenStory);
verify(reporter).beforeScenario("excluded_title");
verify(reporter).scenarioNotAllowed(story.getScenarios().get(0), filterAsString);
verify(reporter).afterScenario();
}
use of org.jbehave.core.reporters.StoryReporter in project jbehave-core by jbehave.
the class StoryRunnerBehaviour method shouldReportStoryCancellation.
@Test
public void shouldReportStoryCancellation() {
// Given
Configuration configuration = mock(Configuration.class, Mockito.RETURNS_DEEP_STUBS);
when(configuration.storyControls().dryRun()).thenReturn(false);
StoryReporter reporter = mock(ConcurrentStoryReporter.class);
when(configuration.storyReporter(Matchers.anyString())).thenReturn(reporter);
Story story = mock(Story.class);
String storyPath = "story/path";
when(story.getPath()).thenReturn(storyPath);
RuntimeException expected = new RuntimeException();
when(story.getMeta()).thenThrow(expected);
InjectableStepsFactory stepsFactory = mock(InjectableStepsFactory.class);
MetaFilter metaFilter = mock(MetaFilter.class);
State state = mock(State.class);
// When
long durationInSecs = 2;
long timeoutInSecs = 1;
StoryDuration storyDuration = new StoryDuration(timeoutInSecs);
try {
StoryRunner runner = new StoryRunner();
runner.cancelStory(story, storyDuration);
runner.run(configuration, stepsFactory, story, metaFilter, state);
throw new AssertionError("A exception should be thrown");
} catch (Throwable e) {
// Then
assertThat(e.equals(expected), is(true));
}
verify(reporter).storyCancelled(story, storyDuration);
}
use of org.jbehave.core.reporters.StoryReporter in project jbehave-core by jbehave.
the class StoryRunnerBehaviour method shouldNotRunStoriesNotAllowedByFilter.
@Test
public void shouldNotRunStoriesNotAllowedByFilter() 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());
Meta meta = new Meta(asList("some property"));
Story story = new Story("", Description.EMPTY, meta, Narrative.EMPTY, asList(new Scenario()));
boolean givenStory = false;
givenStoryWithNoBeforeOrAfterSteps(story, givenStory, collector, mySteps);
String filterAsString = "-some property";
MetaFilter filter = new MetaFilter(filterAsString);
// When
StoryRunner runner = new StoryRunner();
runner.run(configurationWith(reporter, collector, strategy), 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 shouldRunStepsInDryRunMode.
@Test
public void shouldRunStepsInDryRunMode() 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));
Step step = mock(Step.class);
StepResult result = mock(StepResult.class, "result");
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.doDryRun(true);
CandidateSteps mySteps = new Steps(configuration);
UUIDExceptionWrapper failure = new UUIDExceptionWrapper(new IllegalArgumentException());
Step successfulStep = mockSuccessfulStep("successfulStep");
Step pendingStep = mock(Step.class, "pendingStep");
Step failingStep = mock(Step.class, "failingStep");
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));
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).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(givenStory);
inOrder.verify(failureStrategy).handleFailure(failure);
}
use of org.jbehave.core.reporters.StoryReporter in project jbehave-core by jbehave.
the class StepCreatorBehaviour method shouldDescribeStepToReporterBeforeExecutingParametrisedStep.
@Test
public void shouldDescribeStepToReporterBeforeExecutingParametrisedStep() throws IntrospectionException {
// Given
SomeSteps stepsInstance = new SomeSteps();
InjectableStepsFactory stepsFactory = new InstanceStepsFactory(new MostUsefulConfiguration(), stepsInstance);
StepCreator stepCreator = new StepCreator(stepsInstance.getClass(), stepsFactory, stepsContext, null, new ParameterControls(), null, new SilentStepMonitor());
StoryReporter storyReporter = mock(StoryReporter.class);
// When
Method method = SomeSteps.methodFor("aMethod");
((ParametrisedStep) stepCreator.createParametrisedStep(method, "When I run", "I run", null)).describeTo(storyReporter);
// Then
verify(storyReporter).beforeStep("When I run");
}
Aggregations