Skip to content

Commit ed3b48d

Browse files
rogertorresilslv
andauthored
Fix skipped Background steps not failing in writer::FailOnSkipped (#199, #198)
Co-authored-by: ilslv <[email protected]>
1 parent 935602b commit ed3b48d

File tree

3 files changed

+52
-10
lines changed

3 files changed

+52
-10
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ All user visible changes to `cucumber` crate will be documented in this file. Th
66

77

88

9+
## [0.11.2] · 2022-01-??
10+
[0.11.2]: /../../tree/v0.11.2
11+
12+
[Diff](/../../compare/v0.11.1...v0.11.2) | [Milestone](/../../milestone/7)
13+
14+
### Fixed
15+
16+
- Skipped `Background` steps not failing in `writer::FailOnSkipped`. ([#199], [#198])
17+
18+
[#198]: /../../issues/198
19+
[#199]: /../../pull/199
20+
21+
22+
23+
924
## [0.11.1] · 2022-01-07
1025
[0.11.1]: /../../tree/v0.11.1
1126

src/cucumber.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,8 @@ where
438438
Wr: Writer<W> + for<'val> writer::Arbitrary<'val, W, String>,
439439
Cli: clap::Args,
440440
{
441-
/// Consider [`Skipped`] steps as [`Failed`] if their [`Scenario`] isn't
442-
/// marked with `@allow.skipped` tag.
441+
/// Consider [`Skipped`] [`Background`] or regular [`Step`]s as [`Failed`]
442+
/// if their [`Scenario`] isn't marked with `@allow.skipped` tag.
443443
///
444444
/// It's useful option for ensuring that all the steps were covered.
445445
///
@@ -502,9 +502,11 @@ where
502502
/// Then the dog is not hungry
503503
/// ```
504504
///
505+
/// [`Background`]: gherkin::Background
505506
/// [`Failed`]: crate::event::Step::Failed
506507
/// [`Scenario`]: gherkin::Scenario
507508
/// [`Skipped`]: crate::event::Step::Skipped
509+
/// [`Step`]: gherkin::Step
508510
#[must_use]
509511
pub fn fail_on_skipped(
510512
self,
@@ -519,8 +521,8 @@ where
519521
}
520522
}
521523

522-
/// Consider [`Skipped`] steps as [`Failed`] if the given `filter` predicate
523-
/// returns `true`.
524+
/// Consider [`Skipped`] [`Background`] or regular [`Step`]s as [`Failed`]
525+
/// if the given `filter` predicate returns `true`.
524526
///
525527
/// # Example
526528
///
@@ -594,9 +596,11 @@ where
594596
/// Then the dog is not hungry
595597
/// ```
596598
///
599+
/// [`Background`]: gherkin::Background
597600
/// [`Failed`]: crate::event::Step::Failed
598601
/// [`Scenario`]: gherkin::Scenario
599602
/// [`Skipped`]: crate::event::Step::Skipped
603+
/// [`Step`]: gherkin::Step
600604
#[must_use]
601605
pub fn fail_on_skipped_with<Filter>(
602606
self,

src/writer/fail_on_skipped.rs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,29 +70,52 @@ where
7070
Cucumber, Feature, Rule, Scenario, Step, StepError::Panic,
7171
};
7272

73-
let map_failed = |f: Arc<_>, r: Option<Arc<_>>, sc: Arc<_>, st: _| {
74-
let ev = if (self.should_fail)(&f, r.as_deref(), &sc) {
73+
let map_failed = |f: &Arc<_>, r: &Option<_>, sc: &Arc<_>| {
74+
if (self.should_fail)(f, r.as_deref(), sc) {
7575
Step::Failed(None, None, Panic(Arc::new("not allowed to skip")))
7676
} else {
7777
Step::Skipped
78-
};
79-
78+
}
79+
};
80+
let map_failed_bg = |f: Arc<_>, r: Option<_>, sc: Arc<_>, st: _| {
81+
let ev = map_failed(&f, &r, &sc);
82+
Cucumber::scenario(f, r, sc, Scenario::Background(st, ev))
83+
};
84+
let map_failed_step = |f: Arc<_>, r: Option<_>, sc: Arc<_>, st: _| {
85+
let ev = map_failed(&f, &r, &sc);
8086
Cucumber::scenario(f, r, sc, Scenario::Step(st, ev))
8187
};
8288

8389
let event = event.map(|outer| {
8490
outer.map(|ev| match ev {
91+
Cucumber::Feature(
92+
f,
93+
Feature::Rule(
94+
r,
95+
Rule::Scenario(
96+
sc,
97+
Scenario::Background(st, Step::Skipped),
98+
),
99+
),
100+
) => map_failed_bg(f, Some(r), sc, st),
101+
Cucumber::Feature(
102+
f,
103+
Feature::Scenario(
104+
sc,
105+
Scenario::Background(st, Step::Skipped),
106+
),
107+
) => map_failed_bg(f, None, sc, st),
85108
Cucumber::Feature(
86109
f,
87110
Feature::Rule(
88111
r,
89112
Rule::Scenario(sc, Scenario::Step(st, Step::Skipped)),
90113
),
91-
) => map_failed(f, Some(r), sc, st),
114+
) => map_failed_step(f, Some(r), sc, st),
92115
Cucumber::Feature(
93116
f,
94117
Feature::Scenario(sc, Scenario::Step(st, Step::Skipped)),
95-
) => map_failed(f, None, sc, st),
118+
) => map_failed_step(f, None, sc, st),
96119
Cucumber::Started
97120
| Cucumber::Feature(..)
98121
| Cucumber::Finished => ev,

0 commit comments

Comments
 (0)