minitest-summarize 0.0.2

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: e5d19e862386d46d91aece0676ffa467f564a5c0
4
+ data.tar.gz: f20714e5769844964c137783ac5b1e7bff13d269
5
+ SHA512:
6
+ metadata.gz: e95c356c2f22d9a6f4784f9c2c158fbd3f92847d9fab3e76d95eee93283f0ccc986327c6af687b7ccfdcaf1162dd4ac6e39175f130b2bf99c16b60cd91d1b7f9
7
+ data.tar.gz: f54f01a442b80921354f58295d7ea53e79d3ebad885a29fefeea82b06c8e9139ad50afffacb430f042a5853fa6863403ecfa23c8295580683c9fbb25fb4c9712
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ (The MIT License)
2
+
3
+ Copyright © Randy Carnahan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the 'Software'), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9
+ of the Software, and to permit persons to whom the Software is furnished to do
10
+ so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # Minitest Summarize
2
+
3
+ I love Minitest. It's really helped me not just better understand BDD, but
4
+ really dive into how the tests are run and so forth.
5
+
6
+ The source for Minitest is **_really_** easy to read and understand.
7
+
8
+ However, even despite some of my favorite output plugins making things nice,
9
+ the one thing I got tired of was the long line of dots (or [emoji][1]!) so I
10
+ decided to fix it.
11
+
12
+ Thus, this Minitest plugin.
13
+
14
+ ## Description
15
+
16
+ Instead of printing out the standard Minitest output per test, this will
17
+ instead update a summary of the results, in color unless told not to use color.
18
+
19
+ ## Install
20
+
21
+ ```sh
22
+ gem install minitest-summarize
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ require 'minitest/autorun'
29
+ require 'minitest/summarize'
30
+ ```
31
+
32
+ Then, when your tests are run, it'll display a summary before the results long
33
+ form results:
34
+
35
+ ```text
36
+ [Skipped: 1] [Passed: 30] [Failed 2] [Error: 0]
37
+
38
+ Finished in 0.002814s, 11728.0541 runs/s, 11372.6586 assertions/s.
39
+
40
+ 1) Failure:
41
+ do some tests#test_0031_has some fails [/Users/rcarnahan/repos/minitest-summarize/spec/main_spec.rb:14]:
42
+ Expected: 1
43
+ Actual: 0
44
+
45
+ 2) Failure:
46
+ do some tests#test_0032_has some fails [/Users/rcarnahan/repos/minitest-summarize/spec/main_spec.rb:14]:
47
+ Expected: 2
48
+ Actual: 1
49
+
50
+ 3) Skipped:
51
+ do some tests#test_0033_has some skips [/Users/rcarnahan/repos/minitest-summarize/spec/main_spec.rb:20]:
52
+ Skip #0
53
+ ```
54
+
55
+ If you do not want to use color, then you must specify that before tests are
56
+ run via the `no_color!` class method:
57
+
58
+ ```ruby
59
+ Minitest::Summarize.no_color!
60
+ ```
61
+
62
+ ## License
63
+
64
+ MIT.
65
+
66
+ [1]: <https://github.com/tenderlove/minitest-emoji>
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,3 @@
1
+ require 'minitest'
2
+
3
+ Minitest.load_plugins
@@ -0,0 +1,16 @@
1
+ require 'minitest'
2
+
3
+ require_relative './summarize_reporter'
4
+
5
+ Minitest::SummarizeReporter.color!
6
+
7
+ # Update Minitest with Plugin data.
8
+ module Minitest
9
+ def self.plugin_summarize_init(options)
10
+ Minitest.reporter.reporters.clear
11
+
12
+ io = options[:io]
13
+
14
+ Minitest.reporter << SummarizeReporter.new(io)
15
+ end
16
+ end
@@ -0,0 +1,125 @@
1
+ # Add our customer reporter to the Minitest module.
2
+ module Minitest
3
+ # Define our custom reporter.
4
+ class SummarizeReporter < Minitest::StatisticsReporter
5
+ SUMMARY_LABELS = {
6
+ '.' => 'Passed:',
7
+ 'F' => 'Failed',
8
+ 'E' => 'Error:',
9
+ 'S' => 'Skipped:'
10
+ }.freeze
11
+
12
+ CODE_TO_COLOR = {
13
+ '.' => :green,
14
+ 'F' => :red,
15
+ 'E' => :red,
16
+ 'S' => :blue
17
+ }.freeze
18
+
19
+ COLOR_CODE = {
20
+ red: 31,
21
+ green: 32,
22
+ blue: 34,
23
+ none: 0
24
+ }.freeze
25
+
26
+ STATS_FORMAT = 'Finished in %.6fs, %.4f runs/s, %.4f assertions/s.'.freeze
27
+
28
+ def self.color!
29
+ @color = true
30
+ end
31
+
32
+ def self.no_color!
33
+ @color = false
34
+ end
35
+
36
+ def self.color?
37
+ @color ||= true
38
+ end
39
+
40
+ def initialize(io)
41
+ super io
42
+
43
+ @io = io
44
+ @summary = {}
45
+ @last_length = 0
46
+
47
+ SUMMARY_LABELS.keys.each { |key| @summary[key] = 0 }
48
+ end
49
+
50
+ def record(result)
51
+ super
52
+
53
+ code = result.result_code
54
+
55
+ @summary[code] += 1
56
+
57
+ summarize_clear
58
+
59
+ @io.print generate_output
60
+ end
61
+
62
+ def report
63
+ super
64
+
65
+ io.puts "\n\n"
66
+ io.puts statistics
67
+ io.puts aggregated_results
68
+ io.puts "\n\n"
69
+ end
70
+
71
+ def statistics
72
+ format(STATS_FORMAT,
73
+ total_time, count / total_time,
74
+ assertions / total_time)
75
+ end
76
+
77
+ def aggregated_results
78
+ filtered_results = results.sort_by { |result| result.skipped? ? 1 : 0 }
79
+
80
+ filtered_results.each_with_index.map do |result, idx|
81
+ color = result.skipped? ? :yellow : :red
82
+ text = format("\n%3d) %s", idx + 1, result)
83
+
84
+ self.class.color? ? colorize(color, text) : text
85
+ end.join + "\n"
86
+ end
87
+
88
+ def generate_output
89
+ list = []
90
+
91
+ SUMMARY_LABELS.each do |key, label|
92
+ value = @summary[key]
93
+
94
+ list.push format_string(key, label, value)
95
+ end
96
+
97
+ @last_format = list.join(' ')
98
+ @last_length = @last_format.length
99
+
100
+ @last_format + "\r"
101
+ end
102
+
103
+ def format_string(key, label, value)
104
+ str = "#{label} #{value}"
105
+
106
+ self.class.color? ? "[#{colorize_by_key(key, str)}]" : "[#{str}]"
107
+ end
108
+
109
+ def colorize_by_key(key, str)
110
+ code = CODE_TO_COLOR[key]
111
+
112
+ colorize(code, str)
113
+ end
114
+
115
+ def colorize(code, str)
116
+ "\e[#{COLOR_CODE[code]}m#{str}\e[0m"
117
+ end
118
+
119
+ def summarize_clear
120
+ @io.print ' ' * @last_length if @last_length
121
+ @io.print "\r"
122
+ @io.flush
123
+ end
124
+ end
125
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest-summarize
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Randy Carnahan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Reduces the output from the standard Minitest run.
14
+ email: syntruth@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - LICENSE
20
+ - README.md
21
+ - VERSION
22
+ - lib/minitest/summarize.rb
23
+ - lib/minitest/summarize_plugin.rb
24
+ - lib/minitest/summarize_reporter.rb
25
+ homepage: https://github.com/syntruth/minitest-summarize
26
+ licenses:
27
+ - MIT
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.5.1
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Minitest Summarize Reporter
49
+ test_files: []