cucumber-rs / cucumber

Cucumber testing framework for Rust. Fully native, no external test runners or dependencies.
https://cucumber-rs.github.io/cucumber/main
Apache License 2.0
564 stars 69 forks source link

📚 Doc: Example of `after_hook` #224

Closed tgsmith61591 closed 2 years ago

tgsmith61591 commented 2 years ago

I'm having a really difficult time understanding how to add an after_hook to my World struct. Is there an example in the documentation you can point me to? This is the closest I can find, and the linked source is not too helpful either.

Assuming I have a world as follows:

#[async_trait(?Send)]
impl World for MyCoolWorld {
    type Error = Infallible;

    async fn new() -> Result<Self, Infallible> {
        Ok(Self {
            thing_one: None,
            thing_two: None,
        })
    }
}

And I'm running like so:

    MyCoolWorld::cucumber()
        .run_and_exit("./products")
        .await;

How/where do I attach an after hook? Is it in the World impl block? Is it a builder when I set up the runner? Any example you can provide would be extremely appreciated!

ilslv commented 2 years ago

We have a separate book chapter covering Scenario hooks. In your case it would look something like

MyCoolWorld::cucumber()
    .after(|feature, rule, scenario, world| {
        // Hook logic here.
    })
    .run_and_exit("./products")
    .await;