Class: RSpecFlake::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_flake/rspec_flake.rb

Class Method Summary collapse

Class Method Details

.run_tests(opts = {}) ⇒ Object



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
# File 'lib/rspec_flake/rspec_flake.rb', line 4

def self.run_tests opts={}
  count = opts[:count]
  raise 'count is required and must be a number' unless count && count.match(/\d+/)
  count = count.to_i

  command = opts[:command]
  raise "command is required and must start with rspec. #{command}" unless command && command.start_with?('rspec')

  tmp_path = File.expand_path File.join Dir.pwd, 'tmp'
  FileUtils.rm_rf tmp_path
  FileUtils.mkdir_p tmp_path

  xml_files = []

  count.times do |iteration|
    out_file = File.expand_path File.join(tmp_path, iteration.to_s + '.xml')
    xml_files << out_file
    spawn_command = %Q(#{command} --format JUnit --out "#{out_file}")
    puts "Running: #{spawn_command}"
    Process::waitpid(POSIX::Spawn::spawn(spawn_command))
  end

  merge_path = File.join(tmp_path, '..', 'merged.xml')
  File.open(merge_path, 'w') do |file|
    xml = RSpecFlake.merge_xml input: xml_files
    file.write xml
    puts RSpecFlake.stats_from_merge_xml xml
  end
end