Skip to content

Commit

Permalink
Fix informed seed when not explicitly passed
Browse files Browse the repository at this point in the history
If you don't explicitly pass a seed, cucumber would inform it has run
test with an incorrect seed, so it would be impossible to actually
reproduce a failing run.
  • Loading branch information
deivid-rodriguez committed Dec 7, 2018
1 parent 79428be commit 67291c3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions features/docs/cli/randomize.feature
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ Feature: Randomize
"""

Scenario: Rerun scenarios randomized
When I run `cucumber --order random --format summary`
And I rerun the previous command with the same seed
Then the output of both commands should be the same

@spawn @todo-windows
Scenario: Run scenarios randomized with some skipped
When I run `cucumber --tags 'not @skipme' --order random:41544 -q`
Expand Down
14 changes: 14 additions & 0 deletions features/lib/step_definitions/cucumber_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@
run_feature features.first, formatter
end

When(/^I rerun the previous command with the same seed$/) do
previous_seed = last_command_started.output.match(/with seed (\d+)/)[1]
second_command = all_commands.last.commandline.gsub(/random/, "random:#{previous_seed}")

step "I run `#{second_command}`"
end

Then(/the output of both commands should be the same/) do
first_output = all_commands.first.output.gsub(/\d+m\d+\.\d+s/, '')
last_output = all_commands.last.output.gsub(/\d+m\d+\.\d+s/, '')

expect(first_output).to eq(last_output)
end

module CucumberHelper
def run_feature(filename = 'features/a_feature.feature', formatter = 'progress')
run_simple "#{Cucumber::BINARY} #{filename} --format #{formatter}", false
Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/cli/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def paths
end

def to_hash
Hash(@options).merge(out_stream: @out_stream, error_stream: @error_stream)
Hash(@options).merge(out_stream: @out_stream, error_stream: @error_stream, seed: seed)
end

private
Expand Down

0 comments on commit 67291c3

Please sign in to comment.