Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@patorash
Created February 25, 2019 01:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patorash/ae97ac4002a790cf7b85212a0ebbc95d to your computer and use it in GitHub Desktop.
Save patorash/ae97ac4002a790cf7b85212a0ebbc95d to your computer and use it in GitHub Desktop.
parallel_testsを使ってテストケース単位でテストを分割して実行する
#!/usr/bin/env ruby
require 'optparse'
require 'json'
options = {
number: nil
}
OptionParser.new do |opts|
opts.on('-n', '--number VALUE', Integer, 'How many processes to use, default: available CPUs') { |v| options[:number] = v }
opts.on('-h', '--help', 'Prints this help') do
puts opts
exit
end
end.parse!
return if ARGV.size.zero?
output_file = if ARGV.size == 1
"tmp/#{File.dirname(ARGV[0])}/#{File.basename(ARGV[0], '.rb')}.json"
else
"tmp/spec/test-results.json"
end
system("bin/rspec --dry-run --format json --out #{output_file} #{ARGV.join(' ')}")
json = open(output_file) { |io| JSON.load(io) }
test_cases = json['examples'].map { |example| example['id'] }
system("bin/parallel_rspec #{options[:number].nil? ? '' : "-n #{options[:number]} "}--quiet --group-by found -- #{test_cases.join(' ')}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment