minitest-reporters-json_reporter 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 94a1de8a674e4127f623f886a6ba0643726d5d86
4
+ data.tar.gz: 678bd26a89e8565ec5f1892fbf9d1c8ab65db7c7
5
+ SHA512:
6
+ metadata.gz: 32264e3865b0e4a3c287e96ab466d070c105e081e46847834c8c793062eae47cf45c715630d4fdca7895ec9c80688f0dbac190a186144b3d256c4774bbf5f3e7
7
+ data.tar.gz: a43bfb4e853845f1695b13c7877ef0020df3a0ea37bf8908704170c7d2fea69499b56f1ae560b0197afc8df4fc8136bfdc6006b8ed597a41e8a74af655140623
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,15 @@
1
+ # rubocop.yml - settings for Rubocop Ruby static code analyzer
2
+ Metrics/LineLength:
3
+ Max: 85
4
+ Exclude:
5
+ - 'minitest-reporters-json_reporter.gemspec'
6
+
7
+ Style/Documentation:
8
+ Exclude:
9
+ - 'spec/**/*'
10
+ - 'test/**/*'
11
+ #Style/Semicolon:
12
+ # Exclude:
13
+ # - 'lib/minitest/reporters/json_reporter.rb'
14
+ Metrics/ClassLength:
15
+ Max: 120
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in minitest-reporters-json_reporter.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 edhowland
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.
@@ -0,0 +1,58 @@
1
+ # Minitest::Reporters::JsonReporter
2
+
3
+ This is an extension gem for the minitest-reporters gem. It adds JSON output as an output format.
4
+ You can use this gem to interface MiniTest output into automated tools or IDEs or programmer's editors. An
5
+ example interface might be to the Atom editor: [https://atom.io](https://atom.io)
6
+ I originally wrote this gem to interface to the Viper audible Programmer's editor for the blind programmer community. See: [https://github.com/edhowland/viper](https://github.com/edhowland/viper)
7
+
8
+ ## Version 0.1.1
9
+
10
+
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'minitest-reporters-json_reporter'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install minitest-reporters-json_reporter
27
+
28
+ ## Usage
29
+
30
+ Add this line to your 'spec_helper.rb' or 'test_helper.rb':
31
+
32
+ ```
33
+ require 'minitest/reporters/json_reporter'
34
+ ```
35
+
36
+ In that same file, add something like this near the bottom of the file:
37
+
38
+ ```
39
+ MiniTest::Reporters.use! [ MiniTest::Reporters::JsonReporter.new ]
40
+ ```
41
+
42
+ Then run your tests as normal. You will get a JSON formatted string in stdout.
43
+ There are 5 objects contained within this output:
44
+
45
+ 1. metadata - General information about this test run. Includes generator name, version and the test run completion time in UTC formatted in ISO8601 format.
46
+ 2. status - Status of the overall test run. Can be 'Success', 'Passed with skipped tests' or 'Failed'. There also a color attribute: green, yellow or red - respectfully.
47
+ 3. statistics - Contains counts of the status of test cases. Includes: Total, Skipped, Failed Errored and Passed.
48
+ 4. fails - Array of failed or errored tests. Each object herein contains the information of each test, its name, class, error message and location of the test.
49
+ 5. skips - Array of each skipped. Each object contains the information as a failed test, including the skip message, if any.
50
+
51
+
52
+ ## Contributing
53
+
54
+ 1. Fork it ( https://github.com/edhowland/minitest-reporters-json_reporter/fork )
55
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
56
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
57
+ 4. Push to the branch (`git push origin my-new-feature`)
58
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,4 @@
1
+ # TODO.txt:
2
+
3
+
4
+ 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
@@ -0,0 +1,161 @@
1
+ # json_reporter.rb - class MiniTest::Reporters::JsonReporter
2
+
3
+ require 'json'
4
+ require 'time'
5
+ require 'minitest'
6
+ require 'minitest/reporters'
7
+
8
+ require_relative 'json_reporter/version'
9
+
10
+ # MiniTest namespace - plugins must live here
11
+ module MiniTest
12
+ # MiniTest::Reporters from minitest-reporters gem: See: https://github.com/kern/minitest-reporters
13
+ module Reporters
14
+ # MiniTest Reporter that produces a JSON output for interface in IDEs, editor
15
+ class JsonReporter < BaseReporter
16
+ def initialize(opts = {})
17
+ super(opts)
18
+ @skipped = 0
19
+ @failed = 0
20
+ @errored = 0
21
+ @passed = 0
22
+ @storage = init_status
23
+ end
24
+
25
+ def metadata_h
26
+ {
27
+ generated_by: self.class.name,
28
+ version: MiniTest::Reporters::JsonReporter::VERSION,
29
+ time: Time.now.utc.iso8601
30
+ }
31
+ end
32
+
33
+ def init_status
34
+ {
35
+ status: red_status,
36
+ metadata: metadata_h,
37
+ statistics: {},
38
+ fails: [],
39
+ skips: []
40
+ }
41
+ end
42
+
43
+ def record(test)
44
+ super
45
+ skipped(test) || errored(test) || failed(test) || passed(test)
46
+ end
47
+
48
+ def report
49
+ super
50
+ set_status # sets the sucess or failure and color in the status object
51
+ @storage[:statistics][:total] = @passed + @skipped + @failed + @errored
52
+ @storage[:statistics][:failed] = @failed
53
+ @storage[:statistics][:errored] = @errored
54
+ @storage[:statistics][:skipped] = @skipped
55
+ @storage[:statistics][:passed] = @passed
56
+
57
+ # output JSON
58
+ output($stdout, @storage)
59
+ end
60
+
61
+ def yellow?
62
+ @skipped > 0 && !red?
63
+ end
64
+
65
+ def green?
66
+ !red? && !yellow?
67
+ end
68
+
69
+ def red?
70
+ @failed + @errored > 0
71
+ end
72
+
73
+ private
74
+
75
+ def set_status
76
+ if yellow?
77
+ @storage[:status] = yellow_status
78
+ elsif green?
79
+ @storage[:status] = green_status
80
+ end
81
+ end
82
+
83
+ def color_h(code, color)
84
+ { code: code, color: color }
85
+ end
86
+
87
+ def red_status
88
+ color_h('Failed', 'red')
89
+ end
90
+
91
+ def yellow_status
92
+ color_h('Passed, with skipped tests', 'yellow')
93
+ end
94
+
95
+ def green_status
96
+ color_h('Success', 'green')
97
+ end
98
+
99
+ def location(exception)
100
+ last_before_assertion = ''
101
+
102
+ exception.backtrace.reverse_each do |s|
103
+ break if s =~ /in .(assert|refute|flunk|pass|fail|raise|must|wont)/
104
+ last_before_assertion = s
105
+ end
106
+
107
+ last_before_assertion.sub(/:in .*$/, '')
108
+ end
109
+
110
+ def fault_h(type, test, e)
111
+ {
112
+ type: type,
113
+ class: test.class.name,
114
+ name: test.name,
115
+ message: e.message,
116
+ location: location(e)
117
+ }
118
+ end
119
+
120
+ def status(type, test, msg, &_blk)
121
+ result = test.send(msg)
122
+ if result
123
+ e = fault_h(type, test, test.failure)
124
+ yield(e)
125
+ end
126
+
127
+ result
128
+ end
129
+
130
+ def skipped(test)
131
+ status('skipped', test, :skipped?) do |e|
132
+ @storage[:skips] << e
133
+ @skipped += 1
134
+ end
135
+ end
136
+
137
+ def errored(test)
138
+ status('error', test, :error?) do |e|
139
+ @storage[:fails] << e
140
+ @errored += 1
141
+ end
142
+ end
143
+
144
+ def failed(test)
145
+ status('failure', test, :failure) do |e|
146
+ @storage[:fails] << e
147
+ @failed += 1
148
+ end
149
+ end
150
+
151
+ def passed(_test)
152
+ @passed += 1
153
+ end
154
+
155
+ # I/O
156
+ def output(io, body)
157
+ io.write(JSON.dump(body))
158
+ end
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,12 @@
1
+ # version.rb - version constant: MiniTest::Reporters::JsonReporter::VERSION
2
+
3
+ # MiniTest namespace - plugins must live here
4
+ module MiniTest
5
+ # MiniTest::Reporters from minitest-reporters gem: See: https://github.com/kern/minitest-reporters
6
+ module Reporters
7
+ # MiniTest Reporter that produces a JSON output for interface in IDEs, editor.
8
+ class JsonReporter < BaseReporter
9
+ VERSION = '0.1.1'.freeze
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'minitest/reporters'
5
+
6
+ require 'minitest/reporters/json_reporter/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'minitest-reporters-json_reporter'
10
+ spec.version = Minitest::Reporters::JsonReporter::VERSION
11
+ spec.authors = ['edhowland']
12
+ spec.email = ['ed.howland@gmail.com']
13
+
14
+ spec.summary = 'JSON Reporter format for minitest-reporters gem.'
15
+ spec.description = ' Formats the output of a MiniTest run as JSON. Useful for interfacing MiniTest or MiniSpec to IDEs or programming text editors, such as the Atom editor.
16
+ See: https://atom.io. Originally written to interface with the Viper Audible editor for blind programmers. See https://github.com/edhowland/viper'
17
+ spec.homepage = "https://github.com/edhowland/minitest-reporters-json_reporter"
18
+ spec.license = 'MIT'
19
+
20
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+ spec.add_runtime_dependency 'minitest', '~> 5.7'
25
+ spec.add_runtime_dependency 'minitest-reporters', '~> 1.1.8'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.9'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest-reporters-json_reporter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - edhowland
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest-reporters
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.8
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.8
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: |2-
70
+ Formats the output of a MiniTest run as JSON. Useful for interfacing MiniTest or MiniSpec to IDEs or programming text editors, such as the Atom editor.
71
+ See: https://atom.io. Originally written to interface with the Viper Audible editor for blind programmers. See https://github.com/edhowland/viper
72
+ email:
73
+ - ed.howland@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rubocop.yml"
80
+ - ".travis.yml"
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - TODO.txt
87
+ - lib/minitest/reporters/json_reporter.rb
88
+ - lib/minitest/reporters/json_reporter/version.rb
89
+ - minitest-reporters-json_reporter.gemspec
90
+ homepage: https://github.com/edhowland/minitest-reporters-json_reporter
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.4.5
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: JSON Reporter format for minitest-reporters gem.
114
+ test_files: []
115
+ has_rdoc: