Search in sources :

Example 1 with I18n

use of gherkin.I18n in project cucumber-jvm by cucumber.

the class StepDefinitionMatchTest method throws_arity_mismatch_exception_when_there_are_fewer_parameters_than_arguments.

@Test
public void throws_arity_mismatch_exception_when_there_are_fewer_parameters_than_arguments() throws Throwable {
    Step step = new Step(null, "Given ", "I have 4 cukes in my belly", 1, null, null);
    StepDefinition stepDefinition = new StubStepDefinition(new Object(), Object.class.getMethod("toString"), "some pattern");
    StepDefinitionMatch stepDefinitionMatch = new StepDefinitionMatch(asList(new Argument(7, "4")), stepDefinition, null, step, new LocalizedXStreams(getClass().getClassLoader()));
    try {
        stepDefinitionMatch.runStep(new I18n("en"));
        fail();
    } catch (CucumberException expected) {
        assertEquals("Arity mismatch: Step Definition 'toString' with pattern [some pattern] is declared with 0 parameters. However, the gherkin step has 1 arguments [4]. \n" + "Step: Given I have 4 cukes in my belly", expected.getMessage());
    }
}
Also used : Argument(gherkin.formatter.Argument) Step(gherkin.formatter.model.Step) LocalizedXStreams(cucumber.runtime.xstream.LocalizedXStreams) I18n(gherkin.I18n) Test(org.junit.Test)

Example 2 with I18n

use of gherkin.I18n in project cucumber-jvm by cucumber.

the class StepDefinitionMatchTest method throws_arity_mismatch_exception_when_there_are_more_parameters_than_arguments.

@Test
public void throws_arity_mismatch_exception_when_there_are_more_parameters_than_arguments() throws Throwable {
    Step step = new Step(null, "Given ", "I have 4 cukes in my belly", 1, new ArrayList<DataTableRow>(), null);
    StepDefinition stepDefinition = new StubStepDefinition(new Object(), WithTwoParams.class.getMethod("withTwoParams", Integer.TYPE, Short.TYPE, List.class), "some pattern");
    StepDefinitionMatch stepDefinitionMatch = new StepDefinitionMatch(asList(new Argument(7, "4")), stepDefinition, null, step, new LocalizedXStreams(getClass().getClassLoader()));
    try {
        stepDefinitionMatch.runStep(new I18n("en"));
        fail();
    } catch (CucumberException expected) {
        assertEquals("Arity mismatch: Step Definition 'withTwoParams' with pattern [some pattern] is declared with 3 parameters. However, the gherkin step has 2 arguments [4, Table:[]]. \n" + "Step: Given I have 4 cukes in my belly", expected.getMessage());
    }
}
Also used : Argument(gherkin.formatter.Argument) Step(gherkin.formatter.model.Step) LocalizedXStreams(cucumber.runtime.xstream.LocalizedXStreams) ArrayList(java.util.ArrayList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) DataTableRow(gherkin.formatter.model.DataTableRow) I18n(gherkin.I18n) Test(org.junit.Test)

Example 3 with I18n

use of gherkin.I18n in project cucumber-jvm by cucumber.

the class RuntimeTest method runStep.

public void runStep(Reporter reporter, Runtime runtime) {
    Step step = mock(Step.class);
    I18n i18n = mock(I18n.class);
    runtime.runStep("<featurePath>", step, reporter, i18n);
}
Also used : Step(gherkin.formatter.model.Step) I18n(gherkin.I18n)

Example 4 with I18n

use of gherkin.I18n in project cucumber-jvm by cucumber.

the class FeatureBuilder method parse.

public void parse(Resource resource, List<Object> filters) {
    String gherkin = read(resource);
    String checksum = checksum(gherkin);
    String path = pathsByChecksum.get(checksum);
    if (path != null) {
        return;
    }
    pathsByChecksum.put(checksum, resource.getPath());
    Formatter formatter = this;
    if (!filters.isEmpty()) {
        formatter = new FilterFormatter(this, filters);
    }
    Parser parser = new Parser(formatter);
    try {
        parser.parse(gherkin, convertFileSeparatorToForwardSlash(resource.getPath()), 0);
    } catch (Exception e) {
        throw new CucumberException(String.format("Error parsing feature file %s", convertFileSeparatorToForwardSlash(resource.getPath())), e);
    }
    I18n i18n = parser.getI18nLanguage();
    if (currentCucumberFeature != null) {
        // The current feature may be null if we used a very restrictive filter, say a tag that isn't used.
        // Might also happen if the feature file itself is empty.
        currentCucumberFeature.setI18n(i18n);
    }
}
Also used : Formatter(gherkin.formatter.Formatter) FilterFormatter(gherkin.formatter.FilterFormatter) FilterFormatter(gherkin.formatter.FilterFormatter) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Parser(gherkin.parser.Parser) I18n(gherkin.I18n)

Example 5 with I18n

use of gherkin.I18n in project cucumber-jvm by cucumber.

the class FromDataTableTest method runStepDef.

private StepDefs runStepDef(Method method, List<DataTableRow> rows) throws Throwable {
    StepDefs stepDefs = new StepDefs();
    StepDefinition stepDefinition = new StubStepDefinition(stepDefs, method, "some pattern");
    Step stepWithRows = new Step(NO_COMMENTS, "Given ", "something", 10, rows, null);
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    StepDefinitionMatch stepDefinitionMatch = new StepDefinitionMatch(NO_ARGS, stepDefinition, "some.feature", stepWithRows, new LocalizedXStreams(classLoader));
    stepDefinitionMatch.runStep(new I18n("en"));
    return stepDefs;
}
Also used : StubStepDefinition(cucumber.runtime.StubStepDefinition) StepDefinition(cucumber.runtime.StepDefinition) StubStepDefinition(cucumber.runtime.StubStepDefinition) Step(gherkin.formatter.model.Step) StepDefinitionMatch(cucumber.runtime.StepDefinitionMatch) LocalizedXStreams(cucumber.runtime.xstream.LocalizedXStreams) I18n(gherkin.I18n)

Aggregations

I18n (gherkin.I18n)6 Step (gherkin.formatter.model.Step)5 LocalizedXStreams (cucumber.runtime.xstream.LocalizedXStreams)3 Test (org.junit.Test)3 Argument (gherkin.formatter.Argument)2 StepDefinition (cucumber.runtime.StepDefinition)1 StepDefinitionMatch (cucumber.runtime.StepDefinitionMatch)1 StubStepDefinition (cucumber.runtime.StubStepDefinition)1 FilterFormatter (gherkin.formatter.FilterFormatter)1 Formatter (gherkin.formatter.Formatter)1 DataTableRow (gherkin.formatter.model.DataTableRow)1 Parser (gherkin.parser.Parser)1 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1