minitest-display 0.2.0.pre → 0.2.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,7 +1,8 @@
1
1
  source "http://rubygems.org"
2
2
 
3
+ gem "minitest", "~> 4.3"
4
+
3
5
  group :development do
4
- gem "bundler", "~> 1.0.0"
5
- gem "jeweler", "~> 1.5.2"
6
- gem "minitest"
6
+ gem "bundler", "~> 1.0"
7
+ gem "jeweler", "~> 1.5"
7
8
  end
@@ -2,17 +2,21 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  git (1.2.5)
5
- jeweler (1.5.2)
6
- bundler (~> 1.0.0)
5
+ jeweler (1.8.4)
6
+ bundler (~> 1.0)
7
7
  git (>= 1.2.5)
8
8
  rake
9
- minitest (2.3.1)
10
- rake (0.9.2)
9
+ rdoc
10
+ json (1.7.5)
11
+ minitest (4.3.3)
12
+ rake (10.0.2)
13
+ rdoc (3.12)
14
+ json (~> 1.4)
11
15
 
12
16
  PLATFORMS
13
17
  ruby
14
18
 
15
19
  DEPENDENCIES
16
- bundler (~> 1.0.0)
17
- jeweler (~> 1.5.2)
18
- minitest
20
+ bundler (~> 1.0)
21
+ jeweler (~> 1.5)
22
+ minitest (~> 4.3)
data/Rakefile CHANGED
@@ -21,10 +21,6 @@ Jeweler::Tasks.new do |gem|
21
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
22
  gem.email = "aaron@quirkey.com"
23
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.3'
27
- # gem.add_development_dependency 'rspec', '> 1.2.3'
28
24
  end
29
25
  Jeweler::RubygemsDotOrgTasks.new
30
26
 
@@ -36,13 +32,3 @@ Rake::TestTask.new(:test) do |test|
36
32
  end
37
33
 
38
34
  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
@@ -1,3 +1,5 @@
1
+ require 'minitest/unit'
2
+
1
3
  class Hash
2
4
  unless method_defined?(:deep_merge!)
3
5
 
@@ -18,7 +20,7 @@ end
18
20
 
19
21
  module MiniTest
20
22
  module Display
21
- VERSION = '0.1.0'
23
+ VERSION = '0.2.0.pre1'
22
24
 
23
25
  class << self
24
26
  def options
@@ -116,12 +118,57 @@ module MiniTest
116
118
  end
117
119
  end
118
120
 
119
- class MiniTest::Unit
120
- # Monkey Patchin!
121
- def _run_anything(type)
121
+ class MiniTest::Display::Runner < MiniTest::Unit
122
+
123
+ def initialize(*args)
124
+ super
125
+ @recorders = []
126
+ end
127
+
128
+ # Add a recorder which for each test that has a `record`.
129
+ # Optionally can also have an:
130
+ #
131
+ # `record_tests_started`,
132
+ # `record_suite_started(suite)`,
133
+ # `record(suite, method, assertions, time, error)`
134
+ # `record_suite_finished(suite, assertions, time)`,
135
+ # `record_tests_finished(report, test_count, assertion_count, time)
136
+ #
137
+ # (Executed in that order)
138
+ #
139
+ def add_recorder(new_recorder)
140
+ new_recorder_instance = new_recorder.new(self)
141
+ @recorders << new_recorder_instance
142
+ end
143
+
144
+ def record_suite_started(suite)
145
+ run_recorder_method(:record_suite_started, suite)
146
+ end
147
+
148
+ def record_suite_finished(suite, assertions, time)
149
+ run_recorder_method(:record_suite_finished, suite)
150
+ end
151
+
152
+ def record_tests_started
153
+ run_recorder_method(:record_tests_started)
154
+ end
155
+
156
+ def record_tests_finished(report, test_count, assertion_count, time)
157
+ run_recorder_method(:record_tests_finished, report, test_count, assertion_count, time)
158
+ end
159
+
160
+ def record(suite, method, assertions, time, error)
161
+ run_recorder_method(:record, suite, method, assertions, time, error)
162
+ end
163
+
164
+ # Patched _run_anything
165
+ def _run_anything type
122
166
  suites = TestCase.send "#{type}_suites"
123
167
  return if suites.empty?
124
168
 
169
+ # PATCH
170
+ record_tests_started
171
+ # END
125
172
  start = Time.now
126
173
 
127
174
  puts
@@ -152,34 +199,49 @@ class MiniTest::Unit
152
199
 
153
200
  puts
154
201
 
202
+ # PATCH
203
+ record_tests_finished(report, test_count, assertion_count, t)
204
+ # END
155
205
  status
156
206
  end
157
207
 
208
+ # Patched _run_suite
158
209
  def _run_suite(suite, type)
159
- suite_header = ""
210
+ header = "#{type}_suite_header"
211
+ suite_header = send(header, suite) if respond_to? header
212
+
213
+ # PATCH
160
214
  if display.options[:suite_names] && display.printable_suite?(suite)
161
- suite_header = suite.to_s
215
+ suite_header ||= suite.to_s
162
216
  print display.color("\n#{suite_header}#{display.options[:suite_divider]}", :suite)
163
217
  end
218
+ # END
164
219
 
165
220
  filter = options[:filter] || '/./'
166
221
  filter = Regexp.new $1 if filter =~ /\/(.*)\//
