minitest-reporters-json_reporter 0.2.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f5f134ca33ed222b123711da89d4d1a11e7e028a
4
- data.tar.gz: fc6d7d916c7798d6e091232c382be1a439f31680
3
+ metadata.gz: 79425b4f7ac452e39470769e75a23773949d9531
4
+ data.tar.gz: f5170807896b351ad3669c601c2ae3d567e17dea
5
5
  SHA512:
6
- metadata.gz: 47bcd68180b082db1ba5549fc14929faa540052128b792d6d1673d663cd45e2d245e9bf598962b1645bc09456c7c17b384d4f24f879b986380d76f0fcf4c8069
7
- data.tar.gz: b3c875b539c0c087ae6f7bb90adc4ebeddb77d7b8efaa38578f4d9ac660765aa09ccbc5ce870eeb4fc3119ea9bb4be608009103f28998f354b743208ecb216ab
6
+ metadata.gz: 1735a7dc30c50e75ce8e5c98776ca67818c31937d49d8b6ac7ad4f01a1c1b2e4d79c513e7e963d762310b23d17baffa1ece6d69c43d4777df9176fbd766b75ce
7
+ data.tar.gz: 211f32fdc974942a3354076463ec827b27ee6487662d86207e7bb3ffbe3105fa6ade14ce7db90ee83e7d1596b716124c73bfb8384fddfbe8af25e5514c6b0bf7
data/.rubocop.yml CHANGED
@@ -15,8 +15,12 @@ Style/Semicolon:
15
15
  # - 'lib/minitest/reporters/json_reporter.rb'
16
16
 
17
17
  Metrics/ClassLength:
18
- Max: 120
18
+ Max: 140
19
19
 
20
20
  Style/GlobalVars:
21
21
  Exclude:
22
22
  - 'test/**/*'
23
+
24
+ Style/ClassAndModuleChildren:
25
+ Exclude:
26
+ - 'test/fake_tests.rb'
data/Announcement.txt CHANGED
@@ -1,17 +1,21 @@
1
- minitest-reporters-json_reporter version 0.2.0 has been released.
1
+ minitest-reporters-json_reporter version 0.9.1 has been released.
2
2
 
3
3
  Home, Code: https://github.com/edhowland/minitest-reporters-json_reporter
4
4
  Bugs: https://github.com/edhowland/minitest-reporters-json_reporter/issues
5
- Docs:https://github.com/edhowland/minitest-reporters-json_reporter/blob/master/doc/index.html
5
+ Docs:http://www.rubydoc.info/gems/minitest-reporters-json_reporter/0.9.1
6
6
 
7
7
  minitest-reporters-json_reporter is an extension to the Ruby minitest-reporters gem that provides JSON output from your Minitest or MiniSpec test run.
8
+ This version is the beta/release candidate before the official 1.0 version.
8
9
 
9
- This version is the preliminary version before doing a PR to the mainline Minitest::Reporters gem.
10
- It includes a normal unit test in the test folder of the source repository.
11
- It also includes a customizable output file destination: test/report/json_report.json, some other file or stdout.
12
- It also includes the passed tests if the --verbose flag is passed.
13
- It also embeds the backtrace for error fails.
14
- It also adds parsed command line options to the metadata object.
10
+ Changes:
11
+
12
+ Rewritten to be:
13
+ o conformant with Minitest::Reporters superclass.
14
+ o Simpler and easy to customize.
15
+ o More inclusive of elements from the Minitest test run.
16
+ o Includes:
17
+ o Timings.
18
+ o Count of assertions.
15
19
 
16
20
  Abstract
17
21
 
@@ -20,11 +24,6 @@ for Minitest, but no JSON format until now. If you want to hook up an IDE or som
20
24
  framework like a CI or CD tool, it is natural to send output in some parsable format like XML or JSON. This extension summarizes the result of
21
25
  a test run in format like JSON.a test run in an easible consumable format.
22
26
 
23
- Anti-features:
24
-
25
- This version does not include any timing statistics.
26
- However, you can subclass Minitest::Reporters::JsonReporter and add to the storage accessor any object. This is just a Hash.
27
- The class is derived from Minitest::StatisticsReporter wherin you can get this detail.
28
27
 
29
28
  Usage is very simple. Just require 'minitest/reporters/json_reporter' in your test_helper.rb or spec_helper.rb.
30
29
  This gem also depends on 'minitest' and 'minitest/reporters'. Then, you should also invoke the use! method of Minitest::Reporters class with a call to Minitest::Reporters::JsonReporter.new.
@@ -40,82 +39,12 @@ Minitest::Reporters.use! [Minitest::Reporters::JsonReporter.new]
40
39
 
