Code Monkey home page Code Monkey logo

Comments (6)

gaeljw avatar gaeljw commented on September 25, 2024

Actually this also apply with optional capture group (not necessarily within non capture group).

Example:

Given("""^I have the name:\s?(.+)?$""") { (name: String) =>
  // Do something
}

(This one might not make much sense but I didn't have a better example in mind)


I think a first step would be to provide a better exception message when this happens.

The proper fix to this issue would be to be able to declare parameters as Options which is for now not supported out of the box.

from cucumber-jvm-scala.

mpkorstanje avatar mpkorstanje commented on September 25, 2024

Can you map java.util.Optional to scalas Option? That should be relatively easy to add to cucumber-expressions.

from cucumber-jvm-scala.

gaeljw avatar gaeljw commented on September 25, 2024

I guess having the ability to have Java's Optional supported out of the box as parameters would be enough indeed.

@mpkorstanje Do you mean I should open an issue on cucumber-expressions? I'll be happy to have a look and work on it of course :)

from cucumber-jvm-scala.

mpkorstanje avatar mpkorstanje commented on September 25, 2024

I'd start of with the PR straight away. Saves us writing an issue 😄

We keep Cucumber expressions in the mono repo.

https://github.com/cucumber/cucumber/tree/master/cucumber-expressions

You'd have to add a case for Optional here:

https://github.com/cucumber/cucumber/blob/master/cucumber-expressions/java/src/main/java/io/cucumber/cucumberexpressions/BuiltInParameterTransformer.java

That way when if an Optional<String> or Optional<Integer> is used as a type hint the parameter is transformed to either a wrapped value or an empty.

from cucumber-jvm-scala.

mpkorstanje avatar mpkorstanje commented on September 25, 2024

The first version of JVM after 6.0.0-RC2 JVM will support optionals

from cucumber-jvm-scala.

gaeljw avatar gaeljw commented on September 25, 2024

Starting Cucumber Scala 6.0.0, it's now possible to have such step definitions:

import java.util.Optional

import io.cucumber.scala.{EN, ScalaDsl}

// Scala 2.13 only, use compat lib or your own converter for 2.12 or 2.11
import scala.jdk.OptionConverters._

class OptionalCaptureGroupsSteps extends ScalaDsl with EN {

  Given("""^I have the name:\s?(.+)?$""") { (name: Optional[String]) =>
    val option: Option[String] = name.toScala
    // Do something
  }

}

from cucumber-jvm-scala.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.