-
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
Support Cucumber Expressions (#124) #157
Conversation
Current blockers:
|
@ilslv |
# Conflicts: # codegen/src/attribute.rs
FCM
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ilslv we need a clear example of how to use custom parameters in Cucumber Expressions.
Also, a FromStr
example in the Book doesn't actually demonstrate how it works with a parameter captured by a Cucumber Expression.
@tyranron for custom parameters I propose something like this enum Animal {
Cat,
Dog,
Ferris,
}
impl FromStr for Animal {
type Err = &'static str;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"cat" => Ok(Self::Cat),
"dog" => Ok(Self::Dog),
"🦀" => Ok(Self::Ferris),
_ => Err("expected 'cat', 'dog' or '🦀'"),
}
}
}
impl CustomParameter for Animal {
const NAME = "animal";
const REGEX = "cat|dog|🦀";
}
#[then(expr = "the {animal} is not hungry")]
async fn cat_is_fed(world: &mut AnimalWorld, animal: Animal) {
sleep(Duration::from_secs(2)).await;
match animal {
Animal::Cat => assert!(!world.cat.hungry),
Animal::Dog => assert!(!world.dog.hungry),
Animal::Ferris => assert!(!world.ferris.hungry),
};
} With that we can validate that parameter name is right with const assertion. And to validate regex we can even use clippy lint : Playground. UPD: Clippy lint will require our users to run it over tests codebase, which is rarely done. If we want to avoid this, we'll have to implement |
@ilslv let's move this discussion to the issue, because it won't be a part of this PR. And merge this PR only with |
Part of #124
Synopsis
Sometimes
regex
is a bit too much and we want something easier. Cucumber expressions are a great fit in this scenario.Solution
Support in attribute macros with
#[given(expr = "...")]
/#[given(expression = "...")]
Checklist
Draft:
prefixDraft:
prefix is removed