Class: DTR::RubyRunner

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

Constant Summary collapse

SUMMARY_REGEX =
/^\s*(\d+) tests, (\d+) assertions, (\d+) failures, (\d+) errors$/

Instance Method Summary collapse

Instance Method Details

#parse(stdout) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/dtr/base.rb', line 42

def parse(stdout)
  summary = stdout.strip.split("\n").reverse.find do |line|
    SUMMARY_REGEX =~ line.strip
  end
  if SUMMARY_REGEX =~ summary
    [$1, $2, $3, $4].collect{|str| str.to_i}
  else
    logger.info {"\tStdout has no tests summary line: #{stdout}"}
    [0, 0, 0, 0]
  end
end

#run(server, client, test_files, signature) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/dtr/base.rb', line 16

def run(server, client, test_files, signature)
  test_files.each do |test_file|
    logger.info { "\tRun #{test_file}..." }
    unless File.exist?(test_file.untaint)
      logger.info {"\tSkip test file not exists: #{test_file}"}
      next
    end
    
    server_reports = server.reports
    break unless server_reports # if can't get reports, server maybe shutdown
    
    if server_reports[test_file]
      logger.info {"\tSkip test file has report on server: #{test_file}"}
      next
    end
    result = client.execute("ruby #{test_file}")
    tests, assertions, failures, errors = parse(result[:stdout])
    report = TestReport.new(test_file, result, tests, assertions, failures, errors)
    
    logger.info { report.to_yaml } unless report.succeeded?
    
    break unless server.update signature, report
  end
end