Replace Kernel.srand with Random.new #837

Merged
merged 6 commits into from Mar 20, 2013
@@ -871,7 +871,9 @@ def randomize?
# @private
RANDOM_ORDERING = lambda do |list|
Kernel.srand RSpec.configuration.seed
- list.sort_by { Kernel.rand(list.size) }
+ ordering = list.sort_by { Kernel.rand(list.size) }
+ Kernel.srand # reset random generation
+ ordering
end
# Sets a strategy by which to order examples.
@@ -415,4 +415,19 @@ def run_and_capture_reported_message(group)
expect(example.metadata[:execution_result][:run_time]).to be < 0.2
end
end
+
+ it 'does not interfere with per-example randomness when running examples in a random order' do
+ values = []
+
+ RSpec.configuration.order = :random
+
+ RSpec::Core::ExampleGroup.describe do
+ # The bug was only triggered when the examples
+ # were in nested contexts; see https://github.com/rspec/rspec-core/pull/837
+ context { example { values << rand } }
+ context { example { values << rand } }
+ end.run
+
+ expect(values.uniq).to have(2).values
+ end
end