Class: TestParser::RubyUnit

Inherits:
Base
  • Object
show all
Defined in:
lib/test-parser/parsers/rubyunit.rb

Class Method Summary collapse

Class Method Details

.parse(test_results) ⇒ Object



3
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
33
34
35
36
37
38
39
40
# File 'lib/test-parser/parsers/rubyunit.rb', line 3

def self.parse test_results
  test_info = Hash.new(0)
  test_info[:failures] = []
  
  #1 tests, 1 assertions, 0 failures, 0 errors
  test_results.scan(/(\d+) tests?, \d+ assertions?, (\d+) failures?, (\d+) errors/).each do |(tests,failures,errors)|
    test_info[:failure_count] += failures.to_i + errors.to_i
    test_info[:test_count] += tests.to_i
  end
  
  #  1) Failure:
  #test_truth(TestGtest) [test/test_gtest.rb:9]:
  #<false> is not true.
  test_results.scan(/\s+\d+\) Failure:\n(.*?) \[(.*?):(\d+)\]:\n(.*?)\n/).each do |(test,file,line,message)|
    test_info[:failures] << {:test => test,
                             :file => file,
                             :line => line.to_i,
                             :message => message}
  end
  
  #  1) Error:
  #test_truth(TestGtest):
  #RuntimeError: What
  #    test/test_gtest.rb:9:in `test_truth'
  test_results.scan(/\s+\d+\) Error:\n(.+?):\n(.+?): (.+?)\n\s*(.+?):(\d+):in `(.+?)'/).each do |(test,error_type,message,file,line,method)|
    test_info[:failures] << {:test => test,
                             :error_type => error_type,
                             :message => message,
                             :file => file,
                             :line => line.to_i,
                             :method => method}
  end
  
  
  test_info[:success_count] = test_info[:test_count] - test_info[:failure_count]
  test_info.default = nil
  test_info
end