├── .gitignore ├── Rakefile ├── lib ├── colorific │ └── version.rb └── colorific.rb ├── Gemfile ├── README.markdown ├── test ├── test_nothing.rb ├── test_fail.rb ├── test_error.rb ├── test_pass.rb └── test_skip.rb └── colorific.gemspec /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | .bundle 3 | Gemfile.lock 4 | pkg/* 5 | .rvmrc* -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler' 2 | Bundler::GemHelper.install_tasks 3 | -------------------------------------------------------------------------------- /lib/colorific/version.rb: -------------------------------------------------------------------------------- 1 | module Colorific 2 | VERSION = "1.0.2" 3 | end 4 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "http://rubygems.org" 2 | 3 | # Specify your gem's dependencies in colorific.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 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! -------------------------------------------------------------------------------- /test/test_nothing.rb: -------------------------------------------------------------------------------- 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 10 | -------------------------------------------------------------------------------- /test/test_fail.rb: -------------------------------------------------------------------------------- 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 24 | -------------------------------------------------------------------------------- /test/test_error.rb: -------------------------------------------------------------------------------- 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 24 | -------------------------------------------------------------------------------- /test/test_pass.rb: -------------------------------------------------------------------------------- 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 24 | -------------------------------------------------------------------------------- /test/test_skip.rb: -------------------------------------------------------------------------------- 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 24 | -------------------------------------------------------------------------------- /colorific.gemspec: -------------------------------------------------------------------------------- 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.8.0" 23 | s.add_dependency "ruby-progressbar", "~> 0.0.10" 24 | end 25 | -------------------------------------------------------------------------------- /lib/colorific.rb: -------------------------------------------------------------------------------- 1 | gem 'minitest' 2 | require "minitest/autorun" 3 | require 'progressbar' 4 | 5 | class MiniTest::Unit 6 | ANSI_COLOR_CODES = { :clear => "\e[0m", :red => "\e[31m", :green => "\e[32m", :yellow => "\e[33m" } 7 | TEST_COLORS = { "F" => :red, "E" => :red, "S" => :yellow, "." => :green } 8 | 9 | alias :original_puke :puke 10 | alias :original_run_suites :_run_suites 11 | alias :original_status :status 12 | 13 | def puke(klass, meth, e) 14 | r = original_puke(klass, meth, e) 15 | 16 | if report = @report.pop 17 | lines = report.split(/\n/) 18 | lines[0] = tint(r, lines[0]) 19 | @report << lines.join("\n") 20 | end 21 | 22 | return r 23 | end 24 | 25 | def _run_suites(suites, type) 26 | @colorful_test_count = suites.reduce(0) { |mem, suite| mem + suite.send("#{type}_methods").size } 27 | @finished_count = 0 28 | @progress_bar = ProgressBar.new(" #{test_count} tests", @colorful_test_count, output) 29 | original_run_suites(suites, type) 30 | end 31 | 32 | def status(io = self.output) 33 | with_color { original_status(io) } 34 | end 35 | 36 | def print(*a) 37 | if %w(. S F E).include?(a.join) 38 | set_color(a.join) 39 | increment 40 | else 41 | output.print(*a) 42 | end 43 | end 44 | 45 | protected 46 | def tint(status, msg) 47 | color_name = TEST_COLORS[status[0,1]] 48 | return msg unless color_name 49 | ANSI_COLOR_CODES[color_name] + msg + ANSI_COLOR_CODES[:clear] 50 | end 51 | 52 | def set_color(type) 53 | case type 54 | when '.' 55 | @state = :green unless @state == :yellow || @state == :red 56 | when "S" 57 | @state = :yellow unless @state == :red 58 | when "F", "E" 59 | @state = :red 60 | end 61 | end 62 | 63 | def state 64 | @state ||= :clear 65 | end 66 | 67 | def with_color 68 | output.print ANSI_COLOR_CODES[state] 69 | yield 70 | output.print "\e[0m" 71 | end 72 | 73 | def increment 74 | with_color do 75 | @finished_count += 1 76 | @progress_bar.instance_variable_set("@title", " #{@finished_count}/#{@colorful_test_count}") 77 | @progress_bar.inc 78 | end 79 | end 80 | end --------------------------------------------------------------------------------