167
222
 
168
- wrap_at = display.options[:wrap_at] - suite_header.length
223
+ # PATCH
224
+ wrap_at = display.options[:wrap_at] - suite_header.length if suite_header
169
225
  wrap_count = wrap_at
170
226
 
227
+ record_suite_started(suite)
171
228
  full_start_time = Time.now
172
229
  @test_times ||= Hash.new { |h, k| h[k] = [] }
230
+
231
+ #END
173
232
  assertions = suite.send("#{type}_methods").grep(filter).map { |method|
174
233
  inst = suite.new method
175
234
  inst._assertions = 0
176
235
 
177
236
  print "#{suite}##{method} = " if @verbose
178
237
 
179
- @start_time = Time.now
238
+ # PATCH
239
+ start_time = Time.now
240
+ # END
180
241
  result = inst.run self
181
- time = Time.now - @start_time
182
242
 
243
+ # PATCH
244
+ time = Time.now - start_time
183
245
  @test_times[suite] << ["#{suite}##{method}", time]
184
246
 
185
247
  print "%.2f s = " % time if @verbose
@@ -193,6 +255,7 @@ class MiniTest::Unit
193
255
  else
194
256
  result
195
257
  end
258
+
196
259
  puts if @verbose
197
260
 
198
261
  wrap_count -= 1
@@ -206,6 +269,7 @@ class MiniTest::Unit
206
269
 
207
270
  total_time = Time.now - full_start_time
208
271
 
272
+ record_suite_finished(suite, assertions, total_time)
209
273
  if assertions.length > 0 && display.options[:suite_time]
210
274
  print "\n#{' ' * suite_header.length}#{display.options[:suite_divider]}"
211
275
  print "%.2f s" % total_time
@@ -234,7 +298,7 @@ class MiniTest::Unit
234
298
  end
235
299
 
236
300
  def display_slow_suites
237
- times = @test_times.map { |suite, tests| [suite, tests.map(&:last).sum] }.sort { |a, b| b[1] <=> a[1] }
301
+ times = @test_times.map { |suite, tests| [suite, tests.map(&:last).inject {|sum, n| sum + n }] }.sort { |a, b| b[1] <=> a[1] }
238
302
  puts "Slowest suites:"
239
303
  times[0..display.options[:output_slow_suites].to_i].each do |suite, time|
240
304
  puts "%.2f s\t#{suite}" % time
@@ -242,7 +306,17 @@ class MiniTest::Unit
242
306
  end
243
307
 
244
308
  private
309
+ def run_recorder_method(method, *args)
310
+ @recorders.each do |recorder|
311
+ if recorder.respond_to?(method)
312
+ recorder.send method, *args
313
+ end
314
+ end
315
+ end
316
+
245
317
  def display
246
318
  ::MiniTest::Display
247
319
  end
248
320
  end
321
+
322
+ MiniTest::Unit.runner = MiniTest::Display::Runner.new
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "minitest-display"
8
- s.version = "0.2.0.pre"
8
+ s.version = "0.2.0.pre1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Aaron Quint"]
@@ -96,6 +96,67 @@ class TestMinitestDisplay < MiniTest::Unit::TestCase
96
96
  end
97
97
 
98
98
  def test_runs_basic_test_with_slow_output
99
+ capture_test_output <<-TESTCASE
100
+ MiniTest::Display.options = {
101
+ :suite_divider => ' // ',
102
+ :print => {
103
+ :success => 'PASS'
104
+ },
105
+ :output_slow => true
106
+ }
107
+ class PrintTest < MiniTest::Unit::TestCase
108
+
109
+ def test_truth
110
+ assert false
111
+ end
112
+
113
+ def test_equality
114
+ assert_equal 'test', 'test'
115
+ end
116
+ end
117
+ TESTCASE
118
+
119
+ assert_output(/PrintTest \/\//)
120
+ assert_output(/F/)
121
+ assert_output(/PASS/)
122
+ assert_output(/Slowest tests:/)
123
+ end
124
+
125
+ def test_adding_a_recorder
126
+ capture_test_output <<-TESTCASE
127
+ MiniTest::Display.options = {
128
+ :suite_divider => ' // ',
129
+ :print => {
130
+ :success => 'PASS'
131
+ }
132
+ }
133
+ class TestRecorder
134
+ def initialize(runner)
135
+ @runner = runner
136
+ end
99
137
 
138
+ def record(suite, method, assertions, time, error)
139
+ puts "I just recorded \#{method}"
140
+ end
141
+ end
142
+
143
+ MiniTest::Unit.runner.add_recorder TestRecorder
144
+
145
+ class PrintTest < MiniTest::Unit::TestCase
146
+
147
+ def test_truth
148
+ assert false
149
+ end
150
+
151
+ def test_equality
152
+ assert_equal 'test', 'test'
153
+ end
154
+ end
155
+ TESTCASE
156
+
157
+ assert_output(/PrintTest \/\//)
158
+ assert_output(/F/)
159
+ assert_output(/PASS/)
160
+ assert_output(/I just recorded test_truth/)
100
161
  end
101
162
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-display
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.pre
4
+ version: 0.2.0.pre1
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -97,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
97
  version: '0'
98
98
  segments:
99
99
  - 0
100
- hash: 4169721688534295478
100
+ hash: -196578224241529299
101
101
  required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  none: false
103
103
  requirements: