Class: Scan::TestResultParser

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

Instance Method Summary collapse

Instance Method Details

#parse_result(output) ⇒ Object



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
# File 'scan/lib/scan/test_result_parser.rb', line 5

def parse_result(output)
  unless output
    return {
        tests: 0,
        failures: 0
    }
  end

  # e.g. ...<testsuites tests='2' failures='1'>...
  matched = output.scan(/<testsuites\b(?=[^<>]*\s+tests='(\d+)')(?=[^<>]*\s+failures='(\d+)')[^<>]+>/)

  if matched && matched.length == 1 && matched[0].length == 2
    tests = matched[0][0].to_i
    failures = matched[0][1].to_i

    {
      tests: tests,
      failures: failures
    }
  else
    UI.error("Couldn't parse the number of tests from the output")
    {
      tests: 0,
      failures: 0
    }
  end
end