From 7a25d81e6a23447dfaed15542b77956b755099c4 Mon Sep 17 00:00:00 2001 From: Dana Scheider Date: Mon, 19 Oct 2015 11:29:09 -0700 Subject: [PATCH] Add consistently failing scenario to test cases Define steps for the retry feature --- features/docs/cli/retry_failing_tests.feature | 9 +-- .../lib/step_definitions/cucumber_steps.rb | 64 +++++++++++++++++++ 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/features/docs/cli/retry_failing_tests.feature b/features/docs/cli/retry_failing_tests.feature index 44fcdaa280..1df3a1ece4 100644 --- a/features/docs/cli/retry_failing_tests.feature +++ b/features/docs/cli/retry_failing_tests.feature @@ -15,17 +15,18 @@ Feature: Retry failing tests Given a scenario "Flakey" that fails once, then passes And a scenario "Shakey" that fails twice, then passes And a scenario "Solid" that passes + And a scenario "No Dice" that fails Scenario: - When I run `cucumber --retry 1` + When I run `cucumber -q --retry 1` Then it should fail with: """ - 3 scenarios (2 passed, 1 failed) + 4 scenarios (2 passed, 2 failed) """ Scenario: - When I run `cucumber --retry 2` + When I run `cucumber -q --retry 2` Then it should pass with: """ - 3 scenarios (3 passed) + 4 scenarios (3 passed, 1 failed) """ \ No newline at end of file diff --git a/features/lib/step_definitions/cucumber_steps.rb b/features/lib/step_definitions/cucumber_steps.rb index 3a70db6450..9eaeea66e4 100644 --- a/features/lib/step_definitions/cucumber_steps.rb +++ b/features/lib/step_definitions/cucumber_steps.rb @@ -32,6 +32,70 @@ create_step_definition { string } end +Given /^a scenario "([^\"]*)" that fails once, then passes$/ do |name| + write_file "features/#{name}.feature", + <<-FEATURE + Feature: #{name} + Scenario: #{name} + Given it fails once, then passes + FEATURE + + write_file "features/step_defnitions/#{name}_steps.rb", + <<-STEPS + Given(/^it fails once, then passes$/) do + $#{name.downcase} ||= 0 + $#{name.downcase} += 1 + expect($#{name.downcase}).to eql 2 + end + STEPS +end + +Given /^a scenario "([^\"]*)" that fails twice, then passes$/ do |name| + write_file "features/#{name}.feature", + <<-FEATURE + Feature: #{name} + Scenario: #{name} + Given it fails twice, then passes + FEATURE + + write_file "features/step_definitions/#{name}_steps.rb", + <<-STEPS + Given(/^it fails twice, then passes$/) do + $#{name.downcase} ||= 0 + $#{name.downcase} += 1 + expect($#{name.downcase}).to eql 3 + end + STEPS +end + +Given /^a scenario "([^\"]*)" that passes$/ do |name| + write_file "features/#{name}.feature", + <<-FEATURE + Feature: #{name} + Scenario: #{name} + Given it passes + FEATURE + + write_file "features/step_definitions/#{name}_steps.rb", + <<-STEPS + Given(/^it passes$/) { expect(true).to be true } + STEPS +end + +Given /^a scenario "([^\"]*)" that fails$/ do |name| + write_file "features/#{name}.feature", + <<-FEATURE + Feature: #{name} + Scenario: #{name} + Given it fails + FEATURE + + write_file "features/step_definitions/#{name}_steps.rb", + <<-STEPS + Given(/^it fails$/) { expect(false).to be true } + STEPS +end + When /^I run the feature with the (\w+) formatter$/ do |formatter| expect(features.length).to eq 1 run_feature features.first, formatter