Search code examples
kotlincucumbercucumber-jvm

Is it not possible to have a step definition with no parameters?


I have the following scenario:

Feature: Spheres
  Scenario: A ray intersects a sphere at two points
    Given r ← ray(point(0, 0, -5), vector(0, 0, 1))
    And s ← sphere()
    When xs ← intersect(s, r)
    Then xs.count = 2
    And xs[0] = 4.0
    And xs[1] = 6.0

Trying to keep it simple, I thought I'd write the step definition literally to start off:

import io.cucumber.java8.En

class SphereStepDefinitions: En {
    private val epsilon: Double = 0.00001
    lateinit var s: Sphere
    lateinit var xs : List<Double>

    init {
        Given("s ← sphere\\()") {
            s = Sphere()
        }
    }
}

The result,

The step "s ← sphere()" is undefined. You can implement it using the snippet(s) below:

Given("s ← sphere\\()", () -> {
    // Write code here that turns the phrase above into concrete actions
    throw new io.cucumber.java8.PendingException();
});

Which is exactly the same step string that I specified already. :(

I have many working steps in the project already, but I think this is the first one I have tried where there aren't any parameters... is this just not something that works?

I'm using cucumber-jvm 5.7.0 (tried 5.6.0 and 6.0.0-RC2 as well) with Kotlin 1.3.72, on Java 11.


Solution

  • You're using a Cucumber expression right now. Looks like Cucumber doesn't generate the proper cucumber expression snippet.

    You can either use a regular expresion (by using ^ and $):

    ^s ← sphere\\(\\)$

    Or use:

    s ← sphere() to work around the bug. I'd recommend the former over the latter.