Skip to content

Commit

Permalink
Merge pull request #1329 from cucumber/fix_randomization_seed
Browse files Browse the repository at this point in the history
Fix randomization seed
  • Loading branch information
deivid-rodriguez authored Dec 10, 2018
2 parents 79428be + 0a0266b commit 2f5d7b8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
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

0 comments on commit 2f5d7b8

Please sign in to comment.