Class: JunitReader

Inherits:
Object
  • Object
show all
Defined in:
lib/utils/junit_reader.rb

Class Method Summary collapse

Class Method Details

.build_json_from_juniter(file_path) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/utils/junit_reader.rb', line 5

def build_json_from_juniter(file_path)
  answer = {}
  xml = File.read(file_path)
  doc = Nokogiri::XML(xml) do |config|
    config.options = Nokogiri::XML::ParseOptions::NOBLANKS
  end

  root_element = doc.root
  answer["name"] = root_element["name"]
  answer["tests"] = root_element["tests"]
  answer["failures"] = root_element["failures"]

  testsuites = root_element.children.map do |element|
    # Read testsuite
    next if element.name != "testsuite"
    read_test_suite( element )
  end
  testsuites.reject! {|m| m == nil}

  answer["testsuites"] =  testsuites
  answer
end

.read_test_case(element) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/utils/junit_reader.rb', line 44

def read_test_case(element)
  testcase = {}
  testcase["classname"] = element["classname"]
  testcase["name"] = element["name"]
  testcase["time"] = element["time"]
  failure_node = element.children.first
  if failure_node && failure_node.name == "failure"
    testcase["failure"] = {
      message: failure_node["message"],
      __content__: failure_node.text
    }
  end
  testcase
end

.read_test_suite(element) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/utils/junit_reader.rb', line 28

def read_test_suite(element)
  test_suite = {}
  test_suite["name"] = element["name"]
  test_suite["tests"] = element["tests"]
  test_suite["failures"] = element["failures"]
  testcases = element.children.map do |element_testcase|
    # Read testcase
    next if element_testcase.name != "testcase"
    read_test_case(element_testcase)
  end
  testcases.reject! {|m| m == nil}

  test_suite["testcases"]  = testcases
  test_suite
end