pub enum StepKeyword {
Given,
When,
Then,
And,
But,
}Expand description
Keyword used to categorise a step definition.
The enum includes And and But variants for completeness, but feature
parsing resolves them against the preceding Given/When/Then using
the resolve method.
Variants§
Given
Setup preconditions for a scenario.
When
Perform an action when testing behaviour.
Then
Assert the expected outcome of a scenario.
And
Additional conditions that share context with the previous step.
But
Negative or contrasting conditions.
Implementations§
Source§impl StepKeyword
impl StepKeyword
Sourcepub const fn as_str(&self) -> &'static str
pub const fn as_str(&self) -> &'static str
Return the keyword as a string slice.
§Examples
use rstest_bdd_patterns::StepKeyword;
assert_eq!(StepKeyword::Given.as_str(), "Given");
assert_eq!(StepKeyword::And.as_str(), "And");Sourcepub fn resolve(self, prev: &mut Option<Self>) -> Self
pub fn resolve(self, prev: &mut Option<Self>) -> Self
Resolve conjunctions to the semantic keyword of the previous step.
When the current keyword is And or But, returns the value stored in
prev. For primary keywords (Given/When/Then), updates prev and
returns the keyword unchanged.
Callers typically seed prev with the first primary keyword in a
sequence, defaulting to Given when none is found.
§Examples
use rstest_bdd_patterns::StepKeyword;
let mut prev = Some(StepKeyword::Given);
assert_eq!(StepKeyword::And.resolve(&mut prev), StepKeyword::Given);
assert_eq!(StepKeyword::When.resolve(&mut prev), StepKeyword::When);
assert_eq!(prev, Some(StepKeyword::When));Trait Implementations§
Source§impl Clone for StepKeyword
impl Clone for StepKeyword
Source§fn clone(&self) -> StepKeyword
fn clone(&self) -> StepKeyword
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for StepKeyword
impl Debug for StepKeyword
Source§impl FromStr for StepKeyword
impl FromStr for StepKeyword
Source§impl Hash for StepKeyword
impl Hash for StepKeyword
Source§impl PartialEq for StepKeyword
impl PartialEq for StepKeyword
Source§impl TryFrom<&str> for StepKeyword
impl TryFrom<&str> for StepKeyword
Source§impl TryFrom<StepType> for StepKeyword
impl TryFrom<StepType> for StepKeyword
Source§fn try_from(ty: StepType) -> Result<Self, Self::Error>
fn try_from(ty: StepType) -> Result<Self, Self::Error>
Convert a parsed Gherkin StepType to a StepKeyword.
§Gherkin coupling
The gherkin crate (v0.14) defines StepType with only Given, When,
and Then variants. Gherkin syntax also includes And and But
keywords, but the parser resolves these to the preceding primary keyword
before exposing them via StepType.
If a future gherkin release adds new StepType variants (e.g., And,
But, or others), the #[expect(unreachable_patterns)] guard below will
trigger a compiler warning, prompting an update to this match arm.