-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
@serial
scenarios continue running after failure on `.fail_fast…
…()` option (#252) - make `runner::Basic::fail_fast()` available as `Cucumber::fail_fast()`
- Loading branch information
Showing
11 changed files
with
199 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Feature: FromStr | ||
Scenario: FromStr | ||
Given regex: int: 42 | ||
And expr: int: 42 | ||
And regex: quoted: 'inner' | ||
And expr: quoted: 'inner' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Feature: Result | ||
|
||
Scenario: Given ok | ||
Given ok | ||
|
||
Scenario: When ok | ||
When ok | ||
|
||
Scenario: Then ok | ||
Then ok | ||
|
||
Scenario: Given error | ||
Given error | ||
|
||
Scenario: When error | ||
When error | ||
|
||
Scenario: Then error | ||
Then error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Feature: retry fail fast | ||
|
||
@serial | ||
Scenario Outline: attempts | ||
Given attempt <attempt> | ||
|
||
Examples: | ||
| attempt | | ||
| 1 | | ||
| 2 | | ||
| 3 | | ||
| 4 | | ||
| 5 | | ||
| 6 | | ||
| 7 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use std::{convert::Infallible, str::FromStr}; | ||
|
||
use cucumber::{given, Parameter, StatsWriter as _, World}; | ||
|
||
#[derive(Debug, Parameter, PartialEq)] | ||
#[param(name = "param", regex = "'([^']*)'|(\\d+)")] | ||
enum Param { | ||
Int(u64), | ||
Quoted(String), | ||
} | ||
|
||
impl FromStr for Param { | ||
type Err = Infallible; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
Ok(s.parse::<u64>() | ||
.map_or_else(|_| Self::Quoted(s.to_owned()), Param::Int)) | ||
} | ||
} | ||
|
||
#[given(regex = "^regex: int: (\\d+)$")] | ||
#[given(expr = "expr: int: {param}")] | ||
fn assert_int(_: &mut W, v: Param) { | ||
assert_eq!(v, Param::Int(42)); | ||
} | ||
|
||
#[given(regex = "^regex: quoted: '([^']*)'$")] | ||
#[given(expr = "expr: quoted: {param}")] | ||
fn assert_quoted(_: &mut W, v: Param) { | ||
assert_eq!(v, Param::Quoted("inner".to_owned())); | ||
} | ||
|
||
#[derive(Clone, Copy, Debug, Default, World)] | ||
struct W; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let writer = W::cucumber() | ||
.run("tests/features/from_str_and_parameter") | ||
.await; | ||
|
||
assert_eq!(writer.passed_steps(), 4); | ||
assert_eq!(writer.skipped_steps(), 0); | ||
assert_eq!(writer.failed_steps(), 0); | ||
assert_eq!(writer.retried_steps(), 0); | ||
assert_eq!(writer.parsing_errors(), 0); | ||
assert_eq!(writer.hook_errors(), 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use cucumber::{given, then, when, StatsWriter as _, World}; | ||
|
||
#[given("ok")] | ||
#[when("ok")] | ||
#[then("ok")] | ||
fn ok(_: &mut W) -> Result<(), &'static str> { | ||
Ok(()) | ||
} | ||
|
||
#[given("error")] | ||
#[when("error")] | ||
#[then("error")] | ||
fn error(_: &mut W) -> Result<(), &'static str> { | ||
Err("error") | ||
} | ||
|
||
#[derive(Clone, Copy, Debug, Default, World)] | ||
struct W; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let writer = W::cucumber().run("tests/features/result").await; | ||
|
||
assert_eq!(writer.passed_steps(), 3); | ||
assert_eq!(writer.skipped_steps(), 0); | ||
assert_eq!(writer.failed_steps(), 3); | ||
assert_eq!(writer.retried_steps(), 0); | ||
assert_eq!(writer.parsing_errors(), 0); | ||
assert_eq!(writer.hook_errors(), 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use std::sync::atomic::{AtomicUsize, Ordering}; | ||
|
||
use cucumber::{given, StatsWriter as _, World}; | ||
|
||
#[derive(Clone, Copy, Debug, Default, World)] | ||
struct W; | ||
|
||
#[given(regex = "attempt (\\d+)")] | ||
async fn assert(_: &mut W) { | ||
static TIMES_CALLED: AtomicUsize = AtomicUsize::new(0); | ||
|
||
match TIMES_CALLED.fetch_add(1, Ordering::SeqCst) { | ||
n @ 1..=5 if n % 2 != 0 => panic!("flake"), | ||
0..=5 => {} | ||
_ => panic!("too much!"), | ||
} | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let writer = W::cucumber() | ||
.max_concurrent_scenarios(1) | ||
.retries(3) | ||
.fail_fast() | ||
.run("tests/features/retry_fail_fast") | ||
.await; | ||
|
||
assert_eq!(writer.passed_steps(), 3); | ||
assert_eq!(writer.skipped_steps(), 0); | ||
assert_eq!(writer.failed_steps(), 1); | ||
assert_eq!(writer.retried_steps(), 5); | ||
assert_eq!(writer.parsing_errors(), 0); | ||
assert_eq!(writer.hook_errors(), 0); | ||
} |