Search in sources :

Example 1 with PendingStep

use of org.jbehave.core.steps.StepCreator.PendingStep in project jbehave-core by jbehave.

the class MarkUnmatchedStepsAsPending method addMatchedSteps.

private void addMatchedSteps(List<String> stepsAsString, List<Step> steps, Map<String, String> namedParameters, List<CandidateSteps> candidateSteps, Outcome outcome, StepMonitor stepMonitor) {
    List<StepCandidate> allCandidates = stepFinder.collectCandidates(candidateSteps);
    String previousNonAndStep = null;
    for (String stepAsString : stepsAsString) {
        // pending is default step, overridden below
        Step step = StepCreator.createPendingStep(stepAsString, previousNonAndStep);
        List<Step> composedSteps = new ArrayList<>();
        List<StepCandidate> prioritisedCandidates = stepFinder.prioritise(stepAsString, allCandidates);
        for (StepCandidate candidate : prioritisedCandidates) {
            candidate.useStepMonitor(stepMonitor);
            if (candidate.ignore(stepAsString)) {
                // ignorable steps are added so they can be reported
                step = StepCreator.createIgnorableStep(stepAsString);
                break;
            }
            if (candidate.comment(stepAsString)) {
                // comments are added so they can be reported
                step = StepCreator.createComment(stepAsString);
                break;
            }
            if (matchesCandidate(stepAsString, previousNonAndStep, candidate)) {
                // step matches candidate
                if (candidate.isPending()) {
                    ((PendingStep) step).annotatedOn(candidate.getMethod());
                } else {
                    if (outcome != null) {
                        step = candidate.createMatchedStepUponOutcome(stepAsString, namedParameters, outcome);
                    } else {
                        step = candidate.createMatchedStep(stepAsString, namedParameters);
                    }
                    if (candidate.isComposite()) {
                        candidate.addComposedSteps(composedSteps, stepAsString, namedParameters, allCandidates);
                    }
                }
                if (!(candidate.isAndStep(stepAsString) || candidate.isIgnorableStep(stepAsString))) {
                    // only update previous step if not AND or IGNORABLE step
                    previousNonAndStep = stepAsString;
                }
                break;
            }
        }
        if (!(keywords.isAndStep(stepAsString) || keywords.isIgnorableStep(stepAsString))) {
            previousNonAndStep = stepAsString;
        }
        steps.add(step);
        steps.addAll(composedSteps);
    }
}
Also used : PendingStep(org.jbehave.core.steps.StepCreator.PendingStep) ArrayList(java.util.ArrayList) PendingStep(org.jbehave.core.steps.StepCreator.PendingStep)

Example 2 with PendingStep

use of org.jbehave.core.steps.StepCreator.PendingStep in project jbehave-core by jbehave.

the class PendingStepMethodGeneratorBehaviour method shouldNormaliseStepPatternToJavaCompatibleMethodNameAndString.

@Test
public void shouldNormaliseStepPatternToJavaCompatibleMethodNameAndString() throws IntrospectionException {
    // When
    String pattern = "I'm searching for \".*\", and for others chars such as :;!|, and I look for <this>: $ \\ / () {} [] ";
    PendingStep pendingStep = (PendingStep) StepCreator.createPendingStep("When " + pattern, null);
    // Then
    String method = "@When(\"" + escapeJava(pattern) + "\")\n" + "@Pending\n" + "public void whenImSearchingForAndForOthersCharsSuchAsAndILookForthis() {\n" + "  // PENDING\n" + "}\n";
    assertThat(generator.generateMethod(pendingStep), equalTo(method));
    // test basically all characters (issue JBEHAVE-710)
    // When
    pattern = "I'm searching for ";
    for (int i = 32; i < 128; i++) {
        pattern += (char) i;
    }
    pendingStep = (PendingStep) StepCreator.createPendingStep("When " + pattern, null);
    // Then
    method = "@When(\"" + escapeJava(pattern) + "\")\n" + "@Pending\n" + "public void whenImSearchingFor0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz() {\n" + "  // PENDING\n" + "}\n";
    assertThat(generator.generateMethod(pendingStep), equalTo(method));
    // When
    pattern = "I'm searching for ";
    for (int i = 160; i < 256; i++) {
        pattern += (char) i;
    }
    pendingStep = (PendingStep) StepCreator.createPendingStep("When " + pattern, null);
    // Then
    method = "@When(\"" + escapeJava(pattern) + "\")\n" + "@Pending\n" + "public void whenImSearchingFor¢£¤¥ª­µºÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ() {\n" + "  // PENDING\n" + "}\n";
    assertThat(generator.generateMethod(pendingStep), equalTo(method));
}
Also used : PendingStep(org.jbehave.core.steps.StepCreator.PendingStep) Test(org.junit.Test)

