colorific 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in colorific.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/colorific.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "colorific/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "colorific"
7
+ s.version = Colorific::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Carlos Brando"]
10
+ s.email = ["eduardobrando@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Run your tests (Minitest) with lots of color!}
13
+ s.description = %q{Run your tests (Minitest) with lots of color!}
14
+
15
+ s.rubyforge_project = "colorific"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency('minitest', '~> 2.0')
23
+ s.add_dependency('ruby-progressbar', '>= 0.0.9')
24
+ end
data/lib/colorific.rb ADDED
@@ -0,0 +1,85 @@
1
+ gem 'minitest'
2
+ require "minitest/autorun"
3
+ require 'progressbar'
4
+
5
+ module Colorific
6
+ COLORS = { :clear => 0, :red => 31, :green => 32, :yellow => 33 }
7
+ TEST_COLORS = { "F" => :red, "E" => :red, "S" => :yellow, "." => :green }
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
+ alias :original_puke :puke
22
+ alias :original_run_suites :_run_suites
23
+ alias :original_status :status
24
+
25
+ def puke(klass, meth, e)
26
+ r = original_puke(klass, meth, e)
27
+
28
+ report = @report.pop
29
+ lines = report.split(/\n/)
30
+ lines[0] = Colorific.colored(r, lines[0])
31
+ @report << lines.join("\n")
32
+ r
33
+ end
34
+
35
+ def _run_suites(suites, type)
36
+ @colorful_test_count = suites.reduce(0) { |mem, suite| mem + suite.send("#{type}_methods").size }
37
+ @finished_count = 0
38
+ @progress_bar = ProgressBar.new(" #{test_count} tests", @colorful_test_count, output)
39
+ original_run_suites(suites, type)
40
+ end
41
+
42
+ def status(io = self.output)
43
+ with_color { original_status(io) }
44
+ end
45
+
46
+ def print(*a)
47
+ case type = a.join
48
+ when '.'
49
+ increment
50
+ when 'S', 'F', 'E'
51
+ set_color(type)
52
+ increment
53
+ else
54
+ output.print(*a)
55
+ end
56
+ end
57
+
58
+ protected
59
+ def set_color(type)
60
+ case type
61
+ when "F", "E"
62
+ @state = :red
63
+ when "S"
64
+ @state = :yellow unless @state == :red
65
+ end
66
+ end
67
+
68
+ def state
69
+ @state ||= :green
70
+ end
71
+
72
+ def with_color
73
+ output.print Colorific[state]
74
+ yield
75
+ output.print "\e[0m"
76
+ end
77
+
78
+ def increment
79
+ with_color do
80
+ @finished_count += 1
81
+ @progress_bar.instance_variable_set("@title", " #{@finished_count}/#{@colorful_test_count}")
82
+ @progress_bar.inc
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,3 @@
1
+ module Colorific
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/../lib/colorific'
2
+
3
+ class ColorificErrorTest < MiniTest::Unit::TestCase
4
+ def test_1
5
+ sleep(0.5)
6
+ pass "Pass"
7
+ end
8
+
9
+ def test_2
10
+ sleep(0.5)
11
+ pass "Pass"
12
+ end
13
+
14
+ def test_3
15
+ sleep(0.5)
16
+ skip
17
+ end
18
+
19
+ def test_4
20
+ sleep(0.5)
21
+ raise
22
+ end
23
+ end
data/test/test_fail.rb ADDED
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/../lib/colorific'
2
+
3
+ class ColorificFailTest < MiniTest::Unit::TestCase
4
+ def test_1
5
+ sleep(0.5)
6
+ pass "Pass"
7
+ end
8
+
9
+ def test_2
10
+ sleep(0.5)
11
+ pass "Pass"
12
+ end
13
+
14
+ def test_3
15
+ sleep(0.5)
16
+ skip
17
+ end
18
+
19
+ def test_4
20
+ sleep(0.5)
21
+ flunk
22
+ end
23
+ end
data/test/test_pass.rb ADDED
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/../lib/colorific'
2
+
3
+ class ColorificPassTest < MiniTest::Unit::TestCase
4
+ def test_1
5
+ sleep(0.5)
6
+ pass "Pass"
7
+ end
8
+
9
+ def test_2
10
+ sleep(0.5)
11
+ pass "Pass"
12
+ end
13
+
14
+ def test_3
15
+ sleep(0.5)
16
+ pass "Pass"
17
+ end
18
+
19
+ def test_4
20
+ sleep(0.5)
21
+ pass "Pass"
22
+ end
23
+ end
data/test/test_skip.rb ADDED
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/../lib/colorific'
2
+
3
+ class ColorificSkipTest < MiniTest::Unit::TestCase
4
+ def test_1
5
+ sleep(0.5)
6
+ pass "Pass"
7
+ end
8
+
9
+ def test_2
10
+ sleep(0.5)
11
+ pass "Pass"
12
+ end
13
+
14
+ def test_3
15
+ sleep(0.5)
16
+ pass "Pass"
17
+ end
18
+
19
+ def test_4
20
+ sleep(0.5)
21
+ skip "Skip"
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: colorific
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Carlos Brando
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-02-18 00:00:00 -02:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: minitest
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: "2.0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-progressbar
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 0.0.9
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ description: Run your tests (Minitest) with lots of color!
39
+ email:
40
+ - eduardobrando@gmail.com
41
+ executables: []
42
+
43
+ extensions: []
44
+
45
+ extra_rdoc_files: []
46
+
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - Rakefile
51
+ - colorific.gemspec
52
+ - lib/colorific.rb
53
+ - lib/colorific/version.rb
54
+ - test/test_error.rb
55
+ - test/test_fail.rb
56
+ - test/test_pass.rb
57
+ - test/test_skip.rb
58
+ has_rdoc: true
59
+ homepage: ""
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options: []
64
+
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ requirements: []
80
+
81
+ rubyforge_project: colorific
82
+ rubygems_version: 1.5.2
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Run your tests (Minitest) with lots of color!
86
+ test_files:
87
+ - test/test_error.rb
88
+ - test/test_fail.rb
89
+ - test/test_pass.rb
90
+ - test/test_skip.rb