DEV: Add parallel spec support to autospec

DEV: Add parallel spec support to autospec

Set PARALLEL_SPEC=1 to use this functionality

diff --git a/lib/autospec/simple_runner.rb b/lib/autospec/simple_runner.rb
index 24150c9..f060683 100644
--- a/lib/autospec/simple_runner.rb
+++ b/lib/autospec/simple_runner.rb
@@ -15,7 +15,17 @@ module Autospec
       end
       # we use our custom rspec formatter
       args = ["-r", "#{File.dirname(__FILE__)}/formatter.rb",
-              "-f", "Autospec::Formatter", specs.split].flatten.join(" ")
+        "-f", "Autospec::Formatter"]
+
+      command = begin
+        if ENV["PARALLEL_SPEC"] &&
+              !specs.split.any? { |s| puts s; s =~ /\:/ } # Parallel spec can't run specific groups
+          "parallel_rspec -- #{args.join(" ")} -- #{specs.split.join(" ")}"
+        else
+          "bin/rspec #{args.join(" ")} #{specs.split.join(" ")}"
+        end
+      end
+
       # launch rspec
       Dir.chdir(Rails.root) do
         env = { "RAILS_ENV" => "test" }
@@ -25,7 +35,7 @@ module Autospec
         end
         pid =
           @mutex.synchronize do
-            @pid = Process.spawn(env, "bin/rspec #{args}")
+            @pid = Process.spawn(env, command)
           end
 
         _, status = Process.wait2(pid)

GitHub sha: 25feb287

2 Likes

Does this need a followup all the streams can step on each other?

Also how do we hard reset and start from scratch?

Already done here: DEV: Use parallel-compatible formatter for logging autospec failures

Not sure what you mean here? The log is wiped clean each time the parallel spec process starts.

2 Likes