Search in sources :

Example 1 with ByLevenshteinDistance

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)));
}
Also used : ByLevenshteinDistance(org.jbehave.core.steps.StepFinder.ByLevenshteinDistance) PendingStep(org.jbehave.core.steps.StepCreator.PendingStep) Test(org.junit.Test)

Example 2 with ByLevenshteinDistance

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();
    }
}
Also used : StoryReporterBuilder(org.jbehave.core.reporters.StoryReporterBuilder) StepFinder(org.jbehave.core.steps.StepFinder) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Embedder(org.jbehave.core.embedder.Embedder) FileNotFoundException(java.io.FileNotFoundException) SilentlyAbsorbingFailure(org.jbehave.core.failures.SilentlyAbsorbingFailure) ByLevenshteinDistance(org.jbehave.core.steps.StepFinder.ByLevenshteinDistance) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) InstanceStepsFactory(org.jbehave.core.steps.InstanceStepsFactory) EmbedderControls(org.jbehave.core.embedder.EmbedderControls) MarkUnmatchedStepsAsPending(org.jbehave.core.steps.MarkUnmatchedStepsAsPending)

Example 3 with ByLevenshteinDistance

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();
    }
}
Also used : StoryReporterBuilder(org.jbehave.core.reporters.StoryReporterBuilder) StepFinder(org.jbehave.core.steps.StepFinder) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Embedder(org.jbehave.core.embedder.Embedder) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SilentlyAbsorbingFailure(org.jbehave.core.failures.SilentlyAbsorbingFailure) ByLevenshteinDistance(org.jbehave.core.steps.StepFinder.ByLevenshteinDistance) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) InstanceStepsFactory(org.jbehave.core.steps.InstanceStepsFactory) EmbedderControls(org.jbehave.core.embedder.EmbedderControls) MarkUnmatchedStepsAsPending(org.jbehave.core.steps.MarkUnmatchedStepsAsPending)

Aggregations

ByLevenshteinDistance (org.jbehave.core.steps.StepFinder.ByLevenshteinDistance)3 FileNotFoundException (java.io.FileNotFoundException)2 Configuration (org.jbehave.core.configuration.Configuration)2 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)2 Embedder (org.jbehave.core.embedder.Embedder)2 EmbedderControls (org.jbehave.core.embedder.EmbedderControls)2 SilentlyAbsorbingFailure (org.jbehave.core.failures.SilentlyAbsorbingFailure)2 LoadFromClasspath (org.jbehave.core.io.LoadFromClasspath)2 StoryReporterBuilder (org.jbehave.core.reporters.StoryReporterBuilder)2 InstanceStepsFactory (org.jbehave.core.steps.InstanceStepsFactory)2 MarkUnmatchedStepsAsPending (org.jbehave.core.steps.MarkUnmatchedStepsAsPending)2 StepFinder (org.jbehave.core.steps.StepFinder)2 IOException (java.io.IOException)1 PendingStep (org.jbehave.core.steps.StepCreator.PendingStep)1 Test (org.junit.Test)1