juniter 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/tests.yml +23 -0
- data/.gitignore +9 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +68 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/juniter.gemspec +33 -0
- data/lib/juniter.rb +21 -0
- data/lib/juniter/element.rb +41 -0
- data/lib/juniter/file.rb +40 -0
- data/lib/juniter/has_attributes.rb +70 -0
- data/lib/juniter/has_children.rb +92 -0
- data/lib/juniter/test_case.rb +33 -0
- data/lib/juniter/test_result.rb +51 -0
- data/lib/juniter/test_suite.rb +27 -0
- data/lib/juniter/test_suite_properties.rb +21 -0
- data/lib/juniter/test_suite_property.rb +11 -0
- data/lib/juniter/test_suites.rb +18 -0
- data/lib/juniter/version.rb +3 -0
- metadata +152 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7d9829ead2f6c25be1a34b8dec61c9b83b951ebdf600589a5841e6fff69e5032
|
4
|
+
data.tar.gz: a0b39d17095d93f9d83fe48d594c775e4cc7983dabc9c29e9cc291bf540708f9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ffa0008141543e97144b670847bc597c0828e4eb8d5ae192c3fe20ea07ffe07bb2b44a6f4cd773a98befc50dc3c8c9988184bc9b063c41c456e8aeeb76209010
|
7
|
+
data.tar.gz: 4cd7682af7cd45cd43ca66095d516868720acd65510ea1d7e7e987809bdf5407c2f0a09daaa40b38b9b095e7ca99752367d8b74d90ff9ce08f8b41fb5cdb2c9c
|
@@ -0,0 +1,23 @@
|
|
1
|
+
name: Tests
|
2
|
+
on: [push]
|
3
|
+
|
4
|
+
jobs:
|
5
|
+
ruby:
|
6
|
+
name: Ruby Tests
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
strategy:
|
9
|
+
matrix:
|
10
|
+
ruby: [2.5, 2.6, 2.7]
|
11
|
+
steps:
|
12
|
+
- name: Checkout
|
13
|
+
uses: actions/checkout@v2
|
14
|
+
- name: Ruby Setup
|
15
|
+
uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: ${{ matrix.ruby }}
|
18
|
+
- name: Bundle
|
19
|
+
run: |
|
20
|
+
bundle config path vendor/bundle
|
21
|
+
bundle install --jobs 4 --retry 3
|
22
|
+
- name: Run the tests
|
23
|
+
run: bundle exec rake test
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Matt Kobs
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Juniter
|
2
|
+
![Tests](https://github.com/kobsy/juniter/workflows/Tests/badge.svg)
|
3
|
+
|
4
|
+
A simple Ruby library for parsing and working with JUnit files
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'juniter'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle install
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install juniter
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Load a JUnit XML file into Juniter using one of the following methods:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
Juniter.read(io_stream)
|
28
|
+
# => <Juniter::File>
|
29
|
+
|
30
|
+
Juniter.from_file(file_name)
|
31
|
+
# => <Juniter::File>
|
32
|
+
|
33
|
+
Juniter.parse(xml_string)
|
34
|
+
# => <Juniter::File>
|
35
|
+
```
|
36
|
+
|
37
|
+
From there, you can traverse the JUnit hierarchy via named methods. E.g.,
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
file = Juniter.parse(xml)
|
41
|
+
failures = file.test_suites.test_suites.first.test_cases.select(&:fail?)
|
42
|
+
puts failures.map { |failure| failure.message }.join("\n")
|
43
|
+
```
|
44
|
+
|
45
|
+
Juniter uses [ox](https://github.com/ohler55/ox) under the hood for its XML parsing. You can get at the parsed Ox elements via `juniter_file.parsed_xml`
|
46
|
+
|
47
|
+
Juniter can also reassemble the objects into an XML file:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
juniter_file.to_xml
|
51
|
+
# => "<?xml version="1.0" encoding="UTF-8"><testsuites> ..."
|
52
|
+
```
|
53
|
+
|
54
|
+
## Development
|
55
|
+
|
56
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
57
|
+
|
58
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kobsy/juniter.
|
63
|
+
|
64
|
+
|
65
|
+
## License
|
66
|
+
|
67
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
68
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "juniter"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/juniter.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'lib/juniter/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "juniter"
|
5
|
+
spec.version = Juniter::VERSION
|
6
|
+
spec.authors = ["Matt Kobs"]
|
7
|
+
spec.email = ["matt@kobsy.net"]
|
8
|
+
|
9
|
+
spec.summary = %q{Parse and interact with JUnit XML files as Ruby objects}
|
10
|
+
spec.homepage = "https://github.com/kobsy/juniter"
|
11
|
+
spec.license = "MIT"
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
13
|
+
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
15
|
+
spec.metadata["source_code_uri"] = "https://github.com/kobsy/juniter"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_dependency "ox"
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler"
|
29
|
+
spec.add_development_dependency "rake"
|
30
|
+
spec.add_development_dependency "pry"
|
31
|
+
spec.add_development_dependency "shoulda-context"
|
32
|
+
spec.add_development_dependency "minitest-stub-const"
|
33
|
+
end
|
data/lib/juniter.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "juniter/version"
|
2
|
+
require "juniter/file"
|
3
|
+
|
4
|
+
# Initial implementation based on the XSD found at
|
5
|
+
# https://llg.cubic.org/docs/junit/
|
6
|
+
|
7
|
+
module Juniter
|
8
|
+
class << self
|
9
|
+
def read(*args)
|
10
|
+
Juniter::File.read(*args)
|
11
|
+
end
|
12
|
+
|
13
|
+
def from_file(*args)
|
14
|
+
Juniter::File.from_file(*args)
|
15
|
+
end
|
16
|
+
|
17
|
+
def parse(*args)
|
18
|
+
Juniter::File.parse(*args)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "juniter/has_attributes"
|
2
|
+
require "juniter/has_children"
|
3
|
+
|
4
|
+
module Juniter
|
5
|
+
class Element
|
6
|
+
include HasAttributes
|
7
|
+
include HasChildren
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def tag(*args)
|
11
|
+
@__tag = args.first.to_s unless args.none?
|
12
|
+
@__tag
|
13
|
+
end
|
14
|
+
|
15
|
+
def from_xml(node)
|
16
|
+
new.tap do |element|
|
17
|
+
element.assign_attributes_from_xml(node)
|
18
|
+
element.assign_children_from_xml(node.nodes)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_xml
|
24
|
+
Ox::Element.new(tag).tap do |element|
|
25
|
+
xml_attributes.each do |key, value|
|
26
|
+
element[key.to_s] = value unless value.nil?
|
27
|
+
end
|
28
|
+
children_xml.each do |child|
|
29
|
+
element << child
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
def tag
|
37
|
+
self.class.tag
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
data/lib/juniter/file.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "ox"
|
2
|
+
require "juniter/test_suites"
|
3
|
+
|
4
|
+
module Juniter
|
5
|
+
class File
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def read(io)
|
9
|
+
parse io.read
|
10
|
+
end
|
11
|
+
|
12
|
+
def from_file(filename)
|
13
|
+
::File.open(filename, "r") do |f|
|
14
|
+
read f
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse(xml_string)
|
19
|
+
new(Ox.parse(xml_string))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_reader :test_suites, :parsed_xml
|
24
|
+
|
25
|
+
def initialize(xml)
|
26
|
+
@parsed_xml = xml
|
27
|
+
root = xml.respond_to?(:root) ? xml.root : xml
|
28
|
+
raise ArgumentError, "Invalid JUnit file. Expected <testsuites> or <testsuite> as the root node but got <#{root.value}>" unless %w{testsuites testsuite}.include?(root.value)
|
29
|
+
@test_suites = TestSuites.from_xml(root) if root.value == "testsuites"
|
30
|
+
@test_suites ||= TestSuites.new.tap do |test_suites|
|
31
|
+
test_suites.test_suites = [ TestSuite.from_xml(root) ]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_xml
|
36
|
+
Ox.dump(test_suites.to_xml)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Juniter
|
2
|
+
module HasAttributes
|
3
|
+
|
4
|
+
class UnsetAttributeError < StandardError; end
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.extend(ClassMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
|
12
|
+
def attribute(name, as: nil, required: false, validation: nil, map: nil)
|
13
|
+
attributes << name
|
14
|
+
attribute_aliases[name] = as unless as.nil?
|
15
|
+
attribute_processors[name] = map || ->(value) { value }
|
16
|
+
|
17
|
+
define_method :"#{name}" do
|
18
|
+
instance_variable_get :"@_#{name}" if instance_variable_defined?(:"@_#{name}")
|
19
|
+
end
|
20
|
+
|
21
|
+
define_method :"#{name}=" do |value|
|
22
|
+
send validation, value unless validation.nil?
|
23
|
+
instance_variable_set :"@_#{name}", value
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def attributes
|
28
|
+
@__attributes ||= []
|
29
|
+
end
|
30
|
+
|
31
|
+
def attribute_aliases
|
32
|
+
@__attribute_aliases ||= {}
|
33
|
+
end
|
34
|
+
|
35
|
+
def attribute_processors
|
36
|
+
@__attribute_processors ||= {}
|
37
|
+
end
|
38
|
+
|
39
|
+
def required_attributes
|
40
|
+
@__required_attributes ||= []
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def assign_attributes_from_xml(node)
|
46
|
+
attributes = node.attributes
|
47
|
+
self.class.attributes.each do |name|
|
48
|
+
key = self.class.attribute_aliases.fetch(name, name).to_sym
|
49
|
+
mapped = attributes.key?(key) ? self.class.attribute_processors[name].call(node[key]) : nil
|
50
|
+
public_send "#{name}=", mapped
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def xml_attributes
|
55
|
+
self.class.attributes.each_with_object({}) do |name, hash|
|
56
|
+
key = self.class.attribute_aliases.fetch(name, name)
|
57
|
+
value = public_send(name)
|
58
|
+
raise UnsetAttributeError if self.class.required_attributes.include?(name) && value.nil?
|
59
|
+
hash[key] = public_send(name)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
protected
|
64
|
+
|
65
|
+
def valid_number?(value)
|
66
|
+
raise ArgumentError, "Must be a number" unless value.is_a?(Numeric)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module Juniter
|
2
|
+
module HasChildren
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.extend(ClassMethods)
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def child(name, as: nil, array: false, map: nil)
|
10
|
+
child_types << name
|
11
|
+
child_aliases[name] = as unless as.nil?
|
12
|
+
child_processors[name] = map || ->(node) { node.text }
|
13
|
+
array_children << name if array
|
14
|
+
|
15
|
+
define_method :"#{name}" do
|
16
|
+
instance_variable_set(:"@_#{name}", array ? [] : nil ) unless instance_variable_defined?(:"@_#{name}")
|
17
|
+
instance_variable_get(:"@_#{name}")
|
18
|
+
end
|
19
|
+
|
20
|
+
define_method :"#{name}=" do |value|
|
21
|
+
instance_variable_set :"@_#{name}", value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def text_child(*args)
|
26
|
+
if args.any?
|
27
|
+
@__text_child = args.first
|
28
|
+
child(args.first)
|
29
|
+
end
|
30
|
+
@__text_child
|
31
|
+
end
|
32
|
+
|
33
|
+
def child_types
|
34
|
+
@__child_types ||= []
|
35
|
+
end
|
36
|
+
|
37
|
+
def child_processors
|
38
|
+
@__child_processors ||= {}
|
39
|
+
end
|
40
|
+
|
41
|
+
def child_aliases
|
42
|
+
@__child_aliases ||= {}
|
43
|
+
end
|
44
|
+
|
45
|
+
def array_children
|
46
|
+
@__array_children ||= []
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def assign_children_from_xml(nodes)
|
51
|
+
child_map = self.class.child_types.each_with_object({}) do |name, hash|
|
52
|
+
hash[self.class.child_aliases.fetch(name, name).to_s] = name
|
53
|
+
end
|
54
|
+
|
55
|
+
nodes.each do |node|
|
56
|
+
if node.is_a?(String)
|
57
|
+
text_child = self.class.text_child
|
58
|
+
next unless text_child
|
59
|
+
public_send :"#{text_child}=", [ public_send(:"#{text_child}"), node ].join
|
60
|
+
next
|
61
|
+
end
|
62
|
+
|
63
|
+
name = child_map.fetch(node.value)
|
64
|
+
mapped = self.class.child_processors[name].call(node)
|
65
|
+
if self.class.array_children.include?(name)
|
66
|
+
public_send("#{name}") << mapped
|
67
|
+
else
|
68
|
+
public_send "#{name}=", mapped
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def children_xml
|
74
|
+
self.class.child_types.each_with_object([]) do |name, children|
|
75
|
+
value = public_send(name)
|
76
|
+
next if value.nil?
|
77
|
+
|
78
|
+
element = self.class.child_aliases.fetch(name, name)
|
79
|
+
if self.class.array_children.include?(name)
|
80
|
+
children.concat value.map { |child|
|
81
|
+
child.respond_to?(:to_xml) ? child.to_xml : Ox::Element.new(element).tap { |el| el << child }
|
82
|
+
}
|
83
|
+
elsif self.class.text_child == name
|
84
|
+
children << value
|
85
|
+
else
|
86
|
+
children << (value.respond_to?(:to_xml) ? value.to_xml : Ox::Element.new(element).tap { |el| el << value })
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "juniter/element"
|
2
|
+
require "juniter/test_result"
|
3
|
+
|
4
|
+
module Juniter
|
5
|
+
class TestCase < Element
|
6
|
+
tag "testcase"
|
7
|
+
|
8
|
+
attribute :name, required: true
|
9
|
+
attribute :assertion_count, as: :assertions, map: ->(value) { value.to_i }
|
10
|
+
attribute :duration, as: :time, map: ->(value) { value.to_f }
|
11
|
+
attribute :class_name, as: :classname
|
12
|
+
attribute :status
|
13
|
+
|
14
|
+
child :skip_result, as: :skipped, map: ->(node) { TestResult.from_xml(node) }
|
15
|
+
child :error_result, as: :error, array: true, map: ->(node) { TestResult.from_xml(node) }
|
16
|
+
child :fail_result, as: :failure, array: true, map: ->(node) { TestResult.from_xml(node) }
|
17
|
+
|
18
|
+
child :stdout, as: :"system-out", array: true
|
19
|
+
child :stderr, as: :"system-err", array: true
|
20
|
+
|
21
|
+
def all_results
|
22
|
+
[ skip_result, *error_result, *fail_result ].compact
|
23
|
+
end
|
24
|
+
|
25
|
+
# Convenience method. Assumes that all results are of
|
26
|
+
# the same type, which should mean that querying if the
|
27
|
+
# "result" is pass/fail/skip/error should work without issue.
|
28
|
+
def result
|
29
|
+
all_results.none? ? TestResult.new(:pass) : all_results.first
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "juniter/element"
|
2
|
+
|
3
|
+
module Juniter
|
4
|
+
class TestResult < Element
|
5
|
+
VALID_STATUSES = %i{ pass fail error skip }.freeze
|
6
|
+
|
7
|
+
attribute :type
|
8
|
+
attribute :message
|
9
|
+
text_child :description
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def from_xml(node)
|
13
|
+
status = ELEMENT_TO_STATUS_MAP.fetch(node.value, node.value)
|
14
|
+
new(status).tap do |element|
|
15
|
+
element.assign_attributes_from_xml(node)
|
16
|
+
element.assign_children_from_xml(node.nodes)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(status)
|
22
|
+
self.status = status.to_sym
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :status
|
26
|
+
|
27
|
+
def status=(value)
|
28
|
+
raise ArgumentError, "Unknown status. Must be one of: #{VALID_STATUSES.join(", ")}" unless VALID_STATUSES.include?(value)
|
29
|
+
@status = value
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_xml
|
33
|
+
return nil if pass?
|
34
|
+
super
|
35
|
+
end
|
36
|
+
|
37
|
+
def tag
|
38
|
+
ELEMENT_TO_STATUS_MAP.invert.fetch(status, status.to_s)
|
39
|
+
end
|
40
|
+
|
41
|
+
VALID_STATUSES.each do |status|
|
42
|
+
define_method(:"#{status}?") { self.public_send(:status) == :"#{status}" }
|
43
|
+
end
|
44
|
+
|
45
|
+
ELEMENT_TO_STATUS_MAP = {
|
46
|
+
"skipped" => :skip,
|
47
|
+
"failure" => :fail
|
48
|
+
}.freeze
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "juniter/element"
|
2
|
+
require "juniter/test_case"
|
3
|
+
require "juniter/test_suite_properties"
|
4
|
+
|
5
|
+
module Juniter
|
6
|
+
class TestSuite < Element
|
7
|
+
tag "testsuite"
|
8
|
+
|
9
|
+
attribute :name, required: true
|
10
|
+
attribute :test_count, as: :tests, required: true, map: ->(value) { value.to_i }
|
11
|
+
attribute :failure_count, as: :failures, map: ->(value) { value.to_i }
|
12
|
+
attribute :error_count, as: :errors, map: ->(value) { value.to_i }
|
13
|
+
attribute :disabled_count, as: :disabled, map: ->(value) { value.to_i }
|
14
|
+
attribute :skipped_count, as: :skipped, map: ->(value) { value.to_i }
|
15
|
+
attribute :duration, as: :time, map: ->(value) { value.to_f }
|
16
|
+
attribute :timestamp, map: ->(value) { Time.parse(value) }
|
17
|
+
attribute :hostname
|
18
|
+
attribute :id
|
19
|
+
attribute :package
|
20
|
+
|
21
|
+
child :test_cases, as: :testcase, array: true, map: ->(node) { TestCase.from_xml(node) }
|
22
|
+
child :properties, map: ->(node) { TestSuiteProperties.from_xml(node) }
|
23
|
+
child :stdout, as: :"system-out"
|
24
|
+
child :stderr, as: :"system-err"
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "juniter/test_suite_property"
|
2
|
+
|
3
|
+
module Juniter
|
4
|
+
class TestSuiteProperties < Array
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def from_xml(node)
|
8
|
+
new(node.nodes.map { |n| TestSuiteProperty.from_xml(n) })
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_xml
|
13
|
+
Ox::Element.new(:properties).tap do |properties|
|
14
|
+
each do |property|
|
15
|
+
properties << property.to_xml
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "juniter/element"
|
2
|
+
require "juniter/test_suite"
|
3
|
+
|
4
|
+
module Juniter
|
5
|
+
class TestSuites < Element
|
6
|
+
tag "testsuites"
|
7
|
+
|
8
|
+
attribute :name
|
9
|
+
attribute :duration, as: :time, map: ->(value) { value.to_f }
|
10
|
+
attribute :test_count, as: :tests, map: ->(value) { value.to_i }
|
11
|
+
attribute :failure_count, as: :failures, map: ->(value) { value.to_i }
|
12
|
+
attribute :disabled_count, as: :disabled, map: ->(value) { value.to_i }
|
13
|
+
attribute :error_count, as: :errors, map: ->(value) { value.to_i }
|
14
|
+
|
15
|
+
child :test_suites, as: :testsuite, array: true, map: ->(node) { TestSuite.from_xml(node) }
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: juniter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Kobs
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-05-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ox
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: shoulda-context
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest-stub-const
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- matt@kobsy.net
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".github/workflows/tests.yml"
|
105
|
+
- ".gitignore"
|
106
|
+
- ".travis.yml"
|
107
|
+
- CHANGELOG.md
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- juniter.gemspec
|
115
|
+
- lib/juniter.rb
|
116
|
+
- lib/juniter/element.rb
|
117
|
+
- lib/juniter/file.rb
|
118
|
+
- lib/juniter/has_attributes.rb
|
119
|
+
- lib/juniter/has_children.rb
|
120
|
+
- lib/juniter/test_case.rb
|
121
|
+
- lib/juniter/test_result.rb
|
122
|
+
- lib/juniter/test_suite.rb
|
123
|
+
- lib/juniter/test_suite_properties.rb
|
124
|
+
- lib/juniter/test_suite_property.rb
|
125
|
+
- lib/juniter/test_suites.rb
|
126
|
+
- lib/juniter/version.rb
|
127
|
+
homepage: https://github.com/kobsy/juniter
|
128
|
+
licenses:
|
129
|
+
- MIT
|
130
|
+
metadata:
|
131
|
+
homepage_uri: https://github.com/kobsy/juniter
|
132
|
+
source_code_uri: https://github.com/kobsy/juniter
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: 2.3.0
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubygems_version: 3.1.2
|
149
|
+
signing_key:
|
150
|
+
specification_version: 4
|
151
|
+
summary: Parse and interact with JUnit XML files as Ruby objects
|
152
|
+
test_files: []
|