41
40
  Here is the URLs for the dependent gems:
42
41
 
43
- minitest (5.7.0, 5.4.3) : https://rubygems.org/gems/minitest
44
- minitest-reporters (1.1.8) : https://rubygems.org/gems/minitest-reporters
42
+ minitest : https://rubygems.org/gems/minitest
43
+ minitest-reporters : https://rubygems.org/gems/minitest-reporters
45
44
 
46
45
  The JSON format is sent to stdout when you run a test or all tests.
47
- There are 5 (or 6) objects contained within this output:
48
- The 6th object : passes is only present when --verbose or the options[:verbose] is supplied.
49
-
50
- 1. 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.
51
- 2. metadata - General information about this test run. Includes generator name, version and the test run completion time in UTC formatted in ISO8601 format. This also include the parsed command line in the options object.
52
- 3. statistics - Contains counts of the status of test cases. Includes: Total, Skipped, Failed Errored and Passed.
53
- 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. Tests that generate an error also contain the filter backtrace.
54
- 5. skips - Array of each skipped. Each object contains the information as a failed test, including the skip message, if any.
55
- 6. passes: (Optional: if --verbose is passed to the test): Class name, name and location of the passed test.
56
-
57
- Here is a sample test run:
58
- # Pretty up JSON output with jq
59
- $ cd test/functional
60
- $ ruby report_spec.rb | jq .
61
- {
62
- "status": {
63
- "code": "Failed",
64
- "color": "red"
65
- },
66
- "metadata": {
67
- "generated_by": "Minitest::Reporters::JsonReporter",
68
- "version": "0.2.0",
69
- "time": "2016-04-21T19:09:34Z",
70
- "options": {
71
- "io": "STDOUT",
72
- "seed": 2579,
73
- "args": "--seed 2579"
74
- }
75
- },
76
- "statistics": {
77
- "total": 5,
78
- "failed": 2,
79
- "errored": 1,
80
- "skipped": 1,
81
- "passed": 1
82
- },
83
- "fails": [
84
- {
85
- "type": "failure",
86
- "class": "failure",
87
- "name": "test_0001_anonymous",
88
- "message": "Expected: 2\n Actual: 1",
89
- "location": "report_spec.rb:14"
90
- },
91
- {
92
- "type": "failure",
93
- "class": "second failure",
94
- "name": "test_0001_anonymous",
95
- "message": "Expected: 9\n Actual: 3",
96
- "location": "report_spec.rb:20"
97
- },
98
- {
99
- "type": "error",
100
- "class": "Error",
101
- "name": "test_0001_anonymous",
102
- "message": "RuntimeError: should fail\n report_spec.rb:6:in `block (2 levels) in <main>'",
103
- "location": "report_spec.rb:6",
104
- "backtrace": [
105
- "report_spec.rb:6:in `block (2 levels) in <main>'"
106
- ]
107
- }
108
- ],
109
- "skips": [
110
- {
111
- "type": "skipped",
112
- "class": "skipped test",
113
- "name": "test_0001_anonymous",
114
- "message": "what a layabout",
115
- "location": "report_spec.rb:32"
116
- }
117
- ]
118
- }
46
+ You can customize where the JSON file is written by setting the :io attribute. It must be some IO stream.
47
+ You can see the format of the JSON created by looking at the Home page on GitHub: https://github.com/edhowland/minitest-reporters-json_reporter
119
48
 
120
49
  You can use JSON parsing tools to get elements or subsets of this format. One such tool is JQ: https://stedolan.github.io/jq/
121
50
 
@@ -124,8 +53,12 @@ Here is how you might view only the color of the test:
124
53
  $ ruby blog_test.rb | jq -r .status.color
125
54
  green
126
55
 
56
+ If you want to customize the format of the JSON string, you only need to subclass the Minitest::Reporters::JsonReporter class
57
+ and override the to_h method. See the file README.md for an example on this.
58
+
127
59
  If you find this gem useful, please send me a note about how you are using it.
128
60
  I would be interested if you are hooking it up to an automated framework like CI, CD or a code editor or IDE.
61
+
129
62
  Thanks, Ed
130
63
 
131
64
  Author: Ed Howland email: ed.howland@gmail.com
data/README.md CHANGED
@@ -1,12 +1,17 @@
1
1
  # Minitest::Reporters::JsonReporter
2
2
 
3
3
  This is an extension gem for the minitest-reporters gem. It adds JSON output as an output format.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/minitest-reporters-json_reporter.svg)][gem]
