Skip to content

Commit

Permalink
Add consistently failing scenario to test cases
Browse files Browse the repository at this point in the history
Define steps for the retry feature
  • Loading branch information
danascheider committed Oct 19, 2015
1 parent 22855a7 commit 7a25d81
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 4 deletions.
9 changes: 5 additions & 4 deletions features/docs/cli/retry_failing_tests.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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)
"""
64 changes: 64 additions & 0 deletions features/lib/step_definitions/cucumber_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7a25d81

Please sign in to comment.