1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
# frozen_string_literal: true
require "parallel_tests/test/runner"
module ParallelTests
module RSpec
class Runner < ParallelTests::Test::Runner
DEV_NULL = (WINDOWS ? "NUL" : "/dev/null")
class << self
def run_tests(test_files, process_number, num_processes, options)
cmd = [*executable, *options[:test_options], *color, *spec_opts, *test_files]
execute_command(cmd, process_number, num_processes, options)
end
def determine_executable
if File.exist?("bin/rspec")
ParallelTests.with_ruby_binary("bin/rspec")
elsif ParallelTests.bundler_enabled?
["bundle", "exec", "rspec"]
else
["rspec"]
end
end
def runtime_log
"tmp/parallel_runtime_rspec.log"
end
def default_test_folder
"spec"
end
def test_file_name
"spec"
end
def test_suffix
/_spec\.rb$/
end
def line_is_result?(line)
line =~ /\d+ examples?, \d+ failures?/
end
# remove old seed and add new seed
# --seed 1234
# --order rand
# --order rand:1234
# --order random:1234
def command_with_seed(cmd, seed)
clean = remove_command_arguments(cmd, '--seed', '--order')
[*clean, '--seed', seed]
end
# Summarize results from threads and colorize results based on failure and pending counts.
#
def summarize_results(results)
text = super
return text unless $stdout.tty?
sums = sum_up_results(results)
color =
if sums['failure'] > 0
31 # red
elsif sums['pending'] > 0
33 # yellow
else
32 # green
end
"\e[#{color}m#{text}\e[0m"
end
private
def color
['--color', '--tty'] if $stdout.tty?
end
def spec_opts
options_file = ['.rspec_parallel', 'spec/parallel_spec.opts', 'spec/spec.opts'].detect { |f| File.file?(f) }
["-O", options_file] if options_file
end
end
end
end
end
|