Search in sources :

Example 46 with Step

use of gherkin.formatter.model.Step in project cucumber-jvm by cucumber.

the class CucumberScenarioOutlineTest method allows_doc_strings_to_be_empty_after_replacement.

@Test
public void allows_doc_strings_to_be_empty_after_replacement() {
    Step outlineStep = new Step(C, null, "Some step", 0, null, new DocString(null, "<doc string>", 1));
    Step exampleStep = CucumberScenarioOutline.createExampleStep(outlineStep, new ExamplesTableRow(C, asList("doc string"), 1, ""), new ExamplesTableRow(C, asList(""), 1, ""));
    assertEquals("", exampleStep.getDocString().getValue());
}
Also used : ExamplesTableRow(gherkin.formatter.model.ExamplesTableRow) DocString(gherkin.formatter.model.DocString) Step(gherkin.formatter.model.Step) Test(org.junit.Test)

Example 47 with Step

use of gherkin.formatter.model.Step in project intellij-plugins by JetBrains.

the class JavaStepDefinitionCreator method buildStepDefinitionByStep.

private static PsiMethod buildStepDefinitionByStep(@NotNull final GherkinStep step, Language language) {
    String annotationPackage = new AnnotationPackageProvider().getAnnotationPackageFor(step);
    String methodAnnotation = String.format("@%s.", annotationPackage);
    final Step cucumberStep = new Step(new ArrayList<>(), step.getKeyword().getText(), step.getStepName(), 0, null, null);
    final SnippetGenerator generator = new SnippetGenerator(new JavaSnippet());
    final String snippet = generator.getSnippet(cucumberStep, new FunctionNameGenerator(new CamelCaseConcatenator())).replace("PendingException", CucumberJavaUtil.getCucumberPendingExceptionFqn(step)).replaceFirst("@", methodAnnotation).replaceAll("\\\\\\\\", "\\\\").replaceAll("\\\\d", "\\\\\\\\d");
    JVMElementFactory factory = JVMElementFactories.requireFactory(language, step.getProject());
    return factory.createMethodFromText(snippet, step);
}
Also used : CamelCaseConcatenator(cucumber.runtime.snippets.CamelCaseConcatenator) SnippetGenerator(cucumber.runtime.snippets.SnippetGenerator) FunctionNameGenerator(cucumber.runtime.snippets.FunctionNameGenerator) Step(gherkin.formatter.model.Step) GherkinStep(org.jetbrains.plugins.cucumber.psi.GherkinStep)

Example 48 with Step

use of gherkin.formatter.model.Step in project intellij-plugins by JetBrains.

the class GrStepDefinitionCreator method buildStepDefinitionByStep.

private static GrMethodCall buildStepDefinitionByStep(@NotNull final GherkinStep step) {
    final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(step.getProject());
    final Step cucumberStep = new Step(Collections.emptyList(), step.getKeyword().getText(), step.getStepName(), 0, null, null);
    SnippetGenerator generator = new SnippetGenerator(new GroovySnippet());
    final String fqnPendingException;
    if (GrCucumberUtil.isCucumber_1_1_orAbove(step)) {
        fqnPendingException = "cucumber.api.PendingException";
    } else {
        fqnPendingException = "cucumber.runtime.PendingException";
    }
    String snippet = generator.getSnippet(cucumberStep, null).replace("PendingException", fqnPendingException);
    return (GrMethodCall) factory.createStatementFromText(snippet, step);
}
Also used : GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) SnippetGenerator(cucumber.runtime.snippets.SnippetGenerator) Step(gherkin.formatter.model.Step) GherkinStep(org.jetbrains.plugins.cucumber.psi.GherkinStep) GroovySnippet(cucumber.runtime.groovy.GroovySnippet)

Example 49 with Step

use of gherkin.formatter.model.Step in project allure-cucumberjvm by allure-framework.

the class AllureReporter method extractStep.

private Step extractStep(StepDefinitionMatch match) {
    try {
        Field step = match.getClass().getDeclaredField("step");
        step.setAccessible(true);
        return (Step) step.get(match);
    } catch (ReflectiveOperationException e) {
        //shouldn't ever happen
        LOG.error(e.getMessage(), e);
        throw new CucumberException(e);
    }
}
Also used : Field(java.lang.reflect.Field) Step(gherkin.formatter.model.Step) CucumberException(cucumber.runtime.CucumberException)

Example 50 with Step

use of gherkin.formatter.model.Step in project allure-cucumberjvm by allure-framework.

the class AllureReporter method match.

@Override
public void match(Match match) {
    if (match instanceof StepDefinitionMatch) {
        this.match = (StepDefinitionMatch) match;
        Step step = extractStep(this.match);
        synchronized (gherkinSteps) {
            while (gherkinSteps.peek() != null && !isEqualSteps(step, gherkinSteps.peek())) {
                fireCanceledStep(gherkinSteps.remove());
            }
            if (isEqualSteps(step, gherkinSteps.peek())) {
                gherkinSteps.remove();
            }
        }
        String name = this.getStepName(step);
        ALLURE_LIFECYCLE.fire(new StepStartedEvent(name).withTitle(name));
        createDataTableAttachment(step.getRows());
    }
}
Also used : StepDefinitionMatch(cucumber.runtime.StepDefinitionMatch) Step(gherkin.formatter.model.Step)

Aggregations

Step (gherkin.formatter.model.Step)50 Test (org.junit.Test)34 LocalizedXStreams (cucumber.runtime.xstream.LocalizedXStreams)9 Argument (gherkin.formatter.Argument)9 ExamplesTableRow (gherkin.formatter.model.ExamplesTableRow)7 Scenario (gherkin.formatter.model.Scenario)7 DocString (gherkin.formatter.model.DocString)6 Description (org.junit.runner.Description)6 I18n (gherkin.I18n)5 CucumberFeature (cucumber.runtime.model.CucumberFeature)4 DataTableRow (gherkin.formatter.model.DataTableRow)4 Match (gherkin.formatter.model.Match)4 CucumberException (cucumber.runtime.CucumberException)3 SnippetGenerator (cucumber.runtime.snippets.SnippetGenerator)3 Tag (gherkin.formatter.model.Tag)3 GherkinStep (org.jetbrains.plugins.cucumber.psi.GherkinStep)3 RunNotifier (org.junit.runner.notification.RunNotifier)3 Given (cucumber.api.java.en.Given)2 StepDefinition (cucumber.runtime.StepDefinition)2 StepDefinitionMatch (cucumber.runtime.StepDefinitionMatch)2