cucumber does stuff
Cargo Check, Format, Fix and Test / cargo CI (push) Failing after 1m20s Details

This commit is contained in:
Christoph J. Scherr 2024-01-12 14:22:02 +01:00
parent c5498b5b12
commit 03a972366b
Signed by: cscherrNT
GPG Key ID: 8E2B45BC51A27EA7
6 changed files with 868 additions and 15 deletions

801
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -5,4 +5,11 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dev-dependencies]
futures = "0.3.30"
cucumber = "0.20.2"
tokio = { version = "1.10", features = ["macros", "rt-multi-thread", "time"] }
[[test]]
name = "example" # this should be the same as the filename of your test target
harness = false # allows Cucumber to print output instead of libtest

View File

@ -0,0 +1 @@
// see tests/example.rs

View File

@ -1,3 +0,0 @@
fn main() {
println!("Hello, world!");
}

View File

@ -0,0 +1,58 @@
use cucumber::{given, then, when, World};
// These `Cat` definitions would normally be inside your project's code,
// not test code, but we create them here for the show case.
#[derive(Debug, Default)]
struct Cat {
pub hungry: bool,
}
impl Cat {
fn feed(&mut self) {
self.hungry = false;
}
}
// `World` is your shared, likely mutable state.
// Cucumber constructs it via `Default::default()` for each scenario.
#[derive(Debug, World)]
// Accepts both sync/async and fallible/infallible functions.
// We can set a non default constructor like this vvvv
#[world(init = Self::new)]
pub struct AnimalWorld {
cat: Cat,
}
// new constructor
impl AnimalWorld {
fn new() -> Self {
Self {
cat: Cat { hungry: true },
}
}
}
// Steps are defined with `given`, `when` and `then` attributes.
#[given(regex = r"^a (hungry|satiated) cat$")]
async fn hungry_cat(world: &mut AnimalWorld, state: String) {
match state.as_str() {
"hungry" => world.cat.hungry = true,
"satiated" => world.cat.hungry = false,
_ => unreachable!(),
}
}
#[when("I feed the cat")]
async fn feed_cat(world: &mut AnimalWorld) {
world.cat.feed();
}
#[then("the cat is not hungry")]
async fn cat_is_fed(world: &mut AnimalWorld) {
assert!(!world.cat.hungry);
}
#[tokio::main]
async fn main() {
futures::executor::block_on(AnimalWorld::run("tests/features/book/animal.feature"));
}

View File

@ -0,0 +1,11 @@
Feature: Animal feature
Scenario: If we feed a hungry cat it will no longer be hungry
Given a hungry cat
When I feed the cat
Then the cat is not hungry
Scenario: If we feed a satiated cat it will not become hungry
Given a satiated cat
When I feed the cat
Then the cat is not hungry