Example 3 with PendingStep

use of org.jbehave.core.steps.StepCreator.PendingStep in project jbehave-core by jbehave.

the class PendingStepMethodGeneratorBehaviour method shouldGenerateMethodForNonAndPendingStep.

@Test
public void shouldGenerateMethodForNonAndPendingStep() throws IntrospectionException {
    // When
    PendingStep pendingStep = (PendingStep) StepCreator.createPendingStep("When I am pending", null);
    // Then
    String method = "@When(\"I am pending\")\n" + "@Pending\n" + "public void whenIAmPending() {\n" + "  // PENDING\n" + "}\n";
    assertThat(generator.generateMethod(pendingStep), equalTo(method));
}
Also used : PendingStep(org.jbehave.core.steps.StepCreator.PendingStep) Test(org.junit.Test)

Example 4 with PendingStep

use of org.jbehave.core.steps.StepCreator.PendingStep in project jbehave-core by jbehave.

the class MarkUnmatchedStepsAsPendingBehaviour method assertIsPending.

private void assertIsPending(Step step, String stepAsString, String previousNonAndStep) {
    assertThat(step, instanceOf(PendingStep.class));
    PendingStep pendingStep = (PendingStep) step;
    assertThat(pendingStep.stepAsString(), equalTo(stepAsString));
    assertThat(pendingStep.previousNonAndStepAsString(), equalTo(previousNonAndStep));
    Throwable throwable = step.perform(null).getFailure();
    assertThat(throwable, instanceOf(PendingStepFound.class));
    assertThat(throwable.getMessage(), equalTo(stepAsString));
}
Also used : PendingStepFound(org.jbehave.core.failures.PendingStepFound) PendingStep(org.jbehave.core.steps.StepCreator.PendingStep)

Example 5 with PendingStep

use of org.jbehave.core.steps.StepCreator.PendingStep in project jbehave-core by jbehave.

the class PendingStepMethodGeneratorBehaviour method shouldGenerateMethodForAndPendingStepWithPreviousNonAndStep.

@Test
public void shouldGenerateMethodForAndPendingStepWithPreviousNonAndStep() throws IntrospectionException {
    // When
    PendingStep pendingStep = (PendingStep) StepCreator.createPendingStep("And I am pending", "Given I was pending");
    // Then
    String method = "@Given(\"I am pending\")\n" + "@Pending\n" + "public void givenIAmPending() {\n" + "  // PENDING\n" + "}\n";
    assertThat(generator.generateMethod(pendingStep), equalTo(method));
}
Also used : PendingStep(org.jbehave.core.steps.StepCreator.PendingStep) Test(org.junit.Test)

Aggregations

PendingStep (org.jbehave.core.steps.StepCreator.PendingStep)7 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 ParametrisedStep (org.jbehave.core.steps.StepCreator.ParametrisedStep)2 FailingUponPendingStep (org.jbehave.core.failures.FailingUponPendingStep)1 PendingStepFound (org.jbehave.core.failures.PendingStepFound)1 PendingStepMethodGenerator (org.jbehave.core.steps.PendingStepMethodGenerator)1 Step (org.jbehave.core.steps.Step)1