colorific 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/README.markdown ADDED
@@ -0,0 +1 @@
1
+ If you're using Ruby 1.9 add `gem 'colorific', :group => :test` in your Gemfile and watch an explosion of colors in your tests!
data/lib/colorific.rb CHANGED
@@ -2,22 +2,10 @@ gem 'minitest'
2
2
  require "minitest/autorun"
3
3
  require 'progressbar'
4
4
 
5
- module Colorific
6
- COLORS = { :clear => 0, :red => 31, :green => 32, :yellow => 33 }
5
+ class MiniTest::Unit
6
+ ANSI_COLOR_CODES = { :clear => "\e[0m", :red => "\e[31m", :green => "\e[32m", :yellow => "\e[33m" }
7
7
  TEST_COLORS = { "F" => :red, "E" => :red, "S" => :yellow, "." => :green }
8
8
 
9
- def self.[](color_name)
10
- "\e[#{COLORS[color_name.to_sym]}m"
11
- end
12
-
13
- def self.colored(status, msg)
14
- color_name = TEST_COLORS[status[0,1]]
15
- return msg unless color_name
16
- Colorific[color_name] + msg + Colorific[:clear]
17
- end
18
- end
19
-
20
- class MiniTest::Unit
21
9
  alias :original_puke :puke
22
10
  alias :original_run_suites :_run_suites
23
11
  alias :original_status :status
@@ -27,7 +15,7 @@ class MiniTest::Unit
27
15
 
28
16
  report = @report.pop
29
17
  lines = report.split(/\n/)
30
- lines[0] = Colorific.colored(r, lines[0])
18
+ lines[0] = tint(r, lines[0])
31
19
  @report << lines.join("\n")
32
20
  r
33
21
  end
@@ -44,11 +32,8 @@ class MiniTest::Unit
44
32
  end
45
33
 
46
34
  def print(*a)
47
- case type = a.join
48
- when '.'
49
- increment
50
- when 'S', 'F', 'E'
51
- set_color(type)
35
+ if %w(. S F E).include?(a.join)
36
+ set_color(a.join)
52
37
  increment
53
38
  else
54
39
  output.print(*a)
@@ -56,21 +41,29 @@ class MiniTest::Unit
56
41
  end
57
42
 
58
43
  protected
44
+ def tint(status, msg)
45
+ color_name = TEST_COLORS[status[0,1]]
46
+ return msg unless color_name
47
+ ANSI_COLOR_CODES[color_name] + msg + ANSI_COLOR_CODES[:clear]
48
+ end
49
+
59
50
  def set_color(type)
60
51
  case type
61
- when "F", "E"
62
- @state = :red
52
+ when '.'
53
+ @state = :green unless @state == :yellow || @state == :red
63
54
  when "S"
64
55
  @state = :yellow unless @state == :red
56
+ when "F", "E"
57
+ @state = :red
65
58
  end
66
59
  end
67
60
 
68
61
  def state
69
- @state ||= :green
62
+ @state ||= :clear
70
63
  end
71
64
 
72
65
  def with_color
73
- output.print Colorific[state]
66
+ output.print ANSI_COLOR_CODES[state]
74
67
  yield
75
68
  output.print "\e[0m"
76
69
  end
@@ -1,3 +1,3 @@
1
1
  module Colorific
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + '/../lib/colorific'
2
+
3
+ class ColorificPassTest < MiniTest::Unit::TestCase
4
+
5
+ def do_nothing
6
+
7
+ end
8
+
9
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: colorific
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Carlos Brando
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-18 00:00:00 -02:00
13
+ date: 2011-02-19 00:00:00 -02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -47,12 +47,14 @@ extra_rdoc_files: []
47
47
  files:
48
48
  - .gitignore
49
49
  - Gemfile
50
+ - README.markdown
50
51
  - Rakefile
51
52
  - colorific.gemspec
52
53
  - lib/colorific.rb
53
54
  - lib/colorific/version.rb
54
55
  - test/test_error.rb
55
56
  - test/test_fail.rb
57
+ - test/test_nothing.rb
56
58
  - test/test_pass.rb
57
59
  - test/test_skip.rb
58
60
  has_rdoc: true
@@ -86,5 +88,6 @@ summary: Run your tests (Minitest) with lots of color!
86
88
  test_files:
87
89
  - test/test_error.rb
88
90
  - test/test_fail.rb
91
+ - test/test_nothing.rb
89
92
  - test/test_pass.rb
90
93
  - test/test_skip.rb