Class: TestParser::RSpec

Inherits:
Base
  • Object
show all
Defined in:
lib/test-parser/parsers/rspec.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/test-parser/parsers/rspec.rb', line 3

def self.parse test_results
  test_info = Hash.new(0)
  test_info[:failures] = []

  #count them
  test_results.scan(/(\d+) (specification|example)s?, (\d+) failures?/) do |(examples,_,failures)|
    test_info[:failure_count] += failures.to_i
    test_info[:success_count] += examples.to_i - failures.to_i
    test_info[:test_count] += examples.to_i
  end

  #look for errors
  #  ../../test-parser//pkg/test-parser-0.5.0/setup.rb:440: undefined method `set' for class `ConfigTable::ExecItem' (NameError)
  #/opt/[.......]/rake.rb:2028:in `const_missing': uninitialized constant TestRunner (NameError)
  error_regex1 = /\s*(.*?)\:(\d+)\:(in `(.*?)':)? (.*?) \((.*?)\)/
  test_results.scan(error_regex1) do |(file,line,_,method,message,type)|
    error_info = {:file => file,
                  :line => line.to_i,
                  :message => message,
                  :error_type => type,}
    error_info[:method] = method if method
    test_info[:failures] << error_info
  end

  #1)
  #NameError in 'the PyUnitParser should be able to count successes and failures in some examples'
  #undefined local variable or method `results' for PyUnitParser:Module
  #./spec/../lib/test-parser/parsers/pyunit.rb:8:in `parse'
  error_regex2 = /\s+(.*?) in '(.*?)'\s+(.*?)\s+(.*?):(\d+):(in `(.*?)')?/
  test_results.scan(error_regex2) do |(type,test,message,file,line,_,method)|
    error_info = {:error_type => type,
                  :test => test,
                  :message => message,
                  :file => file,
                  :line => line.to_i,
                  }
    error_info[:method] = method if method
    test_info[:failures] << error_info
  end

  #look for failures
  #1)
  #'RSpecParser should agree with the listed examples' FAILED
  #expected 1, got 2 (using ==)
  #./spec/test_rspec_parser_spec.rb:15:
  #
  failure_regex = /\d+\)\s+'(.*?)' FAILED\s+(.*?)\n\s*(.*?):(\d+):/
  test_results.scan(failure_regex) do |(test,message,file,line)|
    test_info[:failures] << {:test => test,
                             :message => message,
                             :file => file,
                             :line => line.to_i,}
  end

  test_info.default = nil
  test_info
end