Search in sources :

Example 6 with CucumberException

use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.

the class StepDefinitionMatchTest method throws_arity_mismatch_exception_when_there_are_more_parameters_than_arguments.

@Test
void throws_arity_mismatch_exception_when_there_are_more_parameters_than_arguments() {
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given I have 4 cukes in my belly\n" + "       | A | B | \n" + "       | C | D | \n");
    Step step = feature.getPickles().get(0).getSteps().get(0);
    StepDefinition stepDefinition = new StubStepDefinition("I have {int} cukes in my belly", Integer.TYPE, Short.TYPE, List.class);
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    CoreStepDefinition coreStepDefinition = new CoreStepDefinition(id, stepDefinition, expression);
    List<Argument> arguments = coreStepDefinition.matchedArguments(step);
    PickleStepDefinitionMatch stepDefinitionMatch = new PickleStepDefinitionMatch(arguments, stepDefinition, null, step);
    Executable testMethod = () -> stepDefinitionMatch.runStep(null);
    CucumberException actualThrown = assertThrows(CucumberException.class, testMethod);
    assertThat("Unexpected exception message", actualThrown.getMessage(), is(equalTo("Step [I have {int} cukes in my belly] is defined with 3 parameters at '{stubbed location with details}'.\n" + "However, the gherkin step has 2 arguments:\n" + " * 4\n" + " * Table:\n" + "      | A | B |\n" + "      | C | D |\n" + "\n" + "Step text: I have 4 cukes in my belly")));
}
Also used : Argument(io.cucumber.core.stepexpression.Argument) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) Step(io.cucumber.core.gherkin.Step) CucumberException(io.cucumber.core.exception.CucumberException) Executable(org.junit.jupiter.api.function.Executable) Feature(io.cucumber.core.gherkin.Feature) StepExpression(io.cucumber.core.stepexpression.StepExpression) Test(org.junit.jupiter.api.Test)

Example 7 with CucumberException

use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.

the class StepExpressionFactoryTest method throws_for_unknown_parameter_types.

@Test
void throws_for_unknown_parameter_types() {
    StepDefinition stepDefinition = new StubStepDefinition("Given a {unknownParameterType}");
    List<Envelope> events = new ArrayList<>();
    bus.registerHandlerFor(Envelope.class, events::add);
    CucumberException exception = assertThrows(CucumberException.class, () -> stepExpressionFactory.createExpression(stepDefinition));
    assertThat(exception.getMessage(), is("" + "Could not create a cucumber expression for 'Given a {unknownParameterType}'.\n" + "It appears you did not register a parameter type."));
    assertThat(events, iterableWithSize(1));
    assertNotNull(events.get(0).getUndefinedParameterType());
}
Also used : ArrayList(java.util.ArrayList) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) CucumberException(io.cucumber.core.exception.CucumberException) Envelope(io.cucumber.messages.types.Envelope) Test(org.junit.jupiter.api.Test)

Example 8 with CucumberException

use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.

the class PluginFactoryTest method fails_to_instantiate_plugin_that_wants_a_file_without_file_arg.

@Test
void fails_to_instantiate_plugin_that_wants_a_file_without_file_arg() {
    PluginOption option = parse(WantsFile.class.getName());
    Executable testMethod = () -> fc.create(option);
    CucumberException exception = assertThrows(CucumberException.class, testMethod);
    assertThat(exception.getMessage(), is(equalTo("You must supply an output argument to io.cucumber.core.plugin.PluginFactoryTest$WantsFile. Like so: io.cucumber.core.plugin.PluginFactoryTest$WantsFile:DIR|FILE|URL")));
}
Also used : PluginOption(io.cucumber.core.options.PluginOption) CucumberException(io.cucumber.core.exception.CucumberException) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 9 with CucumberException

use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.

the class ResourceScannerTest method scanForResourcesNestedJarUri.

@Test
void scanForResourcesNestedJarUri() {
    URI jarFileUri = new File("src/test/resources/io/cucumber/core/resource/test/spring-resource.jar").toURI();
    URI resourceUri = URI.create("jar:file://" + jarFileUri.getSchemeSpecificPart() + "!/BOOT-INF/lib/jar-resource.jar!/com/example/package-jar-resource.txt");
    CucumberException exception = assertThrows(CucumberException.class, () -> resourceScanner.scanForResourcesUri(resourceUri));
    assertThat(exception.getMessage(), containsString("Cucumber currently doesn't support classpath scanning in nested jars."));
}
Also used : CucumberException(io.cucumber.core.exception.CucumberException) URI(java.net.URI) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 10 with CucumberException

use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.

the class PluginFactoryTest method fails_to_instantiate_plugin_that_declares_two_single_arg_constructors_when_argument_specified.

@Test
void fails_to_instantiate_plugin_that_declares_two_single_arg_constructors_when_argument_specified() {
    PluginOption option = parse(WantsFileOrURL.class.getName() + ":some_arg");
    Executable testMethod = () -> fc.create(option);
    CucumberException exception = assertThrows(CucumberException.class, testMethod);
    assertThat(exception.getMessage(), is(equalTo("class io.cucumber.core.plugin.PluginFactoryTest$WantsFileOrURL must have exactly one constructor that declares a single parameter of one of: [class java.lang.String, class java.io.File, class java.net.URI, class java.net.URL, class java.io.OutputStream, interface java.lang.Appendable]")));
}
Also used : PluginOption(io.cucumber.core.options.PluginOption) CucumberException(io.cucumber.core.exception.CucumberException) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Aggregations

CucumberException (io.cucumber.core.exception.CucumberException)39 Test (org.junit.jupiter.api.Test)28 Executable (org.junit.jupiter.api.function.Executable)19 StepDefinition (io.cucumber.core.backend.StepDefinition)12 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)12 Feature (io.cucumber.core.gherkin.Feature)11 Step (io.cucumber.core.gherkin.Step)11 Argument (io.cucumber.core.stepexpression.Argument)11 StepExpression (io.cucumber.core.stepexpression.StepExpression)8 PluginOption (io.cucumber.core.options.PluginOption)5 CucumberBackendException (io.cucumber.core.backend.CucumberBackendException)4 IOException (java.io.IOException)3 URI (java.net.URI)3 Options (io.cucumber.core.backend.Options)2 DataTableType (io.cucumber.datatable.DataTableType)2 File (java.io.File)2 InputStream (java.io.InputStream)2 URLClassLoader (java.net.URLClassLoader)2 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2