minitest-display 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +39 -1
- data/TODO +7 -0
- data/lib/minitest/display.rb +113 -18
- data/minitest-display.gemspec +5 -3
- data/test/test_minitest-display.rb +3 -2
- metadata +6 -4
data/README.rdoc
CHANGED
@@ -1,6 +1,44 @@
|
|
1
1
|
= minitest-display
|
2
2
|
|
3
|
-
|
3
|
+
MiniTest::Display is a module that monkey patches a lot of the MiniTest::Unit interals to allow for configurable display options.
|
4
|
+
You want color?! You want Suite name printouts?!?! You want fried eggs?! Too bad.
|
5
|
+
|
6
|
+
I was messing with leftright (https://github.com/jordi/leftright - which is awesome btw) and trying to get it to work well with 1.9 but its all tied up in Test::Unit.
|
7
|
+
MiniTest is much much simpler, and its patch points are easy to override and much less scary. Beyond that, MiniTest is also faster and has some neat benefits over test/unit (like benchmark assertions, etc). So, off we went.
|
8
|
+
|
9
|
+
The goal is to be as configurable as possible with some nice defaults. My problem with most test enhancers is that they monkey patch blindly with very little openness and room for configuration. MiniTest::Display should allow for an infinite number (evenutally) of test display enhancements.
|
10
|
+
|
11
|
+
Needless to say, it's a work in progress.
|
12
|
+
|
13
|
+
== Requirements
|
14
|
+
|
15
|
+
Requires Ruby 1.9 and the gem version of minitest >= 2.0.2
|
16
|
+
|
17
|
+
== Usage
|
18
|
+
|
19
|
+
Install minitest and minitest display:
|
20
|
+
|
21
|
+
gem install minitest minitest-display
|
22
|
+
|
23
|
+
In your test suite/test_helper, require and configure mini test/display:
|
24
|
+
|
25
|
+
require 'minitest/autorun'
|
26
|
+
require 'minitest/display'
|
27
|
+
|
28
|
+
MiniTest::Display.options = {
|
29
|
+
suite_names: true,
|
30
|
+
color: true,
|
31
|
+
print: {
|
32
|
+
success: "OK\n",
|
33
|
+
failure: "EPIC FAIL\n"
|
34
|
+
error: "ERRRRRRR\n"
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
That suite will look pretty funny.
|
39
|
+
|
40
|
+
For all current available options see the code:
|
41
|
+
https://github.com/quirkey/minitest-display/blob/master/lib/minitest/display.rb#L25
|
4
42
|
|
5
43
|
== Contributing to minitest-display
|
6
44
|
|
data/TODO
ADDED
data/lib/minitest/display.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'benchmark'
|
2
|
-
|
3
1
|
class Hash
|
4
2
|
unless method_defined?(:deep_merge!)
|
5
3
|
|
@@ -20,23 +18,50 @@ end
|
|
20
18
|
|
21
19
|
module MiniTest
|
22
20
|
module Display
|
23
|
-
VERSION = '0.0.
|
21
|
+
VERSION = '0.0.2'
|
22
|
+
|
24
23
|
class << self
|
25
24
|
def options
|
26
25
|
@options ||= {
|
27
26
|
suite_names: true,
|
28
|
-
suite_divider: "
|
27
|
+
suite_divider: " | ",
|
29
28
|
color: true,
|
29
|
+
wrap_at: 80,
|
30
30
|
print: {
|
31
31
|
success: '.',
|
32
32
|
failure: 'F',
|
33
33
|
error: 'E'
|
34
34
|
},
|
35
35
|
colors: {
|
36
|
-
clear:
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
clear: 0,
|
37
|
+
bold: 1,
|
38
|
+
italics: 3,
|
39
|
+
underline: 4,
|
40
|
+
inverse: 9,
|
41
|
+
strikethrough: 22,
|
42
|
+
bold_off: 23,
|
43
|
+
italics_off: 24,
|
44
|
+
underline_off: 27,
|
45
|
+
inverse_off: 29,
|
46
|
+
strikethrough_off: 30,
|
47
|
+
black: 30,
|
48
|
+
red: 31,
|
49
|
+
green: 32,
|
50
|
+
yellow: 33,
|
51
|
+
blue: 34,
|
52
|
+
magenta: 35,
|
53
|
+
cyan: 36,
|
54
|
+
white: 37,
|
55
|
+
default: 39,
|
56
|
+
bg_black: 40,
|
57
|
+
bg_red: 41,
|
58
|
+
bg_green: 42,
|
59
|
+
bg_yellow: 43,
|
60
|
+
bg_blue: 44,
|
61
|
+
bg_magenta: 45,
|
62
|
+
bg_cyan: 46,
|
63
|
+
bg_white: 47,
|
64
|
+
bg_default: 49,
|
40
65
|
|
41
66
|
suite: :clear,
|
42
67
|
success: :green,
|
@@ -51,19 +76,37 @@ module MiniTest
|
|
51
76
|
end
|
52
77
|
|
53
78
|
def color(string, color)
|
54
|
-
return string unless options[:color]
|
79
|
+
return string unless STDOUT.tty? && options[:color]
|
55
80
|
tint(color) + string + tint(:clear)
|
56
81
|
end
|
57
82
|
|
58
83
|
def tint(color)
|
59
|
-
|
84
|
+
case color
|
85
|
+
when Array
|
86
|
+
color.collect {|c| tint(c) }.join('')
|
87
|
+
when Symbol
|
60
88
|
if c = options[:colors][color]
|
61
89
|
tint(c)
|
62
90
|
end
|
63
91
|
else
|
64
|
-
color
|
92
|
+
"\e[#{color}m"
|
65
93
|
end
|
66
94
|
end
|
95
|
+
|
96
|
+
DONT_PRINT_CLASSES = %w{
|
97
|
+
ActionController::IntegrationTest
|
98
|
+
ActionController::TestCase
|
99
|
+
ActionMailer::TestCase
|
100
|
+
ActionView::TestCase
|
101
|
+
ActiveRecord::TestCase
|
102
|
+
ActiveSupport::TestCase
|
103
|
+
Test::Unit::TestCase
|
104
|
+
MiniTest::Unit::TestCase
|
105
|
+
MiniTest::Spec}
|
106
|
+
|
107
|
+
def printable_suite?(suite)
|
108
|
+
!DONT_PRINT_CLASSES.include?(suite.to_s)
|
109
|
+
end
|
67
110
|
end
|
68
111
|
|
69
112
|
end
|
@@ -71,25 +114,65 @@ end
|
|
71
114
|
|
72
115
|
class MiniTest::Unit
|
73
116
|
# Monkey Patchin!
|
117
|
+
def _run_anything(type)
|
118
|
+
suites = TestCase.send "#{type}_suites"
|
119
|
+
return if suites.empty?
|
120
|
+
|
121
|
+
start = Time.now
|
122
|
+
|
123
|
+
puts
|
124
|
+
puts "# Running #{type}s:"
|
125
|
+
puts
|
126
|
+
|
127
|
+
@test_count, @assertion_count = 0, 0
|
128
|
+
sync = output.respond_to? :"sync=" # stupid emacs
|
129
|
+
old_sync, output.sync = output.sync, true if sync
|
130
|
+
|
131
|
+
results = _run_suites suites, type
|
132
|
+
|
133
|
+
@test_count = results.inject(0) { |sum, (tc, _)| sum + tc }
|
134
|
+
@assertion_count = results.inject(0) { |sum, (_, ac)| sum + ac }
|
135
|
+
|
136
|
+
output.sync = old_sync if sync
|
137
|
+
|
138
|
+
t = Time.now - start
|
139
|
+
|
140
|
+
puts
|
141
|
+
puts
|
142
|
+
puts "Finished #{type}s in %.6fs, %.4f tests/s, %.4f assertions/s." %
|
143
|
+
[t, test_count / t, assertion_count / t]
|
144
|
+
|
145
|
+
report.each_with_index do |msg, i|
|
146
|
+
puts "\n%3d) %s" % [i + 1, msg]
|
147
|
+
end
|
148
|
+
|
149
|
+
puts
|
150
|
+
|
151
|
+
status
|
152
|
+
end
|
153
|
+
|
74
154
|
def _run_suite(suite, type)
|
75
|
-
|
76
|
-
if display.options[:suite_names] && printable_suite
|
77
|
-
|
155
|
+
suite_header = ""
|
156
|
+
if display.options[:suite_names] && display.printable_suite?(suite)
|
157
|
+
suite_header = suite.to_s
|
158
|
+
print display.color("\n#{suite_header}#{display.options[:suite_divider]}", :suite)
|
78
159
|
end
|
79
160
|
|
80
161
|
filter = options[:filter] || '/./'
|
81
162
|
filter = Regexp.new $1 if filter =~ /\/(.*)\//
|
82
163
|
|
164
|
+
wrap_at = display.options[:wrap_at] - suite_header.length
|
165
|
+
wrap_count = wrap_at
|
166
|
+
|
83
167
|
assertions = suite.send("#{type}_methods").grep(filter).map { |method|
|
84
168
|
inst = suite.new method
|
85
169
|
inst._assertions = 0
|
86
170
|
|
87
171
|
print "#{suite}##{method} = " if @verbose
|
88
172
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
}
|
173
|
+
@start_time = Time.now
|
174
|
+
result = inst.run self
|
175
|
+
time = Time.now - @start_time
|
93
176
|
|
94
177
|
print "%.2f s = " % time if @verbose
|
95
178
|
print case result
|
@@ -104,12 +187,24 @@ class MiniTest::Unit
|
|
104
187
|
end
|
105
188
|
puts if @verbose
|
106
189
|
|
190
|
+
wrap_count -= 1
|
191
|
+
if wrap_count == 0
|
192
|
+
print "\n#{' ' * suite_header.length}#{display.options[:suite_divider]}"
|
193
|
+
wrap_count = wrap_at
|
194
|
+
end
|
195
|
+
|
107
196
|
inst._assertions
|
108
197
|
}
|
109
198
|
|
110
199
|
return assertions.size, assertions.inject(0) { |sum, n| sum + n }
|
111
200
|
end
|
112
201
|
|
202
|
+
def status(io = self.output)
|
203
|
+
format = "%d tests, %d assertions, %d failures, %d errors, %d skips"
|
204
|
+
final_status = failures + errors > 0 ? :failure : :success
|
205
|
+
io.puts display.color(format % [test_count, assertion_count, failures, errors, skips], [:bold, final_status])
|
206
|
+
end
|
207
|
+
|
113
208
|
private
|
114
209
|
def display
|
115
210
|
::MiniTest::Display
|
data/minitest-display.gemspec
CHANGED
@@ -5,16 +5,17 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{minitest-display}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Aaron Quint"]
|
12
|
-
s.date = %q{2011-03-
|
12
|
+
s.date = %q{2011-03-27}
|
13
13
|
s.description = %q{Patches MiniTest to allow for an easily configurable output. For Ruby 1.9 :Datches MiniTest to allow for an easily configurable output. For Ruby 1.9 :D. Inspired by leftright, redgreen and other test output gems, with an emphasis on configuration and style}
|
14
14
|
s.email = %q{aaron@quirkey.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
17
|
-
"README.rdoc"
|
17
|
+
"README.rdoc",
|
18
|
+
"TODO"
|
18
19
|
]
|
19
20
|
s.files = [
|
20
21
|
".document",
|
@@ -23,6 +24,7 @@ Gem::Specification.new do |s|
|
|
23
24
|
"LICENSE.txt",
|
24
25
|
"README.rdoc",
|
25
26
|
"Rakefile",
|
27
|
+
"TODO",
|
26
28
|
"lib/minitest/display.rb",
|
27
29
|
"minitest-display.gemspec",
|
28
30
|
"test/helper.rb",
|
@@ -64,8 +64,8 @@ class TestMinitestDisplay < MiniTest::Unit::TestCase
|
|
64
64
|
end
|
65
65
|
TESTCASE
|
66
66
|
|
67
|
-
assert_output(/^BasicTest
|
68
|
-
assert_output(/AnotherBasicTest
|
67
|
+
assert_output(/^BasicTest |/)
|
68
|
+
assert_output(/AnotherBasicTest |/)
|
69
69
|
assert_output(/F/)
|
70
70
|
assert_output(/\./)
|
71
71
|
end
|
@@ -73,6 +73,7 @@ class TestMinitestDisplay < MiniTest::Unit::TestCase
|
|
73
73
|
def test_runs_basic_test_suite_with_different_printing
|
74
74
|
capture_test_output <<-TESTCASE
|
75
75
|
MiniTest::Display.options = {
|
76
|
+
suite_divider: ' // ',
|
76
77
|
print: {
|
77
78
|
success: 'PASS'
|
78
79
|
}
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Aaron Quint
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-03-
|
17
|
+
date: 2011-03-27 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -86,6 +86,7 @@ extensions: []
|
|
86
86
|
extra_rdoc_files:
|
87
87
|
- LICENSE.txt
|
88
88
|
- README.rdoc
|
89
|
+
- TODO
|
89
90
|
files:
|
90
91
|
- .document
|
91
92
|
- Gemfile
|
@@ -93,6 +94,7 @@ files:
|
|
93
94
|
- LICENSE.txt
|
94
95
|
- README.rdoc
|
95
96
|
- Rakefile
|
97
|
+
- TODO
|
96
98
|
- lib/minitest/display.rb
|
97
99
|
- minitest-display.gemspec
|
98
100
|
- test/helper.rb
|
@@ -111,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
113
|
requirements:
|
112
114
|
- - ">="
|
113
115
|
- !ruby/object:Gem::Version
|
114
|
-
hash:
|
116
|
+
hash: 2533676702413746939
|
115
117
|
segments:
|
116
118
|
- 0
|
117
119
|
version: "0"
|