Created
February 25, 2019 01:56
-
-
Save patorash/ae97ac4002a790cf7b85212a0ebbc95d to your computer and use it in GitHub Desktop.
parallel_testsを使ってテストケース単位でテストを分割して実行する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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