From e96c502e66ceb23fa6c410149d3735a8605184fb Mon Sep 17 00:00:00 2001 From: Rudko Date: Fri, 16 Apr 2021 23:52:08 +0300 Subject: [PATCH] add scenario for skip before flaky step --- features/docs/cli/retry_failing_tests.feature | 10 +++++ .../step_definitions/scenarios_and_steps.rb | 38 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/features/docs/cli/retry_failing_tests.feature b/features/docs/cli/retry_failing_tests.feature index ef6ef2b0ae..1d9c07188c 100644 --- a/features/docs/cli/retry_failing_tests.feature +++ b/features/docs/cli/retry_failing_tests.feature @@ -95,3 +95,13 @@ Feature: Retry failing tests 3 scenarios (2 flaky, 1 passed) """ + + Scenario: Flaky scenario gives zero exit code in no-strict-flaky mode if flaky step fails, passes and skips scenario + And a scenario "Flaky-skip" that fails three times, passes and then skips scenario + When I run `cucumber --retry 3 --no-strict-flaky --format summary` + Then it should pass with: + """ + + 4 scenarios (2 flaky, 1 skipped, 1 passed) + """ + diff --git a/features/lib/step_definitions/scenarios_and_steps.rb b/features/lib/step_definitions/scenarios_and_steps.rb index f81cc610db..3c07f65966 100644 --- a/features/lib/step_definitions/scenarios_and_steps.rb +++ b/features/lib/step_definitions/scenarios_and_steps.rb @@ -109,3 +109,41 @@ def snake_case(name) Given('a step definition that looks like this:') do |content| write_file("features/step_definitions/steps#{SecureRandom.uuid}.rb", content) end + +Given('a scenario {string} that fails three times, passes and then skips scenario') do |full_name| + name = snake_case(full_name) + + create_feature("#{full_name} feature") do + create_scenario(full_name) do + """ + Given it three times, then passes + And it skips scenario + """ + end + end + + write_file( + "features/step_definitions/#{name}_steps.rb", + step_definition('/^it skips scenario/', 'skip_this_scenario') + ) + + write_file( + "features/step_definitions/#{name}_steps.rb", + [ + step_definition('/^it skips scenario/', 'skip_this_scenario'), + step_definition( + '/^it three times, then passes/', + [ + "$#{name} ||= 0", + "$#{name} += 1", + "expect($#{name}).to be > 3" + ] + ) + ].join("\n") + ) + + write_file( + "features/support/#{name}_init.rb", + " $#{name} = 0" + ) +end