class RSpecFlake::ReportParser

Public Class Methods

new() click to toggle source
# File lib/rspec_flake/parse.rb, line 13
def initialize
  reset
end

Public Instance Methods

cdata_block(string) click to toggle source
# 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) click to toggle source
# 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
reset() click to toggle source
# File lib/rspec_flake/parse.rb, line 17
def reset
  @data              = {}
  @suite_location    = nil
  @testcase_location = nil
  @failure           = nil
end
result() click to toggle source
# File lib/rspec_flake/parse.rb, line 24
def result
  @data
end
start_element(name, attrs = []) click to toggle source
# 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