-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace #[derive(WorldInit)]
macro with #[derive(World)]
(#217)
#219
Conversation
FCM
|
@tyranron I've also decided to remove In case you have a different view, just revert the last commit. All changes related to Before: use std::{convert::Infallible, time::Duration};
use async_trait::async_trait;
use cucumber::{given, then, when, World, WorldInit};
use tokio::time::sleep;
#[derive(Debug, WorldInit)]
struct MyWorld {
user: Option<String>,
capacity: usize,
}
#[async_trait(?Send)]
impl World for MyWorld {
type Error = Infallible;
async fn new() -> Result<Self, Self::Error> {
Ok(Self { user: None, capacity: 0 })
}
}
#[given(expr = "{word} is hungry")] // Cucumber Expression
async fn someone_is_hungry(w: &mut MyWorld, user: String) {
sleep(Duration::from_secs(2)).await;
w.user = Some(user);
}
#[when(regex = r"^(?:he|she|they) eats? (\d+) cucumbers?$")]
async fn eat_cucumbers(w: &mut MyWorld, count: usize) {
sleep(Duration::from_secs(2)).await;
w.capacity += count;
assert!(w.capacity < 4, "{} exploded!", w.user.as_ref().unwrap());
}
#[then("she is full")]
async fn is_full(w: &mut MyWorld) {
sleep(Duration::from_secs(2)).await;
assert_eq!(w.capacity, 3, "{} isn't full!", w.user.as_ref().unwrap());
}
#[tokio::main]
async fn main() {
MyWorld::run("tests/features/readme").await;
} After: use std::time::Duration;
use cucumber::{given, then, when, World};
use tokio::time::sleep;
#[derive(Debug, Default, World)]
struct MyWorld {
user: Option<String>,
capacity: usize,
}
#[given(expr = "{word} is hungry")] // Cucumber Expression
async fn someone_is_hungry(w: &mut MyWorld, user: String) {
sleep(Duration::from_secs(2)).await;
w.user = Some(user);
}
#[when(regex = r"^(?:he|she|they) eats? (\d+) cucumbers?$")]
async fn eat_cucumbers(w: &mut MyWorld, count: usize) {
sleep(Duration::from_secs(2)).await;
w.capacity += count;
assert!(w.capacity < 4, "{} exploded!", w.user.as_ref().unwrap());
}
#[then("she is full")]
async fn is_full(w: &mut MyWorld) {
sleep(Duration::from_secs(2)).await;
assert_eq!(w.capacity, 3, "{} isn't full!", w.user.as_ref().unwrap());
}
#[tokio::main]
async fn main() {
MyWorld::run("tests/features/readme").await;
} |
Resolves #217
Synopsis
To improve ergonomics we should unify
WorldInit
andWorld
traits and macros.Solution
Replace
#[derive(WorldInit)]
macro with#[derive(World)]
and remove theWorldInit
trait by moving all methods from it into theWorld
trait.Checklist
Draft:
prefixDraft:
prefix is removed