minitest-colorize 0.0.1 → 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.
- data/lib/minitest/colorize.rb +34 -9
- data/lib/minitest/colorize/version.rb +1 -1
- data/test/minitest_colorize_test.rb +54 -5
- metadata +2 -2
data/lib/minitest/colorize.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "minitest/colorize/version"
|
2
|
+
require "minitest/unit"
|
2
3
|
|
3
4
|
module MiniTest
|
4
5
|
class Colorize
|
@@ -8,25 +9,49 @@ module MiniTest
|
|
8
9
|
self.io = io
|
9
10
|
end
|
10
11
|
|
11
|
-
def print(
|
12
|
-
|
13
|
-
|
12
|
+
def print(string = nil)
|
13
|
+
return io.print if string.nil?
|
14
|
+
|
15
|
+
if color = colors[string]
|
16
|
+
io.print tint(color, string)
|
14
17
|
else
|
15
|
-
io.print
|
18
|
+
io.print string
|
16
19
|
end
|
17
20
|
end
|
18
21
|
|
19
|
-
def
|
20
|
-
|
21
|
-
end
|
22
|
+
def puts(string = nil)
|
23
|
+
return io.puts if string.nil?
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
+
if string =~ /(\d+) tests, (\d+) assertions, (\d+) failures, (\d+) errors, (\d+) skips/
|
26
|
+
color = if $3 != '0'
|
27
|
+
colors['F']
|
28
|
+
elsif $4 != '0'
|
29
|
+
colors['E']
|
30
|
+
elsif $5 != '0'
|
31
|
+
colors['S']
|
32
|
+
else
|
33
|
+
colors['.']
|
34
|
+
end
|
35
|
+
|
36
|
+
io.puts tint(color, string)
|
37
|
+
else
|
38
|
+
io.puts string
|
39
|
+
end
|
25
40
|
end
|
26
41
|
|
27
42
|
def method_missing(method, *args, &block)
|
28
43
|
io.send(method, *args, &block)
|
29
44
|
end
|
45
|
+
|
46
|
+
protected
|
47
|
+
|
48
|
+
def tint(color, string)
|
49
|
+
"\e[#{color}m#{string}\e[0m"
|
50
|
+
end
|
51
|
+
|
52
|
+
def colors
|
53
|
+
{ "F" => 31, "E" => 31, "S" => 33, "." => 32 }
|
54
|
+
end
|
30
55
|
end
|
31
56
|
end
|
32
57
|
|
@@ -1,38 +1,87 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class MiniTest::ColorizeTest < MiniTest::Unit::TestCase
|
4
|
-
def
|
4
|
+
def test_print_fail
|
5
5
|
assert_output "\e[31mF\e[0m" do
|
6
6
|
colorize = MiniTest::Colorize.new($stdout)
|
7
7
|
colorize.print 'F'
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
11
|
+
def test_print_error
|
12
12
|
assert_output "\e[31mE\e[0m" do
|
13
13
|
colorize = MiniTest::Colorize.new($stdout)
|
14
14
|
colorize.print 'E'
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
18
|
+
def test_print_skip
|
19
19
|
assert_output "\e[33mS\e[0m" do
|
20
20
|
colorize = MiniTest::Colorize.new($stdout)
|
21
21
|
colorize.print 'S'
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
25
|
+
def test_print_success
|
26
26
|
assert_output "\e[32m.\e[0m" do
|
27
27
|
colorize = MiniTest::Colorize.new($stdout)
|
28
28
|
colorize.print '.'
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
32
|
+
def test_print
|
33
33
|
assert_output "colorize" do
|
34
34
|
colorize = MiniTest::Colorize.new($stdout)
|
35
35
|
colorize.print 'colorize'
|
36
36
|
end
|
37
37
|
end
|
38
|
+
|
39
|
+
def test_print_without_arguments
|
40
|
+
assert_output '' do
|
41
|
+
colorize = MiniTest::Colorize.new($stdout)
|
42
|
+
colorize.print
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_puts_fail
|
47
|
+
assert_output "\e[31m12 tests, 12 assertions, 4 failures, 0 errors, 0 skips\e[0m\n" do
|
48
|
+
colorize = MiniTest::Colorize.new($stdout)
|
49
|
+
colorize.puts '12 tests, 12 assertions, 4 failures, 0 errors, 0 skips'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_puts_error
|
54
|
+
assert_output "\e[31m12 tests, 12 assertions, 0 failures, 4 errors, 0 skips\e[0m\n" do
|
55
|
+
colorize = MiniTest::Colorize.new($stdout)
|
56
|
+
colorize.puts '12 tests, 12 assertions, 0 failures, 4 errors, 0 skips'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_puts_skip
|
61
|
+
assert_output "\e[33m12 tests, 12 assertions, 0 failures, 0 errors, 4 skips\e[0m\n" do
|
62
|
+
colorize = MiniTest::Colorize.new($stdout)
|
63
|
+
colorize.puts '12 tests, 12 assertions, 0 failures, 0 errors, 4 skips'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_puts_success
|
68
|
+
assert_output "\e[32m12 tests, 12 assertions, 0 failures, 0 errors, 0 skips\e[0m\n" do
|
69
|
+
colorize = MiniTest::Colorize.new($stdout)
|
70
|
+
colorize.puts '12 tests, 12 assertions, 0 failures, 0 errors, 0 skips'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_puts
|
75
|
+
assert_output "colorize\n" do
|
76
|
+
colorize = MiniTest::Colorize.new($stdout)
|
77
|
+
colorize.puts 'colorize'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_puts_without_arguments
|
82
|
+
assert_output "\n" do
|
83
|
+
colorize = MiniTest::Colorize.new($stdout)
|
84
|
+
colorize.puts
|
85
|
+
end
|
86
|
+
end
|
38
87
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: minitest-colorize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Gabriel Sobrinho
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-
|
13
|
+
date: 2011-06-25 00:00:00 -03:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|