minitest-display 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "bundler", "~> 1.0.0"
5
+ gem "jeweler", "~> 1.5.2"
6
+ gem "minitest", "2.0.2"
7
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,18 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.2)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ minitest (2.0.2)
10
+ rake (0.8.7)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ bundler (~> 1.0.0)
17
+ jeweler (~> 1.5.2)
18
+ minitest (= 2.0.2)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Aaron Quint
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = minitest-display
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to minitest-display
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Aaron Quint. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require File.join(File.dirname(__FILE__), 'lib', 'minitest', 'display')
13
+ require 'jeweler'
14
+ Jeweler::Tasks.new do |gem|
15
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
16
+ gem.name = "minitest-display"
17
+ gem.version = MiniTest::Display::VERSION
18
+ gem.homepage = "http://github.com/quirkey/minitest-display"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Patches MiniTest to allow for an easily configurable output. For Ruby 1.9 :D}
21
+ gem.description = %Q{Patches MiniTest to allow for an easily configurable output. For Ruby 1.9 :Datches MiniTest to allow for an easily configurable output. For Ruby 1.9 :D. Inspired by leftright, redgreen and other test output gems, with an emphasis on configuration and style}
22
+ gem.email = "aaron@quirkey.com"
23
+ gem.authors = ["Aaron Quint"]
24
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
25
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
26
+ gem.add_runtime_dependency 'minitest', '~> 2.0.2'
27
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
28
+ end
29
+ Jeweler::RubygemsDotOrgTasks.new
30
+
31
+ require 'rake/testtask'
32
+ Rake::TestTask.new(:test) do |test|
33
+ test.libs << 'lib' << 'test'
34
+ test.pattern = 'test/**/test_*.rb'
35
+ test.verbose = true
36
+ end
37
+
38
+ task :default => :test
39
+
40
+ require 'rake/rdoctask'
41
+ Rake::RDocTask.new do |rdoc|
42
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
43
+
44
+ rdoc.rdoc_dir = 'rdoc'
45
+ rdoc.title = "minitest-display #{version}"
46
+ rdoc.rdoc_files.include('README*')
47
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
+ end
@@ -0,0 +1,117 @@
1
+ require 'benchmark'
2
+
3
+ class Hash
4
+ unless method_defined?(:deep_merge!)
5
+
6
+ def deep_merge!(other_hash)
7
+ other_hash.each_pair do |k,v|
8
+ tv = self[k]
9
+ self[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_merge(v) : v
10
+ end
11
+ self
12
+ end
13
+
14
+ def deep_merge(other_hash)
15
+ dup.deep_merge!(other_hash)
16
+ end
17
+
18
+ end
19
+ end
20
+
21
+ module MiniTest
22
+ module Display
23
+ VERSION = '0.0.1'
24
+ class << self
25
+ def options
26
+ @options ||= {
27
+ suite_names: true,
28
+ suite_divider: " // ",
29
+ color: true,
30
+ print: {
31
+ success: '.',
32
+ failure: 'F',
33
+ error: 'E'
34
+ },
35
+ colors: {
36
+ clear: "\e[0m",
37
+ red: "\e[31m",
38
+ green:"\e[32m",
39
+ yellow: "\e[33m",
40
+
41
+ suite: :clear,
42
+ success: :green,
43
+ failure: :red,
44
+ error: :red
45
+ }
46
+ }
47
+ end
48
+
49
+ def options=(new_options)
50
+ self.options.deep_merge!(new_options)
51
+ end
52
+
53
+ def color(string, color)
54
+ return string unless options[:color]
55
+ tint(color) + string + tint(:clear)
56
+ end
57
+
58
+ def tint(color)
59
+ if color.is_a?(Symbol)
60
+ if c = options[:colors][color]
61
+ tint(c)
62
+ end
63
+ else
64
+ color
65
+ end
66
+ end
67
+ end
68
+
69
+ end
70
+ end
71
+
72
+ class MiniTest::Unit
73
+ # Monkey Patchin!
74
+ def _run_suite(suite, type)
75
+ printable_suite = suite.superclass == MiniTest::Unit::TestCase && suite != MiniTest::Spec
76
+ if display.options[:suite_names] && printable_suite
77
+ print display.color("\n#{suite}#{display.options[:suite_divider]}", :suite)
78
+ end
79
+
80
+ filter = options[:filter] || '/./'
81
+ filter = Regexp.new $1 if filter =~ /\/(.*)\//
82
+
83
+ assertions = suite.send("#{type}_methods").grep(filter).map { |method|
84
+ inst = suite.new method
85
+ inst._assertions = 0
86
+
87
+ print "#{suite}##{method} = " if @verbose
88
+
89
+ result = nil
90
+ time = Benchmark.realtime {
91
+ result = inst.run self
92
+ }
93
+
94
+ print "%.2f s = " % time if @verbose
95
+ print case result
96
+ when "."
97
+ display.color(display.options[:print][:success], :success)
98
+ when "F"
99
+ display.color(display.options[:print][:failure], :failure)
100
+ when "E"
101
+ display.color(display.options[:print][:error], :error)
102
+ else
103
+ result
104
+ end
105
+ puts if @verbose
106
+
107
+ inst._assertions
108
+ }
109
+
110
+ return assertions.size, assertions.inject(0) { |sum, n| sum + n }
111
+ end
112
+
113
+ private
114
+ def display
115
+ ::MiniTest::Display
116
+ end
117
+ end
@@ -0,0 +1,63 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{minitest-display}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Aaron Quint"]
12
+ s.date = %q{2011-03-25}
13
+ s.description = %q{Patches MiniTest to allow for an easily configurable output. For Ruby 1.9 :Datches MiniTest to allow for an easily configurable output. For Ruby 1.9 :D. Inspired by leftright, redgreen and other test output gems, with an emphasis on configuration and style}
14
+ s.email = %q{aaron@quirkey.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "lib/minitest/display.rb",
27
+ "minitest-display.gemspec",
28
+ "test/helper.rb",
29
+ "test/test_minitest-display.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/quirkey/minitest-display}
32
+ s.licenses = ["MIT"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.7}
35
+ s.summary = %q{Patches MiniTest to allow for an easily configurable output. For Ruby 1.9 :D}
36
+ s.test_files = [
37
+ "test/helper.rb",
38
+ "test/test_minitest-display.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
47
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
48
+ s.add_development_dependency(%q<minitest>, ["= 2.0.2"])
49
+ s.add_runtime_dependency(%q<minitest>, ["~> 2.0.2"])
50
+ else
51
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
52
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
53
+ s.add_dependency(%q<minitest>, ["= 2.0.2"])
54
+ s.add_dependency(%q<minitest>, ["~> 2.0.2"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
59
+ s.add_dependency(%q<minitest>, ["= 2.0.2"])
60
+ s.add_dependency(%q<minitest>, ["~> 2.0.2"])
61
+ end
62
+ end
63
+
data/test/helper.rb ADDED
@@ -0,0 +1,62 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'minitest/autorun'
11
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
12
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
13
+ require 'minitest/display'
14
+ $print_runs = ENV['DEBUG']
15
+
16
+ class MiniTest::Unit::TestCase
17
+ attr_reader :suite_output
18
+
19
+ def capture_test_output(testcase_str)
20
+ base_dir = File.expand_path(File.dirname(__FILE__))
21
+ lib_dir = File.expand_path(File.join(base_dir, '..', 'lib'))
22
+ tmpdir = File.join(base_dir, '..', "tmp")
23
+ FileUtils.mkdir_p(tmpdir)
24
+ tmpfilename = "#{tmpdir}/fake_test_suite.rb"
25
+ header = %{
26
+ require 'minitest/autorun'
27
+ require '#{lib_dir}/minitest/display'
28
+ }
29
+
30
+ testcase_str = header + "\n" + testcase_str
31
+ File.unlink(tmpfilename) if File.readable?(tmpfilename)
32
+ File.open(tmpfilename, 'w') {|f| f << testcase_str }
33
+ cmd = %[`which ruby` #{tmpfilename} 2>&1]
34
+
35
+ @suite_output = %x[#{cmd}]
36
+ if $print_runs
37
+ puts "-------"
38
+ puts @suite_output
39
+ puts "-------"
40
+ end
41
+ end
42
+
43
+ def assert_output(duck)
44
+ if duck.is_a? Regexp
45
+ assert_match duck, strip_color(suite_output)
46
+ else
47
+ assert strip_color(suite_output).include?(duck.to_s)
48
+ end
49
+ end
50
+
51
+ def assert_no_output(duck)
52
+ if duck.is_a? Regexp
53
+ assert_no_match duck, strip_color(suite_output)
54
+ else
55
+ assert ! strip_color(suite_output).include?(duck.to_s)
56
+ end
57
+ end
58
+
59
+ def strip_color(string)
60
+ string.gsub(/\e\[(?:[34][0-7]|[0-9])?m/, '') # thanks again term/ansicolor
61
+ end
62
+ end
@@ -0,0 +1,100 @@
1
+ require 'helper'
2
+
3
+ class TestMinitestDisplay < MiniTest::Unit::TestCase
4
+
5
+ def test_runs_basic_test_with_default_settings
6
+ capture_test_output <<-TESTCASE
7
+ class BasicTest < MiniTest::Unit::TestCase
8
+
9
+ def test_truth
10
+ assert true
11
+ end
12
+
13
+ def test_equality
14
+ assert_equal 'test', 'test'
15
+ end
16
+ end
17
+ TESTCASE
18
+
19
+ assert_output(/BasicTest/)
20
+ assert_output(/\.\./)
21
+ end
22
+
23
+ def test_runs_basic_test_with_failures
24
+ capture_test_output <<-TESTCASE
25
+ class BasicTest < MiniTest::Unit::TestCase
26
+
27
+ def test_truth
28
+ assert false
29
+ end
30
+
31
+ def test_equality
32
+ assert_equal 'test', 'test'
33
+ end
34
+ end
35
+ TESTCASE
36
+
37
+ assert_output(/BasicTest/)
38
+ assert_output(/F/)
39
+ assert_output(/\./)
40
+ end
41
+
42
+ def test_runs_basic_test_with_multiple_suites
43
+ capture_test_output <<-TESTCASE
44
+ class BasicTest < MiniTest::Unit::TestCase
45
+
46
+ def test_truth
47
+ assert false
48
+ end
49
+
50
+ def test_equality
51
+ assert_equal 'test', 'test'
52
+ end
53
+ end
54
+
55
+ class AnotherBasicTest < MiniTest::Unit::TestCase
56
+
57
+ def test_truth
58
+ assert false
59
+ end
60
+
61
+ def test_equality
62
+ assert_equal 'test', 'test'
63
+ end
64
+ end
65
+ TESTCASE
66
+
67
+ assert_output(/^BasicTest \/\//)
68
+ assert_output(/AnotherBasicTest \/\//)
69
+ assert_output(/F/)
70
+ assert_output(/\./)
71
+ end
72
+
73
+ def test_runs_basic_test_suite_with_different_printing
74
+ capture_test_output <<-TESTCASE
75
+ MiniTest::Display.options = {
76
+ print: {
77
+ success: 'PASS'
78
+ }
79
+ }
80
+ class PrintTest < MiniTest::Unit::TestCase
81
+
82
+ def test_truth
83
+ assert false
84
+ end
85
+
86
+ def test_equality
87
+ assert_equal 'test', 'test'
88
+ end
89
+ end
90
+ TESTCASE
91
+
92
+ assert_output(/PrintTest \/\//)
93
+ assert_output(/F/)
94
+ assert_output(/PASS/)
95
+ end
96
+
97
+ def test_runs_basic_test_with_slow_output
98
+
99
+ end
100
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest-display
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Aaron Quint
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-03-25 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: bundler
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 0
30
+ - 0
31
+ version: 1.0.0
32
+ type: :development
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: jeweler
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 1
44
+ - 5
45
+ - 2
46
+ version: 1.5.2
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: minitest
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - "="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 2
59
+ - 0
60
+ - 2
61
+ version: 2.0.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: minitest
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ~>
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 2
74
+ - 0
75
+ - 2
76
+ version: 2.0.2
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *id004
80
+ description: Patches MiniTest to allow for an easily configurable output. For Ruby 1.9 :Datches MiniTest to allow for an easily configurable output. For Ruby 1.9 :D. Inspired by leftright, redgreen and other test output gems, with an emphasis on configuration and style
81
+ email: aaron@quirkey.com
82
+ executables: []
83
+
84
+ extensions: []
85
+
86
+ extra_rdoc_files:
87
+ - LICENSE.txt
88
+ - README.rdoc
89
+ files:
90
+ - .document
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - LICENSE.txt
94
+ - README.rdoc
95
+ - Rakefile
96
+ - lib/minitest/display.rb
97
+ - minitest-display.gemspec
98
+ - test/helper.rb
99
+ - test/test_minitest-display.rb
100
+ has_rdoc: true
101
+ homepage: http://github.com/quirkey/minitest-display
102
+ licenses:
103
+ - MIT
104
+ post_install_message:
105
+ rdoc_options: []
106
+
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: -2895922119163746472
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ segments:
124
+ - 0
125
+ version: "0"
126
+ requirements: []
127
+
128
+ rubyforge_project:
129
+ rubygems_version: 1.3.7
130
+ signing_key:
131
+ specification_version: 3
132
+ summary: Patches MiniTest to allow for an easily configurable output. For Ruby 1.9 :D
133
+ test_files:
134
+ - test/helper.rb
135
+ - test/test_minitest-display.rb