logo

Derive Macro cucumber::Parameter

source · []
#[derive(Parameter)]
{
    // Attributes available to this derive:
    #[param]
}
Available on crate feature macros only.
Expand description

In addition to default parameters of Cucumber Expressions, you may implement and use custom ones.

Example

use cucumber::{given, when, Parameter, World};
use derive_more::{Deref, FromStr};

#[derive(Debug, Default, World)]
struct MyWorld;

#[given(regex = r"^(\S+) is (\d+)$")]
#[when(expr = "{word} is {u64}")]
fn test(w: &mut MyWorld, param: String, num: CustomU64) {
    assert_eq!(param, "foo");
    assert_eq!(*num, 0);
}

#[derive(Deref, FromStr, Parameter)]
#[param(regex = r"\d+", name = "u64")]
struct CustomU64(u64);

Attribute arguments

  • #[param(regex = "regex")]

    Regex to match this parameter. Usually shouldn’t contain any capturing groups, but in case it requires to do so, only the first non-empty group will be matched as the result.

  • #[param(name = "name")] (optional)

    Name of this parameter to reference it by. If not specified, then lower-cased type name will be used by default.