use of org.jbehave.core.configuration.Configuration 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.configuration.Configuration 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);
}
use of org.jbehave.core.configuration.Configuration in project jbehave-core by jbehave.
the class LocalizedKeywordsBehaviour method shouldAllowKeywordsToBeConfigured.
@Test
public void shouldAllowKeywordsToBeConfigured() {
Configuration configuration = new MostUsefulConfiguration();
ensureKeywordsAreLocalised(configuration, new Locale("en"));
configuration.useKeywords(new LocalizedKeywords(new Locale("it")));
ensureKeywordsAreLocalised(configuration, new Locale("it"));
}
use of org.jbehave.core.configuration.Configuration in project jbehave-core by jbehave.
the class ConfigurableEmbedderBehaviour method shouldAllowAdditionOfSteps.
@Test
public void shouldAllowAdditionOfSteps() 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(configuration, steps);
story.useEmbedder(embedder);
story.run();
// Then
verify(embedder).runStoriesAsPaths(asList(storyPath));
}
use of org.jbehave.core.configuration.Configuration in project jbehave-core by jbehave.
the class StepsBehaviour method shouldAllowLocalizationOfSteps.
@Test
public void shouldAllowLocalizationOfSteps() {
Configuration configuration = new MostUsefulConfiguration();
configuration.useKeywords(new LocalizedKeywords(new Locale("it")));
LocalizedSteps steps = new LocalizedSteps(configuration);
List<StepCandidate> candidates = steps.listCandidates();
assertThat(candidates.size(), equalTo(3));
findCandidate(candidates, "GIVEN un dato che").createMatchedStep("Dato che un dato che", tableRow).perform(null);
findCandidate(candidates, "WHEN un quando").createMatchedStep("Quando un quando", tableRow).perform(null);
findCandidate(candidates, "THEN un allora").createMatchedStep("Allora un allora", tableRow).perform(null);
assertThat(steps.givens, equalTo(1));
assertThat(steps.whens, equalTo(1));
assertThat(steps.thens, equalTo(1));
}
Aggregations