6
+
7
+ ## Abstract
8
+
4
9
  You can use this gem to interface Minitest output into automated tools like CI, CD or IDEs or code editors. An
5
10
  example interface might be to the Atom editor: [https://atom.io](https://atom.io)
6
11
  I originally wrote this gem to interface to the Viper audible code editor for the blind community. See: [https://github.com/edhowland/viper](https://github.com/edhowland/viper)
12
+ Using this gem with Viper also requires the 'viper_ruby' package. See [https://github.com/edhowland/viper_ruby](https://github.com/edhowland/viper_ruby)
7
13
 
8
- ## Version 0.2.0
9
-
14
+ ## Version 0.9.1
10
15
 
11
16
  ## Installation
12
17
 
@@ -40,62 +45,113 @@ Minitest::Reporters.use! [ Minitest::Reporters::JsonReporter.new ]
40
45
 
41
46
  Then run your tests as normal. You will get a JSON formatted string in stdout.
42
47
 
43
- There are 5 or 6 objects contained within this output: The 6th object: passes is only included if the --verbose option was passed to the test or set in the options parameter to the constructor.
44
48
 
45
- 1. 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.
46
- 2. metadata - General information about this test run. Includes generator name, version and the test run completion time in UTC formatted in ISO8601 format. Also include options object computed by super classes including command line arguments.
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 and the filtered backtrace array if an error type.
49
- 5. skips - Array of each skipped. Each object contains the information as a failed test, including the skip message, if any.
50
- 6. passes - Array of passing tests if the --verbose option was set . This object is normally absent otherwise.
51
-
52
- Here is a sample output:
49
+ ## Object Summary
50
+
51
+
52
+ * status of the overall test run. Object.
53
+ * code - Success, Passed with skipped tests or Failed. String.
54
+ * color green, yellow or red. String.
55
+ * metadata The metadata of this particular test run. Object.
56
+ * generated_by Class name of the Minitest Reporter. Will usually be Minitest::Reporters::JsonReporter. String.
57
+ * version - Version of the minitest-reporters-json_reporter gem. String.
58
+ * ruby_version - RUBY_VERSION. String.
59
+ * ruby_patchlevel - RUBY_PATCHLEVEL. Integer.
60
+ * ruby_platform - RUBY_PLATFORM. String.
61
+ * time - Time of test run in UTC and ISO-8601 format. String.
62
+ * options - Options object as constructed by passed options, superclasses and command line args. Object.
63
+ * io - The class name of the IO object. Will be the string 'STDOUT' if equal to $stdout. String.
64
+ * keys of the options hash, if any. Various key/value pairs.
65
+ * args Array of arguments passed to the program. Array of String.
66
+ * total_count - Total number of tests ran. Integer.
67
+ * statisticsThe accumulated counts for this test run. Object.
68
+ * total Number of total runs. Integer.
69
+ * assertions Count of assertions performed. Integer.
70
+ * failures Number of failed tests. Integer.
71
+ * errors Number of errors encountered. Integer.
72
+ * skips Number of skipped tests. Integer.
73
+ * passes Number of passed tests. Integer.
74
+ * timings Object containing the computed timing information for the entire test run. Object.
75
+ * total_seconds total number of seconds for the entire test run. Float.
76
+ * runs_per_second Averaged number of runs per second. Float.
77
+ * assertions_per_second Averaged number of assertions per second. Float.
78
+ * fails - Array of failed or errored tests. Array of Object.
79
+ * type Type of the failure. Either 'failure' or 'error'. String.
80
+ * classClass name of the test. String.
81
+ * name Name of the test. String.
82
+ * assertions Number of the assertions for this test. Integer.
83
+ * time Time in seconds for this test. Float.
84
+ * message Message reported by this failure or error. String.
85
+ * location File name and line number. file:line. String.
86
+ * backtrace (exists only if type is 'error') Array of backtrace paths and line numbers. Array of String.
87
+ * skips Array of skipped tests. Array of Object.
88
+ * type The string 'skipped'. String.
89
+ * class Class name of the test. String.
90
+ * name The name of the test. String.
91
+ * assertions The count of the assertions for this test. Integer.
92
+ * time The time of this test in seconds. Float.
93
+ * message The message string passed to the 'skip()' method. String.
94
+ * location File name and line number. file:line. String.
95
+ * passes Array of passed test runs. Array of Object.
96
+ * type The string 'passed'. String.
97
+ * class Class name of the test. String.
98
+ * name The name of the test. String.
99
+ * assertions The count of the assertions for this test. Integer.
100
+ * time The time of this test in seconds. Float.
101
+
102
+ The last 2 objects: skips[] and passes[] are absent unless the --verbose command
103
+ line flag was passed or if the options[:verbose] value is true.
104
+
105
+
106
+
107
+ ### Sample output
53
108
 
54
109
  ```
55
110
  # Use jq to pretty print the JSON output
56
111
  $ cd test/functional/
57
- $ ruby report_spec.rb --verbose | jq .
112
+ $ ruby report_spec.rb | jq .
58
113
  {
59
- "status": {
60
- "code": "Failed",
61
- "color": "red"
62
- },
114
+ "status": { "code": "Failed", "color": "red" },
63
115
  "metadata": {
64
116
  "generated_by": "Minitest::Reporters::JsonReporter",
65
- "version": "0.2.0",
66
- "time": "2016-04-21T19:09:34Z",
117
+ "version": "0.9.1",
118
+ "ruby_version": "2.2.2",
119
+ "ruby_patchlevel": 95,
120
+ "ruby_platform": "x86_64-linux",
121
+ "time": "2016-05-03T20:57:42Z",
67
122
  "options": {
68
123
  "io": "STDOUT",
69
- "seed": 2579,
70
- "args": "--seed 2579"
124
+ "verbose": true,
125
+ "seed": 3023,
126
+ "args": "--verbose --seed 3023",
127
+ "total_count": 5
71
128
  }
72
129
  },
73
- "statistics": {
74
- "total": 5,
75
- "failed": 2,
76
- "errored": 1,
77
- "skipped": 1,
78
- "passed": 1
130
+ "statistics": { "total": 5, "assertions": 4, "failures": 2,
131
+ "errors": 1, "skips": 1, "passes": 1 },
132
+ "timings": {
133
+ "total_seconds": 0.0014724910142831504,
134
+ "runs_per_second": 3395.606459733908,
135
+ "assertions_per_second": 2716.4851677871266
79
136
  },
80
137
  "fails": [
81
138
  {
82
- "type": "failure",
83
- "class": "failure",
84
- "name": "test_0001_anonymous",
85
- "message": "Expected: 2\n Actual: 1",
86
- "location": "report_spec.rb:14"
87
- },
88
- {
89
- "type": "failure",
90
- "class": "second failure",
91
- "name": "test_0001_anonymous",
139
+ "type": "failed", "class": "second failure", "name": "test_0001_anonymous",
140
+ "assertions": 1, "time": 9.327399311587214e-05,
92
141
  "message": "Expected: 9\n Actual: 3",
93
142
  "location": "report_spec.rb:20"
94
143
  },
95
144
  {
96
- "type": "error",
97
- "class": "Error",
98
- "name": "test_0001_anonymous",
145
+ "type": "failed",
146
+ "class": "failure", "name": "test_0001_anonymous", "assertions": 1,
147
+ "time": 3.400500281713903e-05,
148
+ "message": "Expected: 2\n Actual: 1",
149
+ "location": "report_spec.rb:14"
150
+ },
151
+ {
152
+ "type": "error", "class": "Error",
153
+ "name": "test_0001_anonymous", "assertions": 0,
154
+ "time": 2.1556013962253928e-05,
99
155
  "message": "RuntimeError: should fail\n report_spec.rb:6:in `block (2 levels) in <main>'",
100
156
  "location": "report_spec.rb:6",
101
157
  "backtrace": [
@@ -105,17 +161,47 @@ $ ruby report_spec.rb --verbose | jq .
105
161
  ],
106
162
  "skips": [
107
163
  {
108
- "type": "skipped",
109
- "class": "skipped test",
110
- "name": "test_0001_anonymous",
164
+ "type": "skipped", "class": "skipped test", "name": "test_0001_anonymous",
165
+ "assertions": 0,
166
+ "time": 3.7049001548439264e-05,
111
167
  "message": "what a layabout",
112
- "location": "report_spec.rb:32"
168
+ "location": "report_spec.rb:34"
169
+ }
170
+ ],
171
+ "passes": [
172
+ {
173
+ "type": "passed", "class": "working assertion",
174
+ "name": "test_0001_should have 2 working assertions", "assertions": 2,
175
+ "time": 2.5684013962745667e-05
113
176
  }
114
177
  ]
115
178
  }
116
179
 
117
180
  ```
118
181
 
182
+ ## Customizing the JSON format
183
+
184
+ You can adjust the contents of the returned JSON by sub-classing the Minitest::Reporters::JsonReporter class.
185
+ Override the 'to_h' method and delete or modifythe hash it returns.
186
+
187
+ Here is a simple example that eliminates the 'metadata' and 'timmings' components:
188
+
189
+ ```
190
+ # example spec_helper.rb:
191
+
192
+ class Minitest::Reporters::SlimJsonReporter < Minitest::Reporters::JsonReporter
193
+ def to_h
194
+ h = super
195
+ h.delete(:metadata)
196
+ h.delete(:timings)
197
+ h
198
+ end
199
+ end
200
+
201
+ Minitest::Reporters.use!( Minitest::Reporters::SlimJsonReporter.new )
202
+ ```
203
+
204
+
119
205
 
120
206
  ## Contributing
121
207
 
@@ -127,3 +213,20 @@ $ ruby report_spec.rb --verbose | jq .
127
213
 
128
214
  Note: Extra credit if git flow feature branching was used.
129
215
 
216
+
217
+ ## Resources
218
+
219
+ * Code: [https::/github.com/edhowland/minitest-reporters-json_reporter](https::/github.com/edhowland/minitest-reporters-json_reporter)
220
+ * Bugs: https://github.com/edhowland/minitest-reporters-json_reporter/issues
221
+ * Gem: [https://rubygems.org/gems/minitest-reporters-json_reporter](https://rubygems.org/gems/minitest-reporters-json_reporter)
222
+ * Documentation: [http://www.rubydoc.info/gems/minitest-reporters-json_reporter/0.9.1](http://www.rubydoc.info/gems/minitest-reporters-json_reporter/0.9.1)
223
+
224
+ ###### Feedback
225
+
226
+ If you find this gem helpful, please slip me a note via e-mail: ed.howland@gmail.com
227
+
228
+
229
+ I would like to know if anyone has used this approach to interface Minitest to any automated framework or editor.
230
+
231
+ Thanks, Ed.
232
+
data/doc/Minitest.html CHANGED
@@ -4,7 +4,7 @@
4
4
  <head>
5
5
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
6
  <title>
7
- Module: MiniTest
7
+ Module: Minitest
8
8
 
9
9
  &mdash; Documentation by YARD 0.8.7.6
10
10
 
@@ -17,7 +17,7 @@
17
17
  <script type="text/javascript" charset="utf-8">
18
18
  hasFrames = window.top.frames.main ? true : false;
19
19
  relpath = '';
20
- framesUrl = "frames.html#!MiniTest.html";
20
+ framesUrl = "frames.html#!Minitest.html";
21
21
  </script>
22
22
 
23
23
 
@@ -34,7 +34,7 @@
34
34
  <a href="_index.html">Index (M)</a> &raquo;
35
35
 
36
36
 
37
- <span class="title">MiniTest</span>
37
+ <span class="title">Minitest</span>
38
38
 
39
39
 
40
40
  <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
@@ -63,7 +63,7 @@
63
63
 
64
64
  <iframe id="search_frame"></iframe>
65
65
 
66
- <div id="content"><h1>Module: MiniTest
66
+ <div id="content"><h1>Module: Minitest
67
67
 
68
68
 
69
69
 
@@ -79,7 +79,9 @@
79
79
 
80
80
 
81
81
  <dt class="r1 last">Defined in:</dt>
82
- <dd class="r1 last">lib/minitest/reporters/json_reporter/skip_detail.rb</dd>
82
+ <dd class="r1 last">lib/minitest/reporters/json_reporter.rb<span class="defines">,<br />
83
+ lib/minitest/reporters/json_reporter/version.rb</span>
84
+ </dd>
83
85
 
84
86
  </dl>
85
87
  <div class="clear"></div>
@@ -87,7 +89,7 @@
87
89
  <h2>Overview</h2><div class="docstring">
88
90
  <div class="discussion">
89
91
 
90
- <p>MiniTest Namespace for all things Minitest</p>
92
+ <p>Minitest namespace - plugins must live here</p>
91
93
 
92
94
 
93
95
  </div>
@@ -99,7 +101,7 @@
99
101
  <p class="children">
100
102
 
101
103
 
102
- <strong class="modules">Modules:</strong> <span class='object_link'><a href="MiniTest/Reporters.html" title="MiniTest::Reporters (module)">Reporters</a></span>
104
+ <strong class="modules">Modules:</strong> <span class='object_link'><a href="Minitest/Reporters.html" title="Minitest::Reporters (module)">Reporters</a></span>
103
105
 
104
106
 
105
107
 
@@ -117,7 +119,7 @@
117
119
  </div>
118
120
 
119
121
  <div id="footer">
120
- Generated on Thu Apr 21 20:48:52 2016 by
122
+ Generated on Tue May 3 20:15:41 2016 by
121
123
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
122
124
  0.8.7.6 (ruby-2.2.2).
123
125
  </div>