use of org.jbehave.core.configuration.Configuration 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.configuration.Configuration 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.configuration.Configuration 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.configuration.Configuration in project jbehave-core by jbehave.
the class ConfigurableEmbedderBehaviour method shouldRunMultipleStories.
@Test
public void shouldRunMultipleStories() throws Throwable {
// Given
Embedder embedder = mock(Embedder.class);
Configuration configuration = mock(Configuration.class);
CandidateSteps steps = mock(CandidateSteps.class);
// When
MyStories story = new MyStories(configuration, steps);
story.useEmbedder(embedder);
story.run();
// Then
verify(embedder).runStoriesAsPaths(asList("org/jbehave/core/story1", "org/jbehave/core/story2"));
}
use of org.jbehave.core.configuration.Configuration in project jbehave-core by jbehave.
the class ConfigurableEmbedderBehaviour method shouldAllowOverrideOfDefaultConfiguration.
@Test
public void shouldAllowOverrideOfDefaultConfiguration() throws Throwable {
// Given
Embedder embedder = mock(Embedder.class);
Configuration configuration = mock(Configuration.class);
StoryPathResolver pathResolver = mock(StoryPathResolver.class);
when(embedder.configuration()).thenReturn(configuration);
when(configuration.storyPathResolver()).thenReturn(pathResolver);
Class<MyStory> storyClass = MyStory.class;
String storyPath = "/path/to/story";
when(pathResolver.resolve(storyClass)).thenReturn(storyPath);
CandidateSteps steps = mock(CandidateSteps.class);
// When
MyStory story = new MyStory(new MostUsefulConfiguration(), steps);
assertThat(story.configuration(), is(not(sameInstance(configuration))));
story.useConfiguration(configuration);
assertThat(story.configuration(), is(sameInstance(configuration)));
story.useEmbedder(embedder);
story.run();
// Then
verify(embedder).useConfiguration(configuration);
verify(embedder).useCandidateSteps(Mockito.eq(Arrays.asList(steps)));
verify(embedder).runStoriesAsPaths(asList(storyPath));
}
Aggregations