minitest-ansi 0.1.0

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/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Zeh Rizzatti
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # MiniTest::ANSI
2
+
3
+ Colorize your minitest output using ANSI colors.
4
+
5
+ ![Screenshot](https://github.com/zehrizzatti/minitest-ansi/raw/master/images/screenshot.png)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'minitest-ansi'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install minitest-ansi
20
+
21
+ ## Usage
22
+
23
+ require 'minitest/ansi'
24
+ MiniTest::ANSI.use!
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
@@ -0,0 +1,50 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'minitest/ansi/version'
4
+ require 'delegate'
5
+ require 'ansi'
6
+
7
+ module MiniTest
8
+ class ANSI < ::SimpleDelegator
9
+ include ANSIVersion
10
+
11
+ TEST_REGEX = /\d+(\)| tests)/
12
+ MAPPING = [
13
+ [/[1-9]\d*\)? (F|f)ailures?/, :yellow],
14
+ [/[1-9]\d*\)? (E|e)rrors?/, :red],
15
+ [/[1-9]\d*\)? (S|s)kip(ped|s)/, :cyan],
16
+ ]
17
+
18
+ def initialize(stream=MiniTest::Unit.output)
19
+ super
20
+ end
21
+
22
+ def print(*args)
23
+ char = args.first
24
+ color = case char
25
+ when '.'; then :green
26
+ when 'F'; then :yellow
27
+ when 'E'; then :red
28
+ when 'S'; then :cyan
29
+ else
30
+ __getobj__.print(*args)
31
+ return
32
+ end
33
+ __getobj__.print(::ANSI[color] + char + ::ANSI[:clear])
34
+ end
35
+
36
+ def puts(*args)
37
+ str = args.first
38
+ if str && (str =~ TEST_REGEX) != nil
39
+ MAPPING.each do |regex, color|
40
+ str.gsub!(regex, ::ANSI[color] + "\\0" + ::ANSI[:clear])
41
+ end
42
+ end
43
+ __getobj__.puts(*args)
44
+ end
45
+
46
+ def self.use!
47
+ MiniTest::Unit.output = new
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,7 @@
1
+ # encoding: UTF-8
2
+
3
+ module MiniTest
4
+ module ANSIVersion
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,97 @@
1
+ require 'spec_helper'
2
+ require 'minitest/ansi'
3
+ require 'stringio'
4
+
5
+ module MiniTest
6
+ describe ANSI do
7
+ before { @output = MiniTest::Unit.output }
8
+ after { MiniTest::Unit.output = @output }
9
+
10
+ subject { ANSI }
11
+
12
+ it 'has a version number' do
13
+ subject::VERSION.must_equal ANSIVersion::VERSION
14
+ end
15
+
16
+ it 'changes minitest output with use!' do
17
+ output = subject.use!
18
+ output.object_id.must_be_same_as MiniTest::Unit.output.object_id
19
+ output.must_respond_to :print
20
+ output.must_respond_to :puts
21
+ end
22
+
23
+ describe 'IO' do
24
+ subject { ANSI.new(StringIO.new) }
25
+
26
+ def assert_io(method, input, output)
27
+ subject.public_send method, input
28
+ subject.rewind
29
+ subject.read.must_equal output
30
+ end
31
+
32
+ def assert_print(input, output)
33
+ assert_io(:print, input, output)
34
+ end
35
+
36
+ def assert_puts(input, output)
37
+ assert_io(:puts, input, output + "\n")
38
+ end
39
+
40
+ describe 'printing chars' do
41
+ it 'prints . in green' do
42
+ assert_print '.', "\e[32m.\e[0m"
43
+ end
44
+
45
+ it 'prints F in yellow' do
46
+ assert_print 'F', "\e[33mF\e[0m"
47
+ end
48
+
49
+ it 'prints E in red' do
50
+ assert_print 'E', "\e[31mE\e[0m"
51
+ end
52
+
53
+ it 'prints S in cyan' do
54
+ assert_print 'S', "\e[36mS\e[0m"
55
+ end
56
+ end
57
+
58
+ describe 'describing each problem' do
59
+ it 'prints failures in yellow' do
60
+ assert_puts '1) Failure', "\e[33m1) Failure\e[0m"
61
+ end
62
+
63
+ it 'prints errors in red' do
64
+ assert_puts ' 2) Error', " \e[31m2) Error\e[0m"
65
+ end
66
+
67
+ it 'prints skippeds in cyan' do
68
+ assert_puts '60) Skipped', "\e[36m60) Skipped\e[0m"
69
+ end
70
+ end
71
+
72
+ describe 'showing the status line' do
73
+ it 'prints failures in yellow' do
74
+ assert_puts '3 tests, 1 failures', "3 tests, \e[33m1 failures\e[0m"
75
+ end
76
+
77
+ it 'print error in red' do
78
+ assert_puts '10 tests, 3 errors', "10 tests, \e[31m3 errors\e[0m"
79
+ end
80
+
81
+ it 'prints skips in cyan' do
82
+ assert_puts '5 tests, 2 skips', "5 tests, \e[36m2 skips\e[0m"
83
+ end
84
+
85
+ it 'does not colorize when there are no problems' do
86
+ input = '99 tests, 0 failures, 0 errors, 0 skips'
87
+ subject.puts input
88
+ subject.rewind
89
+ output = subject.read
90
+ output.wont_match "\e[33m"
91
+ output.wont_match "\e[36m"
92
+ output.wont_match "\e[31m"
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,2 @@
1
+ require 'bundler/setup'
2
+ require 'minitest/autorun'
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest-ansi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Zeh Rizzatti
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ansi
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.4.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.4.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: minitest
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 4.3.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 4.3.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Colorizes minitest output with ANSI codes
63
+ email:
64
+ - zehrizzatti@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - lib/minitest/ansi/version.rb
70
+ - lib/minitest/ansi.rb
71
+ - spec/lib/minitest/ansi_spec.rb
72
+ - spec/spec_helper.rb
73
+ - README.md
74
+ - LICENSE.txt
75
+ homepage: https://github.com/zehrizzatti/minitest-ansi
76
+ licenses: []
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 1.8.23
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Colors for minitest output
99
+ test_files:
100
+ - spec/lib/minitest/ansi_spec.rb
101
+ - spec/spec_helper.rb