use of org.jbehave.core.reporters.StoryReporter in project jbehave-core by jbehave.
the class StepCandidateBehaviour method shouldCreatePerformableStepWithResultThatDescribesTheStepPerformed.
@Test
public void shouldCreatePerformableStepWithResultThatDescribesTheStepPerformed() throws Exception {
StoryReporter reporter = mock(StoryReporter.class);
SomeSteps someSteps = new SomeSteps();
Method method = SomeSteps.class.getMethod("aMethodWith", String.class);
StepCandidate candidate = candidateWith("I live on the $nth floor", THEN, method, someSteps);
StepResult result = candidate.createMatchedStep("Then I live on the 1st floor", namedParameters).perform(null);
result.describeTo(reporter);
verify(reporter).successful("Then I live on the " + PARAMETER_VALUE_START + "1st" + PARAMETER_VALUE_END + " floor");
}
use of org.jbehave.core.reporters.StoryReporter in project jbehave-core by jbehave.
the class StepCandidateBehaviour method shouldCreateStepFromTableValuesViaAnnotations.
@Test
public void shouldCreateStepFromTableValuesViaAnnotations() throws Exception {
StoryReporter reporter = mock(StoryReporter.class);
AnnotationNamedParameterSteps steps = new AnnotationNamedParameterSteps();
namedParameters.put("ith", "first");
namedParameters.put("nth", "ground");
String patternAsString = "I live on the ith floor but some call it the nth";
Method method = stepMethodFor("methodWithNamedParametersInNaturalOrder", AnnotationNamedParameterSteps.class);
StepCandidate candidate = candidateWith(patternAsString, WHEN, method, steps);
StepResult result = candidate.createMatchedStep("When I live on the <ith> floor but some call it the <nth>", namedParameters).perform(null);
assertThat(steps.ith, equalTo("first"));
assertThat(steps.nth, equalTo("ground"));
result.describeTo(reporter);
verify(reporter).successful("When I live on the " + PARAMETER_VALUE_START + "first" + PARAMETER_VALUE_END + " floor but some call it the " + PARAMETER_VALUE_START + "ground" + PARAMETER_VALUE_END);
}
use of org.jbehave.core.reporters.StoryReporter in project jbehave-core by jbehave.
the class StepResultBehaviour method shouldDescribeResultToReporterWithParameterValuesWhenAvailable.
@Test
public void shouldDescribeResultToReporterWithParameterValuesWhenAvailable() {
// Given
StoryReporter reporter = mock(StoryReporter.class);
// When
String successful = "Given that a step is pending or failing";
successful("Given that a step is $pending or $failing").withParameterValues(successful).describeTo(reporter);
String pending = "When a step is performed";
pending("When a step is $performed").withParameterValues(pending).describeTo(reporter);
String notPerformed = "Then the step should describe itself properly to reporters";
notPerformed("Then the step should $describe itself properly to reporters").withParameterValues(notPerformed).describeTo(reporter);
String failed = "And any errors should appear at the end of the story";
UUIDExceptionWrapper cause = new UUIDExceptionWrapper(new IllegalStateException());
failed("And any errors should $appear at the end of the story", cause).withParameterValues(failed).describeTo(reporter);
// Then
verify(reporter).successful(successful);
verify(reporter).pending(pending);
verify(reporter).notPerformed(notPerformed);
verify(reporter).failed(failed, cause);
}
use of org.jbehave.core.reporters.StoryReporter in project jbehave-core by jbehave.
the class EmbedderBehaviour method shouldRunStoriesAsPaths.
@SuppressWarnings("unchecked")
@Test
public void shouldRunStoriesAsPaths() throws Throwable {
// Given
PerformableTree performableTree = mock(PerformableTree.class);
EmbedderControls embedderControls = new EmbedderControls();
EmbedderMonitor embedderMonitor = mock(EmbedderMonitor.class);
OutputStream out = new ByteArrayOutputStream();
EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
List<? extends Class<? extends Embeddable>> embeddables = asList(MyStory.class, MyOtherEmbeddable.class);
Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
InjectableStepsFactory stepsFactory = embedder.stepsFactory();
MetaFilter filter = embedder.metaFilter();
final StoryReporter storyReporter = mock(StoryReporter.class);
MostUsefulConfiguration configuration = new MostUsefulConfiguration() {
@Override
public StoryReporter storyReporter(String storyPath) {
return storyReporter;
}
};
embedder.useConfiguration(configuration);
StoryPathResolver resolver = configuration.storyPathResolver();
List<String> storyPaths = new ArrayList<>();
Map<String, Story> stories = new HashMap<>();
for (Class<? extends Embeddable> embeddable : embeddables) {
String storyPath = resolver.resolve(embeddable);
storyPaths.add(storyPath);
Story story = mockStory(Meta.EMPTY);
stories.put(storyPath, story);
when(performableTree.storyOfPath(configuration, storyPath)).thenReturn(story);
when(story.getPath()).thenReturn(storyPath);
assertThat(configuration.storyReporter(storyPath), sameInstance(storyReporter));
}
RunContext runContext = new RunContext(configuration, stepsFactory, embedderMonitor, filter, new BatchFailures());
when(performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(EmbedderMonitor.class), isA(MetaFilter.class), isA(BatchFailures.class))).thenReturn(runContext);
// When
embedder.runStoriesAsPaths(storyPaths);
// Then
for (String storyPath : storyPaths) {
verify(performableTree).perform(Matchers.isA(RunContext.class), Matchers.eq(stories.get(storyPath)));
assertThat(out.toString(), containsString("Running story " + storyPath));
}
assertThatReportsViewGenerated(out);
}
use of org.jbehave.core.reporters.StoryReporter in project jbehave-core by jbehave.
the class StoryRunnerBehaviour method shouldAllowToNotResetStateBeforeScenario.
@Test
public void shouldAllowToNotResetStateBeforeScenario() throws Throwable {
// Given
StoryReporter reporter = mock(ConcurrentStoryReporter.class);
Step pendingStep = mock(Step.class);
when(pendingStep.perform(null)).thenReturn(pending("pendingStep"));
Step secondStep = mockSuccessfulStep("secondStep");
StepCollector collector = mock(StepCollector.class);
CandidateSteps mySteps = new Steps();
Scenario scenario1 = new Scenario();
Scenario scenario2 = new Scenario();
when(collector.collectScenarioSteps(asList(mySteps), scenario1, parameters)).thenReturn(asList(pendingStep));
when(collector.collectScenarioSteps(asList(mySteps), scenario2, parameters)).thenReturn(asList(secondStep));
Story story = new Story(asList(scenario1, scenario2));
givenStoryWithNoBeforeOrAfterSteps(story, false, collector, mySteps);
// When
StoryRunner runner = new StoryRunner();
Configuration configuration = configurationWith(reporter, collector);
configuration.storyControls().doResetStateBeforeScenario(false);
runner.run(configuration, asList(mySteps), story);
// Then
verify(pendingStep).perform(Matchers.<UUIDExceptionWrapper>any());
verify(secondStep).doNotPerform(Matchers.<UUIDExceptionWrapper>any());
verify(secondStep, never()).perform(Matchers.<UUIDExceptionWrapper>any());
}
Aggregations