diff --git a/CHANGELOG.md b/CHANGELOG.md index 7197ca0ddf..bbd37eb5e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,10 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo ### Fixed +* Fix seed printed in cucumber UI to match the seed that was actually used. + ([#1329](https://github.com/cucumber/cucumber-ruby/pull/1329) + [deivid-rodriguez](https://github.com/deivid-rodriguez)) + ### Added ### Improved diff --git a/features/docs/cli/randomize.feature b/features/docs/cli/randomize.feature index 405f89c3e4..dc3ed46987 100644 --- a/features/docs/cli/randomize.feature +++ b/features/docs/cli/randomize.feature @@ -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` diff --git a/features/lib/step_definitions/cucumber_steps.rb b/features/lib/step_definitions/cucumber_steps.rb index 6817a7f4ca..41a3c93efe 100644 --- a/features/lib/step_definitions/cucumber_steps.rb +++ b/features/lib/step_definitions/cucumber_steps.rb @@ -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 diff --git a/lib/cucumber/cli/configuration.rb b/lib/cucumber/cli/configuration.rb index 9126165021..bc4e5a6f51 100644 --- a/lib/cucumber/cli/configuration.rb +++ b/lib/cucumber/cli/configuration.rb @@ -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 diff --git a/lib/cucumber/configuration.rb b/lib/cucumber/configuration.rb index 472cbea536..41365a2337 100644 --- a/lib/cucumber/configuration.rb +++ b/lib/cucumber/configuration.rb @@ -54,7 +54,7 @@ def randomize? end def seed - Integer(@options[:seed] || rand(0xFFFF)) + @options[:seed] end def dry_run?