diff --git a/README.md b/README.md
index 0d22dc4..f5a285a 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@

-
+
@@ -96,6 +96,7 @@ Options:
--runtime-log FILE Location of previously recorded test runtimes
-v, --verbose More output
--fail-fast=[N]
+ --seed SEED Seed for rspec
```
## Development
diff --git a/lib/turbo_tests/cli.rb b/lib/turbo_tests/cli.rb
index 52beab2..ed80ba7 100644
--- a/lib/turbo_tests/cli.rb
+++ b/lib/turbo_tests/cli.rb
@@ -16,6 +16,7 @@ def run
runtime_log = nil
verbose = false
fail_fast = nil
+ seed = nil
OptionParser.new { |opts|
opts.banner = <<~BANNER
@@ -76,6 +77,10 @@ def run
end
fail_fast = n.nil? || n < 1 ? 1 : n
end
+
+ opts.on("--seed SEED", "Seed for rspec") do |s|
+ seed = s
+ end
}.parse!(@argv)
requires.each { |f| require(f) }
@@ -101,6 +106,7 @@ def run
verbose: verbose,
fail_fast: fail_fast,
count: count,
+ seed: seed
)
if success
diff --git a/lib/turbo_tests/reporter.rb b/lib/turbo_tests/reporter.rb
index 033ffed..4996dca 100644
--- a/lib/turbo_tests/reporter.rb
+++ b/lib/turbo_tests/reporter.rb
@@ -114,6 +114,11 @@ def finish
RSpec::Core::Notifications::NullNotification)
end
+ def seed_notification(seed, seed_used)
+ puts RSpec::Core::Notifications::SeedNotification.new(seed, seed_used).fully_formatted
+ puts
+ end
+
protected
def delegate_to_formatters(method, *args)
diff --git a/lib/turbo_tests/runner.rb b/lib/turbo_tests/runner.rb
index 31fd36e..e35fdbd 100644
--- a/lib/turbo_tests/runner.rb
+++ b/lib/turbo_tests/runner.rb
@@ -20,6 +20,8 @@ def self.run(opts = {})
verbose = opts.fetch(:verbose, false)
fail_fast = opts.fetch(:fail_fast, nil)
count = opts.fetch(:count, nil)
+ seed = opts.fetch(:seed, rand(0xFFFF).to_s)
+ seed_used = !opts[:seed].nil?
if verbose
STDERR.puts "VERBOSE"
@@ -34,7 +36,9 @@ def self.run(opts = {})
runtime_log: runtime_log,
verbose: verbose,
fail_fast: fail_fast,
- count: count
+ count: count,
+ seed: seed,
+ seed_used: seed_used
).run
end
@@ -49,6 +53,8 @@ def initialize(opts)
@load_time = 0
@load_count = 0
@failure_count = 0
+ @seed = opts[:seed]
+ @seed_used = opts[:seed_used]
@messages = Thread::Queue.new
@threads = []
@@ -86,6 +92,8 @@ def run
report_number_of_tests(tests_in_groups)
+ @reporter.seed_notification(@seed, @seed_used)
+
wait_threads = tests_in_groups.map.with_index do |tests, process_id|
start_regular_subprocess(tests, process_id + 1, **subprocess_opts)
end
@@ -94,6 +102,8 @@ def run
@reporter.finish
+ @reporter.seed_notification(@seed, @seed_used)
+
@threads.each(&:join)
@reporter.failed_examples.empty? && wait_threads.map(&:value).all?(&:success?)
@@ -150,7 +160,7 @@ def start_subprocess(env, extra_args, tests, process_id, record_runtime:)
command = [
ENV["BUNDLE_BIN_PATH"], "exec", "rspec",
*extra_args,
- "--seed", rand(0xFFFF).to_s,
+ "--seed", @seed,
"--format", "TurboTests::JsonRowsFormatter",
"--out", tmp_filename,
*record_runtime_options,
diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb
index b25c2a6..2b2836a 100644
--- a/spec/cli_spec.rb
+++ b/spec/cli_spec.rb
@@ -1,5 +1,5 @@
RSpec.describe TurboTests::CLI do
- subject(:output) { `bundle exec turbo_tests -f d #{fixture}`.strip }
+ subject(:output) { `bundle exec turbo_tests -f d #{fixture} --seed 1234`.strip }
before { output }
@@ -8,6 +8,9 @@
%(
1 processes for 1 specs, ~ 1 specs per process
+Randomized with seed 1234
+
+
An error occurred while loading #{fixture}.
\e[31mFailure/Error: \e[0m\e[1;34m1\e[0m / \e[1;34m0\e[0m\e[0m
\e[31m\e[0m
@@ -18,6 +21,11 @@
\e[36m# #{fixture}:1:in `'\e[0m
).strip
}
+ let(:expected_end_of_output) do
+ "0 examples, 0 failures\n"\
+ "\n\n"\
+ "Randomized with seed 1234"
+ end
let(:fixture) { "./fixtures/rspec/errors_outside_of_examples_spec.rb" }
@@ -25,7 +33,7 @@
expect($?.exitstatus).to eql(1)
expect(output).to start_with(expected_start_of_output)
- expect(output).to end_with("0 examples, 0 failures")
+ expect(output).to end_with(expected_end_of_output)
end
end
@@ -66,7 +74,7 @@
expect(output).to include(part)
end
- expect(output).to end_with("3 examples, 0 failures, 3 pending")
+ expect(output).to end_with("3 examples, 0 failures, 3 pending\n\n\nRandomized with seed 1234")
end
end