Derive Macro cucumber::Parameter [−][src]
#[derive(Parameter)]
{
// Attributes available to this derive:
#[param]
}
Expand description
In addition to default parameters of Cucumber Expressions, you may implement and use custom ones.
Example
use cucumber::{given, when, Parameter, World, WorldInit};
use derive_more::{Deref, FromStr};
#[derive(Debug, WorldInit)]
struct MyWorld;
#[async_trait(?Send)]
impl World for MyWorld {
type Error = Infallible;
async fn new() -> Result<Self, Self::Error> {
Ok(Self)
}
}
#[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. Shouldn’t contain any capturing groups. -
#[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.