danger-junit 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fd37e7d87505b8882f61d0f5a9177d39f8990d6a
4
+ data.tar.gz: ef98520c2399b83cb9081bb4a84a16ef4c87d7ee
5
+ SHA512:
6
+ metadata.gz: 6b102f1eb6e859468b7594d9f91ee05ffed730ac1cd30f44428704d38bc838638bf96708c4e258992566c75086fb32e94831736fdc3bebc90ae13075fa9fcb0e
7
+ data.tar.gz: 4f5944bc1493db882898df5bb439694c7bdfeb3f44eb3c87c20701acb28241bfe9f2e4064a1bab87f29ac0b6a07edc74370b54f560ffcbce2c4c7099eb013a87
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+ pkg
3
+ .idea/
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ cache:
3
+ directories:
4
+ - bundle
5
+
6
+ rvm:
7
+ - 2.0
8
+ - 2.1.3
9
+ - 2.3.1
10
+
11
+ script:
12
+ - bundle exec rake spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in danger-junit.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,129 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ danger-junit (0.5.0)
5
+ danger (~> 2.0)
6
+ ox (~> 2.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.4.0)
12
+ ast (2.3.0)
13
+ claide (1.0.0)
14
+ claide-plugins (0.9.1)
15
+ cork
16
+ nap
17
+ open4 (~> 1.3)
18
+ coderay (1.1.1)
19
+ colored (1.2)
20
+ cork (0.1.0)
21
+ colored (~> 1.2)
22
+ danger (2.0.1)
23
+ claide (~> 1.0)
24
+ claide-plugins (> 0.9.0)
25
+ colored (~> 1.2)
26
+ cork (~> 0.1)
27
+ faraday (~> 0)
28
+ faraday-http-cache (~> 1.0)
29
+ git (~> 1)
30
+ octokit (~> 4.2)
31
+ redcarpet (~> 3.3)
32
+ terminal-table (~> 1)
33
+ diff-lcs (1.2.5)
34
+ faraday (0.9.2)
35
+ multipart-post (>= 1.2, < 3)
36
+ faraday-http-cache (1.3.0)
37
+ faraday (~> 0.8)
38
+ ffi (1.9.14)
39
+ formatador (0.2.5)
40
+ git (1.3.0)
41
+ guard (2.14.0)
42
+ formatador (>= 0.2.4)
43
+ listen (>= 2.7, < 4.0)
44
+ lumberjack (~> 1.0)
45
+ nenv (~> 0.1)
46
+ notiffany (~> 0.0)
47
+ pry (>= 0.9.12)
48
+ shellany (~> 0.0)
49
+ thor (>= 0.18.1)
50
+ guard-compat (1.2.1)
51
+ guard-rspec (4.7.3)
52
+ guard (~> 2.1)
53
+ guard-compat (~> 1.1)
54
+ rspec (>= 2.99.0, < 4.0)
55
+ listen (3.0.7)
56
+ rb-fsevent (>= 0.9.3)
57
+ rb-inotify (>= 0.9.7)
58
+ lumberjack (1.0.10)
59
+ method_source (0.8.2)
60
+ multipart-post (2.0.0)
61
+ nap (1.1.0)
62
+ nenv (0.3.0)
63
+ notiffany (0.1.1)
64
+ nenv (~> 0.1)
65
+ shellany (~> 0.0)
66
+ octokit (4.3.0)
67
+ sawyer (~> 0.7.0, >= 0.5.3)
68
+ open4 (1.3.4)
69
+ ox (2.4.3)
70
+ parser (2.3.1.2)
71
+ ast (~> 2.2)
72
+ powerpack (0.1.1)
73
+ pry (0.10.4)
74
+ coderay (~> 1.1.0)
75
+ method_source (~> 0.8.1)
76
+ slop (~> 3.4)
77
+ rainbow (2.1.0)
78
+ rake (10.5.0)
79
+ rb-fsevent (0.9.7)
80
+ rb-inotify (0.9.7)
81
+ ffi (>= 0.5.0)
82
+ redcarpet (3.3.4)
83
+ rspec (3.5.0)
84
+ rspec-core (~> 3.5.0)
85
+ rspec-expectations (~> 3.5.0)
86
+ rspec-mocks (~> 3.5.0)
87
+ rspec-core (3.5.2)
88
+ rspec-support (~> 3.5.0)
89
+ rspec-expectations (3.5.0)
90
+ diff-lcs (>= 1.2.0, < 2.0)
91
+ rspec-support (~> 3.5.0)
92
+ rspec-mocks (3.5.0)
93
+ diff-lcs (>= 1.2.0, < 2.0)
94
+ rspec-support (~> 3.5.0)
95
+ rspec-support (3.5.0)
96
+ rubocop (0.42.0)
97
+ parser (>= 2.3.1.1, < 3.0)
98
+ powerpack (~> 0.1)
99
+ rainbow (>= 1.99.1, < 3.0)
100
+ ruby-progressbar (~> 1.7)
101
+ unicode-display_width (~> 1.0, >= 1.0.1)
102
+ ruby-progressbar (1.8.1)
103
+ sawyer (0.7.0)
104
+ addressable (>= 2.3.5, < 2.5)
105
+ faraday (~> 0.8, < 0.10)
106
+ shellany (0.0.1)
107
+ slop (3.6.0)
108
+ terminal-table (1.6.0)
109
+ thor (0.19.1)
110
+ unicode-display_width (1.1.0)
111
+ yard (0.9.5)
112
+
113
+ PLATFORMS
114
+ ruby
115
+
116
+ DEPENDENCIES
117
+ bundler (~> 1.3)
118
+ danger-junit!
119
+ guard (~> 2.14)
120
+ guard-rspec (~> 4.7)
121
+ listen (= 3.0.7)
122
+ pry
123
+ rake (~> 10.0)
124
+ rspec (~> 3.4)
125
+ rubocop (~> 0.41)
126
+ yard (~> 0.8)
127
+
128
+ BUNDLED WITH
129
+ 1.12.5
data/Guardfile ADDED
@@ -0,0 +1,19 @@
1
+ # A guardfile for making Danger Plugins
2
+ # For more info see https://github.com/guard/guard#readme
3
+
4
+ # To run, use `bundle exec guard`.
5
+
6
+ guard :rspec, cmd: 'bundle exec rspec' do
7
+ require 'guard/rspec/dsl'
8
+ dsl = Guard::RSpec::Dsl.new(self)
9
+
10
+ # RSpec files
11
+ rspec = dsl.rspec
12
+ watch(rspec.spec_helper) { rspec.spec_dir }
13
+ watch(rspec.spec_support) { rspec.spec_dir }
14
+ watch(rspec.spec_files)
15
+
16
+ # Ruby files
17
+ ruby = dsl.ruby
18
+ dsl.watch_spec_files_for(ruby.lib_files)
19
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Orta Therox <orta.therox@gmail.com>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # danger-junit
2
+
3
+ A description of danger-junit.
4
+
5
+ ## Installation
6
+
7
+ $ gem install danger-junit
8
+
9
+ ## Usage
10
+
11
+
12
+
13
+ ### junit
14
+
15
+ Report, or inspect any JUnit XML formatted test suite report.
16
+
17
+ Testing frameworks have standardized on the JUnit XML format for
18
+ reporting results, this means that projects using Rspec, Jasmine, Mocha,
19
+ XCTest and more - can all use the same Danger error reporting. Perfect.
20
+
21
+ You can see some examples on [this page from Circle CI](https://circleci.com/docs/test-metadata/)
22
+ about how you can add JUnit XML output for your testing projects.
23
+
24
+ <blockquote>Parse the XML file, and let the plugin do your reporting
25
+ <pre>
26
+ junit.parse "/path/to/output.xml"
27
+ junit.report</pre>
28
+ </blockquote>
29
+
30
+ <blockquote>Let the plugin parse the XML file, and report yourself
31
+ <pre>
32
+ junit.parse "/path/to/output.xml"
33
+ fail("Tests failed") unless junit.fails.empty?</pre>
34
+ </blockquote>
35
+
36
+ <blockquote>Warn on a report about skipped tests
37
+ <pre>
38
+ junit.parse "/path/to/output.xml"
39
+ junit.show_skipped_tests = true
40
+ junit.report</pre>
41
+ </blockquote>
42
+
43
+
44
+
45
+ #### Attributes
46
+ <tr>
47
+ `passes` - An array of XML elements that represent passed tests.
48
+ <tr>
49
+ `failures` - An array of XML elements that represent failed tests.
50
+ <tr>
51
+ `errors` - An array of XML elements that represent passed tests.
52
+ <tr>
53
+ `skipped` - An array of XML elements that represent skipped tests.
54
+ <tr>
55
+ `show_skipped_tests` - An attribute to make the plugin show a warning on skipped tests.
56
+
57
+
58
+
59
+ #### Methods
60
+
61
+ `parse` - Parses an XML file, which fills all the attributes
62
+ will `raise` for errors
63
+
64
+ `report` - Causes a build fail if there are test failures,
65
+ and outputs a markdown table of the results.
66
+
67
+
68
+ ## Development
69
+
70
+ 1. Clone this repo
71
+ 2. Run `bundle install` to setup dependencies.
72
+ 3. Run `bundle exec rake spec` to run the tests.
73
+ 4. Use `bundle exec guard` to automatically have tests run as you make changes.
74
+ 5. Make your changes.
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:specs)
6
+
7
+ task default: :specs
8
+
9
+ task :spec do
10
+ Rake::Task['specs'].invoke
11
+ Rake::Task['rubocop'].invoke
12
+ Rake::Task['spec_docs'].invoke
13
+ end
14
+
15
+ desc 'Run RuboCop on the lib/specs directory'
16
+ RuboCop::RakeTask.new(:rubocop) do |task|
17
+ task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
18
+ end
19
+
20
+ desc 'Ensure that the plugin passes `danger plugins lint`'
21
+ task :spec_docs do
22
+ sh 'bundle exec danger plugins lint'
23
+ end
@@ -0,0 +1,47 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'junit/gem_version.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'danger-junit'
8
+ spec.version = Junit::VERSION
9
+ spec.authors = ['Orta Therox']
10
+ spec.email = ['orta.therox@gmail.com']
11
+ spec.description = 'Get automatic inline test reporting for JUnit-conforming XML files.'
12
+ spec.summary = 'Get automatic inline test reporting for JUnit-conforming XML files'
13
+ spec.homepage = 'https://github.com/orta/danger-junit'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'danger', '~> 2.0'
22
+ spec.add_runtime_dependency 'ox', '~> 2.0'
23
+
24
+ # General ruby development
25
+ spec.add_development_dependency 'bundler', '~> 1.3'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+
28
+ # Testing support
29
+ spec.add_development_dependency 'rspec', '~> 3.4'
30
+
31
+ # Linting code and docs
32
+ spec.add_development_dependency 'rubocop', '~> 0.41'
33
+ spec.add_development_dependency 'yard', '~> 0.8'
34
+
35
+ # Makes testing easy via `bundle exec guard`
36
+ spec.add_development_dependency 'guard', '~> 2.14'
37
+ spec.add_development_dependency 'guard-rspec', '~> 4.7'
38
+
39
+ # If you want to work on older builds of ruby
40
+ spec.add_development_dependency 'listen', '3.0.7'
41
+
42
+ # This gives you the chance to run a REPL inside your test
43
+ # via
44
+ # binding.pry
45
+ # This will stop test execution and let you inspect the results
46
+ spec.add_development_dependency 'pry'
47
+ end
@@ -0,0 +1 @@
1
+ require 'junit/gem_version'
@@ -0,0 +1 @@
1
+ require 'junit/plugin'
@@ -0,0 +1,3 @@
1
+ module Junit
2
+ VERSION = '0.5.0'.freeze
3
+ end
@@ -0,0 +1,108 @@
1
+ module Danger
2
+ # Report, or inspect any JUnit XML formatted test suite report.
3
+ #
4
+ # Testing frameworks have standardized on the JUnit XML format for
5
+ # reporting results, this means that projects using Rspec, Jasmine, Mocha,
6
+ # XCTest and more - can all use the same Danger error reporting. Perfect.
7
+ #
8
+ # You can see some examples on [this page from Circle CI](https://circleci.com/docs/test-metadata/)
9
+ # about how you can add JUnit XML output for your testing projects.
10
+ #
11
+ # @example Parse the XML file, and let the plugin do your reporting
12
+ #
13
+ # junit.parse "/path/to/output.xml"
14
+ # junit.report
15
+ #
16
+ # @example Let the plugin parse the XML file, and report yourself
17
+ #
18
+ # junit.parse "/path/to/output.xml"
19
+ # fail("Tests failed") unless junit.fails.empty?
20
+ #
21
+ # @example Warn on a report about skipped tests
22
+ #
23
+ # junit.parse "/path/to/output.xml"
24
+ # junit.show_skipped_tests = true
25
+ # junit.report
26
+ #
27
+ # @see orta/danger-junit, danger/danger, artsy/eigen
28
+ # @tags testing, reporting, junit, rspec, jasmine, jest, xcpretty
29
+ #
30
+ class DangerJunit < Plugin
31
+ # An array of XML elements that represent passed tests.
32
+ #
33
+ # @return [Array<Ox::Element>]
34
+ attr_accessor :passes
35
+
36
+ # An array of XML elements that represent failed tests.
37
+ #
38
+ # @return [Array<Ox::Element>]
39
+ attr_accessor :failures
40
+
41
+ # An array of XML elements that represent passed tests.
42
+ #
43
+ # @return [Array<Ox::Element>]
44
+ attr_accessor :errors
45
+
46
+ # An array of XML elements that represent skipped tests.
47
+ #
48
+ # @return [Array<Ox::Element>]
49
+ attr_accessor :skipped
50
+
51
+ # An attribute to make the plugin show a warning on skipped tests.
52
+ #
53
+ # @return [Bool]
54
+ attr_accessor :show_skipped_tests
55
+
56
+ # Parses an XML file, which fills all the attributes
57
+ # will `raise` for errors
58
+ # @return [void]
59
+ def parse(file)
60
+ require 'ox'
61
+ raise "No Junit file was found at #{file}" unless File.exist? file
62
+
63
+ xml_string = File.read file
64
+ @doc = Ox.parse xml_string
65
+
66
+ suite_root = @doc.nodes.first.value == 'testsuites' ? @doc.nodes.first : @doc
67
+ tests = suite_root.nodes.map(&:nodes).flatten.select { |node| node.value == 'testcase' }
68
+
69
+ failed_suites = suite_root.nodes.select { |suite| suite[:failures].to_i > 0 || suite[:errors].to_i > 0 }
70
+ failed_tests = failed_suites.map(&:nodes).flatten.select { |node| node.value == 'testcase' }
71
+
72
+ @failures = failed_tests.select { |test| test.nodes.count > 0 }.select { |test| test.nodes.first.value == 'failure' }
73
+
74
+ @errors = failed_tests.select { |test| test.nodes.count > 0 }.select { |test| test.nodes.first.value == 'error' }
75
+
76
+ @skipped = tests.select { |test| test.nodes.count > 0 }.select { |test| test.nodes.first.value == 'skipped' }
77
+
78
+ @passes = tests - @failures - @errors - @skipped
79
+ end
80
+
81
+ # Causes a build fail if there are test failures,
82
+ # and outputs a markdown table of the results.
83
+ #
84
+ # @return [void]
85
+ def report
86
+ warn("Skipped #{skipped.count} tests.") if show_skipped_tests && skipped.count > 0
87
+
88
+ unless failures.empty? && errors.empty?
89
+ fail("Tests have failed, see below for more information.", sticky: false)
90
+ message = "### Tests: \n\n"
91
+
92
+ tests = (failures + errors)
93
+ keys = tests.first.attributes.keys
94
+ attributes = keys.map(&:to_s).map(&:capitalize)
95
+
96
+ # Create the header
97
+ message << attributes.join(' | ') + "|\n"
98
+ message << attributes.map { |_| '---' }.join(' | ') + "|\n"
99
+
100
+ tests.each do |test|
101
+ message << test.attributes.values.join(' | ') + "|\n"
102
+ end
103
+
104
+ markdown message
105
+ end
106
+ end
107
+ end
108
+ end