minitest-colorize 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - ree
5
+ - jruby
6
+ - rbx
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ 0.0.4 [Mon Jul 18 2011]
2
+
3
+ * Colorize output only if output is a tty
4
+
1
5
  0.0.3 [Mon Jun 27 2011]
2
6
 
3
7
  * Show failing tests instantly
@@ -14,8 +14,13 @@ module MiniTest
14
14
  def print(string = nil)
15
15
  return stream.print if string.nil?
16
16
 
17
- if color = colors[string]
18
- stream.print tint(color, string)
17
+ case string
18
+ when 'E', 'F'
19
+ stream.print red(string)
20
+ when 'S'
21
+ stream.print yellow(string)
22
+ when '.'
23
+ stream.print green(string)
19
24
  else
20
25
  stream.print string
21
26
  end
@@ -32,17 +37,13 @@ module MiniTest
32
37
  return stream.puts if string.nil?
33
38
 
34
39
  if string =~ /(\d+) tests, (\d+) assertions, (\d+) failures, (\d+) errors, (\d+) skips/
35
- color = if $3 != '0'
36
- colors['F']
37
- elsif $4 != '0'
38
- colors['E']
39
- elsif $5 != '0'
40
- colors['S']
41
- else
42
- colors['.']
43
- end
44
-
45
- stream.puts tint(color, string)
40
+ if $3 != '0' || $4 != '0'
41
+ stream.puts red(string)
42
+ elsif $5 != '0'
43
+ stream.puts yellow(string)
44
+ else
45
+ stream.puts green(string)
46
+ end
46
47
  else
47
48
  stream.puts string
48
49
  end
@@ -54,12 +55,28 @@ module MiniTest
54
55
 
55
56
  protected
56
57
 
58
+ def color_enabled?
59
+ stream.tty?
60
+ end
61
+
57
62
  def tint(color, string)
58
- "\e[#{color}m#{string}\e[0m"
63
+ if color_enabled?
64
+ "\e[#{color}m#{string}\e[0m"
65
+ else
66
+ string
67
+ end
68
+ end
69
+
70
+ def red(string)
71
+ tint(31, string)
72
+ end
73
+
74
+ def green(string)
75
+ tint(32, string)
59
76
  end
60
77
 
61
- def colors
62
- { "F" => 31, "E" => 31, "S" => 33, "." => 32 }
78
+ def yellow(string)
79
+ tint(33, string)
63
80
  end
64
81
 
65
82
  def report
@@ -1,5 +1,5 @@
1
1
  module MiniTest
2
2
  class Colorize
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -18,4 +18,5 @@ Gem::Specification.new do |s|
18
18
 
19
19
  s.add_dependency 'minitest', '~> 2.0'
20
20
  s.add_development_dependency 'rake', '>= 0.8.7'
21
+ s.add_development_dependency 'mocha', '>= 0.9.12'
21
22
  end
@@ -1,6 +1,10 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class MiniTest::ColorizeTest < MiniTest::Unit::TestCase
4
+ def setup
5
+ MiniTest::Colorize.any_instance.stubs(:color_enabled?).returns(true)
6
+ end
7
+
4
8
  def test_print_fail
5
9
  assert_output "\e[31mF\e[0m" do
6
10
  colorize = MiniTest::Colorize.new
@@ -37,7 +41,10 @@ class MiniTest::ColorizeTest < MiniTest::Unit::TestCase
37
41
  end
38
42
 
39
43
  def test_print_without_arguments
40
- assert_output "" do
44
+ # ruby 1.9 prints nothing and ruby 1.8 prints 'nil'
45
+ output = RUBY_VERSION >= '1.9' ? '' : 'nil'
46
+
47
+ assert_output output do
41
48
  colorize = MiniTest::Colorize.new
42
49
  colorize.print
43
50
  end
@@ -1,4 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
+ require 'mocha'
3
4
  require 'minitest/autorun'
4
- require 'minitest-colorize'
5
+ require 'minitest/colorize'
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.3
5
+ version: 0.0.4
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-27 00:00:00 -03:00
13
+ date: 2011-07-18 00:00:00 -03:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -35,6 +35,17 @@ dependencies:
35
35
  version: 0.8.7
36
36
  type: :development
37
37
  version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: mocha
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.9.12
47
+ type: :development
48
+ version_requirements: *id003
38
49
  description: Colorize MiniTest output and show failing tests instantly
39
50
  email:
40
51
  - gabriel.sobrinho@gmail.com
@@ -46,6 +57,7 @@ extra_rdoc_files: []
46
57
 
47
58
  files:
48
59
  - .gitignore
60
+ - .travis.yml
49
61
  - CHANGELOG
50
62
  - Gemfile
51
63
  - README.markdown