Class: MobileMetrics::JunitParser
- Inherits:
-
Object
- Object
- MobileMetrics::JunitParser
- Defined in:
- lib/mobile_metrics/junit.rb
Overview
Instance Attribute Summary collapse
-
#errors ⇒ Array<Ox::Element>
An array of XML elements that represent passed tests.
-
#failures ⇒ Array<Ox::Element>
An array of XML elements that represent failed tests.
-
#headers ⇒ Array<Symbol>
An array of symbols that become the columns of your tests, if ‘nil`, the default, it will be all of the attributes.
-
#passes ⇒ Array<Ox::Element>
An array of XML elements that represent passed tests.
-
#show_skipped_tests ⇒ Bool
An attribute to make the plugin show a warning on skipped tests.
-
#skipped ⇒ Array<Ox::Element>
An array of XML elements that represent skipped tests.
-
#tests ⇒ Array<Ox::Element>
All the tests for introspection.
Instance Method Summary collapse
-
#parse(file) ⇒ void
Parses an XML file, which fills all the attributes, will ‘raise` for errors.
Instance Attribute Details
#errors ⇒ Array<Ox::Element>
An array of XML elements that represent passed tests.
23 24 25 |
# File 'lib/mobile_metrics/junit.rb', line 23 def errors @errors end |
#failures ⇒ Array<Ox::Element>
An array of XML elements that represent failed tests.
18 19 20 |
# File 'lib/mobile_metrics/junit.rb', line 18 def failures @failures end |
#headers ⇒ Array<Symbol>
An array of symbols that become the columns of your tests, if ‘nil`, the default, it will be all of the attributes.
39 40 41 |
# File 'lib/mobile_metrics/junit.rb', line 39 def headers @headers end |
#passes ⇒ Array<Ox::Element>
An array of XML elements that represent passed tests.
13 14 15 |
# File 'lib/mobile_metrics/junit.rb', line 13 def passes @passes end |
#show_skipped_tests ⇒ Bool
An attribute to make the plugin show a warning on skipped tests.
33 34 35 |
# File 'lib/mobile_metrics/junit.rb', line 33 def show_skipped_tests @show_skipped_tests end |
#skipped ⇒ Array<Ox::Element>
An array of XML elements that represent skipped tests.
28 29 30 |
# File 'lib/mobile_metrics/junit.rb', line 28 def skipped @skipped end |
#tests ⇒ Array<Ox::Element>
All the tests for introspection
8 9 10 |
# File 'lib/mobile_metrics/junit.rb', line 8 def tests @tests end |
Instance Method Details
#parse(file) ⇒ void
This method returns an undefined value.
Parses an XML file, which fills all the attributes, will ‘raise` for errors
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/mobile_metrics/junit.rb', line 44 def parse(file) require 'ox' raise "No JUnit file was found at #{file}" unless File.exist? file xml_string = File.read(file) @doc = Ox.parse(xml_string) suite_root = @doc.nodes.first.value == 'testsuites' ? @doc.nodes.first : @doc @tests = suite_root.nodes.map(&:nodes).flatten.select { |node| node.kind_of?(Ox::Element) && node.value == 'testcase' } failed_suites = suite_root.nodes.select { |suite| suite[:failures].to_i > 0 || suite[:errors].to_i > 0 } failed_tests = failed_suites.map(&:nodes).flatten.select { |node| node.kind_of?(Ox::Element) && node.value == 'testcase' } @failures = failed_tests.select do |test| test.nodes.count > 0 end.select do |test| node = test.nodes.first node.kind_of?(Ox::Element) && node.value == 'failure' end @errors = failed_tests.select do |test| test.nodes.count > 0 end.select do |test| node = test.nodes.first node.kind_of?(Ox::Element) && node.value == 'error' end @skipped = tests.select do |test| test.nodes.count > 0 end.select do |test| node = test.nodes.first node.kind_of?(Ox::Element) && node.value == 'skipped' end @passes = tests - @failures - @errors - @skipped end |