Class: RSpecFlake::ReportParser

Inherits:
Nokogiri::XML::SAX::Document
  • Object
show all
Defined in:
lib/rspec_flake/parse.rb

Instance Method Summary collapse

Constructor Details

#initializeReportParser

Returns a new instance of ReportParser.



13
14
15
# File 'lib/rspec_flake/parse.rb', line 13

def initialize
  reset
end

Instance Method Details

#cdata_block(string) ⇒ Object



52
53
54
55
56
# File 'lib/rspec_flake/parse.rb', line 52

def cdata_block string
  raise 'cdata not associated with failure' unless @failure
  @failure[:content] = string
  @failure           = nil
end

#end_element(name) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/rspec_flake/parse.rb', line 58

def end_element name
  case name
    when 'testsuite'
      @suite_location = nil
    when 'testcase'
      @testcase_location = nil
  end
end

#resetObject



17
18
19
20
21
22
# File 'lib/rspec_flake/parse.rb', line 17

def reset
  @data              = {}
  @suite_location    = nil
  @testcase_location = nil
  @failure           = nil
end

#resultObject



24
25
26
# File 'lib/rspec_flake/parse.rb', line 24

def result
  @data
end

#start_element(name, attrs = []) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rspec_flake/parse.rb', line 28

def start_element name, attrs = []
  name      = name.to_sym
  attrs     = attrs.to_h
  testsuite = :testsuite
  root      = :testsuites
  location  = attrs['location']

  case name
    when root
      @data[root] ||= { attrs: attrs, testsuite: {} }
    when :testsuite
      @suite_location                         = location
      @data[root][testsuite][@suite_location] ||= { attrs: attrs, testcase: {} }
    when :testcase
      raise 'testcase not part of a suite' unless @suite_location
      @testcase_location                                           = location
      @data[root][testsuite][@suite_location][:testcase][location] ||= { attrs: attrs }
    when :failure
      raise 'failure not part of a testcase' unless @testcase_location
      @data[root][testsuite][@suite_location][:testcase][@testcase_location].merge!({ failure: { attrs: attrs } })
      @failure = @data[root][testsuite][@suite_location][:testcase][@testcase_location][:failure]
  end
end