Class: Res::Parsers::Junit
- Inherits:
-
Object
- Object
- Res::Parsers::Junit
- Defined in:
- lib/res/parsers/junit.rb
Instance Attribute Summary collapse
-
#io ⇒ Object
Returns the value of attribute io.
Instance Method Summary collapse
- #attach_cases(node) ⇒ Object
- #attach_suite(component) ⇒ Object
-
#initialize(junit_xml) ⇒ Junit
constructor
A new instance of Junit.
Constructor Details
#initialize(junit_xml) ⇒ Junit
Returns a new instance of Junit.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/res/parsers/junit.rb', line 10 def initialize(junit_xml) file = File.open(junit_xml, "rb") begin junit = Ox.parse(file.read) rescue Ox::ParseError => e raise "Invalid xunit XML format. Error: #{e}" end file.close result = Array.new result = attach_suite(junit) ir = ::Res::IR.new( :type => 'Junit', :started => "", :finished => Time.now(), :results => result ) @io = File.open("./junit.res", "w") @io.puts ir.json @io.close end |
Instance Attribute Details
#io ⇒ Object
Returns the value of attribute io.
8 9 10 |
# File 'lib/res/parsers/junit.rb', line 8 def io @io end |
Instance Method Details
#attach_cases(node) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/res/parsers/junit.rb', line 30 def attach_cases(node) testcase = Hash.new testcase["type"] = "JUnit::" + node.value testcase["name"] = node.attributes[:name] testcase["classname"] = node.attributes[:classname] if testcase["classname"] != nil testcase["duration"] = node.attributes[:time] testcase["status"] = "passed" if node.nodes[0] != nil testcase["status"] = "failed" if node.nodes[0].value == "failure" or node.nodes[0].value == "error" testcase["status"] = "notrun" if node.nodes[0].value == "skipped" end testcase end |
#attach_suite(component) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/res/parsers/junit.rb', line 44 def attach_suite(component) suite = Array.new index = 0 component.nodes.each do |node| if node.value == "testcase" suite[index] = Hash.new suite[index] = attach_cases(node) else suite[index] = Hash.new suite[index]["type"] = "JUnit::" + node.value suite[index]["name"] = node.attributes[:name] suite[index]["classname"] = node.attributes[:classname] if suite[index]["classname"] != nil suite[index]["children"] = attach_suite(node) end # if index += 1 end # each suite end |