use of org.jbehave.core.steps.StepFinder.ByLevenshteinDistance in project jbehave-core by jbehave.
the class MarkUnmatchedStepsAsPendingBehaviour method shouldPrioritiseCandidateStepsByInjectableStrategy.
@Test
public void shouldPrioritiseCandidateStepsByInjectableStrategy() {
// Given some candidate steps classes
// and some methods split across them
CandidateSteps steps1 = mock(Steps.class);
CandidateSteps steps2 = mock(Steps.class);
StepCandidate candidate1 = mock(StepCandidate.class);
StepCandidate candidate2 = mock(StepCandidate.class);
StepCandidate candidate3 = mock(StepCandidate.class);
StepCandidate candidate4 = mock(StepCandidate.class);
Step step1 = mock(Step.class);
Step step2 = mock(Step.class);
Step step3 = mock(Step.class);
Step step4 = mock(Step.class);
when(steps1.listCandidates()).thenReturn(asList(candidate1, candidate2));
when(steps2.listCandidates()).thenReturn(asList(candidate3, candidate4));
// all matching the same step string with different priorities
String stepAsString = "Given a step";
when(candidate1.matches(stepAsString)).thenReturn(true);
when(candidate2.matches(stepAsString)).thenReturn(true);
when(candidate3.matches(stepAsString)).thenReturn(true);
when(candidate4.matches(stepAsString)).thenReturn(true);
when(candidate1.getPatternAsString()).thenReturn("Given I do something");
when(candidate2.getPatternAsString()).thenReturn("When I do something ");
when(candidate3.getPatternAsString()).thenReturn("Then I do something");
when(candidate4.getPatternAsString()).thenReturn("And I do something");
when(candidate1.createMatchedStep(stepAsString, parameters)).thenReturn(step1);
when(candidate2.createMatchedStep(stepAsString, parameters)).thenReturn(step2);
when(candidate3.createMatchedStep(stepAsString, parameters)).thenReturn(step3);
when(candidate4.createMatchedStep(stepAsString, parameters)).thenReturn(step4);
StepCollector stepCollector = new MarkUnmatchedStepsAsPending(new StepFinder(new ByLevenshteinDistance()));
List<Step> steps = stepCollector.collectScenarioSteps(asList(steps1, steps2), createScenario(stepAsString), parameters);
// Then the step with highest priority is returned
assertThat(step4, equalTo(steps.get(0)));
}
use of org.jbehave.core.steps.StepFinder.ByLevenshteinDistance in project jbehave-core by jbehave.
the class ReportTransformBehaviour method runStories.
private void runStories(String... storyPaths) {
StoryReporterBuilder storyReporterBuilder = new StoryReporterBuilder().withDefaultFormats().withCodeLocation(CodeLocations.codeLocationFromClass(ReportTransformBehaviour.class)).withFormats(Format.XML);
Configuration configuration = new MostUsefulConfiguration().useStoryLoader(new LoadFromClasspath(this.getClass())).useStoryReporterBuilder(storyReporterBuilder).useFailureStrategy(new SilentlyAbsorbingFailure()).useStepCollector(new MarkUnmatchedStepsAsPending(new StepFinder(new ByLevenshteinDistance())));
Embedder embedder = new Embedder();
embedder.useEmbedderControls(new EmbedderControls().doGenerateViewAfterStories(false));
embedder.useConfiguration(configuration);
embedder.useCandidateSteps(new InstanceStepsFactory(configuration, new MySteps()).createCandidateSteps());
embedder.useMetaFilters(asList("-skip true"));
try {
embedder.runStoriesAsPaths(asList(storyPaths));
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.jbehave.core.steps.StepFinder.ByLevenshteinDistance in project jbehave-core by jbehave.
the class ReportTransformBehaviour method runStories.
private void runStories(String... storyPaths) {
StoryReporterBuilder storyReporterBuilder = new StoryReporterBuilder().withDefaultFormats().withCodeLocation(CodeLocations.codeLocationFromClass(ReportTransformBehaviour.class)).withFormats(Format.XML);
Configuration configuration = new MostUsefulConfiguration().useStoryLoader(new LoadFromClasspath(this.getClass())).useStoryReporterBuilder(storyReporterBuilder).useFailureStrategy(new SilentlyAbsorbingFailure()).useStepCollector(new MarkUnmatchedStepsAsPending(new StepFinder(new ByLevenshteinDistance())));
Embedder embedder = new Embedder();
embedder.useEmbedderControls(new EmbedderControls().doGenerateViewAfterStories(false));
embedder.useConfiguration(configuration);
embedder.useCandidateSteps(new InstanceStepsFactory(configuration, new MySteps()).createCandidateSteps());
embedder.useMetaFilters(asList("-skip true"));
try {
embedder.runStoriesAsPaths(asList(storyPaths));
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations