Attribute Macro cucumber_rust::then [−][src]
#[then]
This is supported on crate feature
macros
only.Attribute to auto-wire the test to the World
implementer.
There are 3 step-specific attributes:
Example
use cucumber_rust::{given, World, WorldInit}; #[derive(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+)")] fn test(w: &mut MyWorld, param: String, num: i32) { assert_eq!(param, "foo"); assert_eq!(num, 0); } #[tokio::main] async fn main() { let runner = MyWorld::init(&["./features"]); runner.run().await; }
Arguments
- First argument has to be mutable refence to the
WorldInit
deriver (yourWorld
implementer). - Other argument's types have to implement
FromStr
or it has to be a slice where the element type also implementsFromStr
. - To use
gherking::Step
, name the argument asstep
, or mark the argument with a#[given(step)]
attribute.
#[derive(WorldInit)] struct MyWorld; #[given(regex = r"(\S+) is not (\S+)")] fn test_step( w: &mut MyWorld, matches: &[String], #[given(step)] s: &Step, ) { assert_eq!(matches.get(0).unwrap(), "foo"); assert_eq!(matches.get(1).unwrap(), "bar"); assert_eq!(s.value, "foo is bar"); }