Skip to content
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

Fix fail_on_skipped for Background steps #199

Merged
merged 4 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ All user visible changes to `cucumber` crate will be documented in this file. Th



## [0.11.2] · 2022-01-??
[0.11.2]: /../../tree/v0.11.2

[Diff](/../../compare/v0.11.1...v0.11.2) | [Milestone](/../../milestone/7)

### Fixed

- Skipped `Background` steps not failing in `writer::FailOnSkipped`. ([#199], [#198])

[#198]: /../../issues/198
[#199]: /../../pull/199




## [0.11.1] · 2022-01-07
[0.11.1]: /../../tree/v0.11.1

Expand Down
12 changes: 8 additions & 4 deletions src/cucumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ where
Wr: Writer<W> + for<'val> writer::Arbitrary<'val, W, String>,
Cli: clap::Args,
{
/// Consider [`Skipped`] steps as [`Failed`] if their [`Scenario`] isn't
/// marked with `@allow.skipped` tag.
/// Consider [`Skipped`] [`Background`] or regular [`Step`]s as [`Failed`]
/// if their [`Scenario`] isn't marked with `@allow.skipped` tag.
///
/// It's useful option for ensuring that all the steps were covered.
///
Expand Down Expand Up @@ -502,9 +502,11 @@ where
/// Then the dog is not hungry
/// ```
///
/// [`Background`]: gherkin::Background
/// [`Failed`]: crate::event::Step::Failed
/// [`Scenario`]: gherkin::Scenario
/// [`Skipped`]: crate::event::Step::Skipped
/// [`Step`]: gherkin::Step
#[must_use]
pub fn fail_on_skipped(
self,
Expand All @@ -519,8 +521,8 @@ where
}
}

/// Consider [`Skipped`] steps as [`Failed`] if the given `filter` predicate
/// returns `true`.
/// Consider [`Skipped`] [`Background`] or regular [`Step`]s as [`Failed`]
/// if the given `filter` predicate returns `true`.
///
/// # Example
///
Expand Down Expand Up @@ -594,9 +596,11 @@ where
/// Then the dog is not hungry
/// ```
///
/// [`Background`]: gherkin::Background
/// [`Failed`]: crate::event::Step::Failed
/// [`Scenario`]: gherkin::Scenario
/// [`Skipped`]: crate::event::Step::Skipped
/// [`Step`]: gherkin::Step
#[must_use]
pub fn fail_on_skipped_with<Filter>(
self,
Expand Down
35 changes: 29 additions & 6 deletions src/writer/fail_on_skipped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,29 +70,52 @@ where
Cucumber, Feature, Rule, Scenario, Step, StepError::Panic,
};

let map_failed = |f: Arc<_>, r: Option<Arc<_>>, sc: Arc<_>, st: _| {
let ev = if (self.should_fail)(&f, r.as_deref(), &sc) {
let map_failed = |f: &Arc<_>, r: &Option<_>, sc: &Arc<_>| {
if (self.should_fail)(f, r.as_deref(), sc) {
Step::Failed(None, None, Panic(Arc::new("not allowed to skip")))
} else {
Step::Skipped
};

}
};
let map_failed_bg = |f: Arc<_>, r: Option<_>, sc: Arc<_>, st: _| {
let ev = map_failed(&f, &r, &sc);
Cucumber::scenario(f, r, sc, Scenario::Background(st, ev))
};
let map_failed_step = |f: Arc<_>, r: Option<_>, sc: Arc<_>, st: _| {
let ev = map_failed(&f, &r, &sc);
Cucumber::scenario(f, r, sc, Scenario::Step(st, ev))
};

let event = event.map(|outer| {
outer.map(|ev| match ev {
Cucumber::Feature(
f,
Feature::Rule(
r,
Rule::Scenario(
sc,
Scenario::Background(st, Step::Skipped),
),
),
) => map_failed_bg(f, Some(r), sc, st),
ilslv marked this conversation as resolved.
Show resolved Hide resolved
Cucumber::Feature(
f,
Feature::Scenario(
sc,
Scenario::Background(st, Step::Skipped),
),
) => map_failed_bg(f, None, sc, st),
Cucumber::Feature(
f,
Feature::Rule(
r,
Rule::Scenario(sc, Scenario::Step(st, Step::Skipped)),
),
) => map_failed(f, Some(r), sc, st),
) => map_failed_step(f, Some(r), sc, st),
Cucumber::Feature(
f,
Feature::Scenario(sc, Scenario::Step(st, Step::Skipped)),
) => map_failed(f, None, sc, st),
) => map_failed_step(f, None, sc, st),
Cucumber::Started
| Cucumber::Feature(..)
| Cucumber::Finished => ev,
Expand Down