Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix randomization seed #1329

Merged
merged 3 commits into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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
2 changes: 1 addition & 1 deletion lib/cucumber/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def randomize?
end

def seed
Integer(@options[:seed] || rand(0xFFFF))
@options[:seed]
end

def dry_run?
Expand Down