ZenTest 3.8.0 → 3.9.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.
@@ -1,3 +1,24 @@
1
+ === 3.9.0 / 2008-01-30
2
+
3
+ * 15 minor enhancements:
4
+
5
+ * Added Wilson's patch to allow unit_diff to work with mspec. Adding rspec next.
6
+ * Minor overhaul for autotest:
7
+ * Added -f flag to start up without testing.
8
+ * Added -q flag to autotest to make it extra quiet. Patch by Aaron Patterson.
9
+ * Added ability to set test execution order, defaults to :random. EVIL!
10
+ * Added completed_re and failed_results_re to help subclasses like rspec.
11
+ * Added deprecation warnings for hooks. Deprecated :run.
12
+ * Added find_directories accessor, defaults to ['.']
13
+ * Added sleep accessor, defaults to 1 second.
14
+ * Changed find_files to order files in the same order as find_directories.
15
+ * Changed how autodiscover works with $:, added lib to the front.
16
+ * Cleaned out nearly every @ and use accessor methods instead. You should too.
17
+ * Made test_mappings ordered.
18
+ * Removed @files, adding @find_order and @known_files.
19
+ * Renamed tests_for_file to test_files_for.
20
+ * test_files_for now only returns known files.
21
+
1
22
  === 3.8.0 / 2008-01-12
2
23
 
3
24
  * 10 minor enhancements:
data/Rakefile CHANGED
@@ -6,16 +6,9 @@ require 'rubygems'
6
6
  require 'hoe'
7
7
  require './lib/zentest.rb'
8
8
 
9
- Hoe.new("ZenTest", ZenTest::VERSION) do |p|
10
- p.author = ['Ryan Davis', 'Eric Hodel']
11
-
12
- changes = p.paragraphs_of("History.txt", 0..4).join("\n\n")
13
- urls, summary, *description = p.paragraphs_of("README.txt", 1, 3, 3..8)
14
-
15
- p.url = urls.gsub(/^\* /, '').split(/\n/)
16
- p.changes = changes
17
- p.summary = summary
18
- p.description = description.join("\n\n")
9
+ Hoe.new("ZenTest", ZenTest::VERSION) do |zentest|
10
+ zentest.developer('Ryan Davis', 'ryand-ruby@zenspider.com')
11
+ zentest.developer('Eric Hodel', 'drbrain@segment7.net')
19
12
  end
20
13
 
21
14
  task :autotest do
@@ -2,6 +2,8 @@
2
2
 
3
3
  $v ||= false
4
4
  $h ||= false
5
+ $f ||= false
6
+ $q ||= false
5
7
  $help ||= false
6
8
 
7
9
  if $h or $help then
@@ -15,6 +17,11 @@ if $h or $help then
15
17
  "\t-v\t\tBe verbose.",
16
18
  "\t\t\tPrints files that autotest doesn't know how to map to",
17
19
  "\t\t\ttests.",
20
+ nil,
21
+ "\t-q\t\tBe more quiet.",
22
+ nil,
23
+ "\t-f\t\tFast start.",
24
+ "\t\t\tDoesn't initially run tests at start.",
18
25
  ]
19
26
  STDERR.puts help.join("\n")
20
27
  exit 1
@@ -57,6 +57,8 @@ $TESTING = false unless defined? $TESTING
57
57
 
58
58
  class Autotest
59
59
 
60
+ T0 = Time.at 0
61
+
60
62
  HOOKS = Hash.new { |h,k| h[k] = [] }
61
63
  unless defined? WINDOZE then
62
64
  WINDOZE = /win32/ =~ RUBY_PLATFORM
@@ -101,8 +103,9 @@ class Autotest
101
103
  def self.autodiscover
102
104
  style = []
103
105
 
104
- $:.push(*Dir["vendor/plugins/*/lib"])
105
106
  paths = $:.dup
107
+ paths.push 'lib'
108
+ paths.push(*Dir["vendor/plugins/*/lib"])
106
109
 
107
110
  begin
108
111
  require 'rubygems'
@@ -112,8 +115,12 @@ class Autotest
112
115
  end
113
116
 
114
117
  paths.each do |d|
118
+ next unless File.directory? d
115
119
  f = File.join(d, 'autotest', 'discover.rb')
116
- load f if File.exist? f
120
+ if File.exist? f then
121
+ $: << d unless $:.include? d
122
+ load f
123
+ end
117
124
  end
118
125
 
119
126
  @@discoveries.map { |proc| proc.call }.flatten.compact.sort.uniq
@@ -126,16 +133,22 @@ class Autotest
126
133
  new.run
127
134
  end
128
135
 
129
- attr_accessor(:extra_class_map,
136
+ attr_writer :known_files
137
+ attr_accessor(:completed_re,
138
+ :extra_class_map,
130
139
  :extra_files,
131
- :files,
140
+ :failed_results_re,
132
141
  :files_to_test,
142
+ :find_order,
133
143
  :interrupted,
134
144
  :last_mtime,
135
145
  :libs,
146
+ :order,
136
147
  :output,
137
148
  :results,
149
+ :sleep,
138
150
  :tainted,
151
+ :find_directories,
139
152
  :unit_diff,
140
153
  :wants_to_quit)
141
154
 
@@ -143,16 +156,24 @@ class Autotest
143
156
  # Initialize the instance and then load the user's .autotest file, if any.
144
157
 
145
158
  def initialize
159
+ # these two are set directly because they're wrapped with
160
+ # add/remove/clear accessor methods
146
161
  @exception_list = []
147
- @extra_class_map = {}
148
- @extra_files = []
149
- @files = Hash.new Time.at(0)
150
- @files_to_test = Hash.new { |h,k| h[k] = [] }
151
- @libs = %w[. lib test].join(File::PATH_SEPARATOR)
152
- @output = $stderr
153
- @sleep = 1
154
- @unit_diff = "unit_diff -u"
155
- @test_mappings = {}
162
+ @test_mappings = []
163
+
164
+ self.completed_re = /\d+ tests, \d+ assertions, \d+ failures, \d+ errors/
165
+ self.extra_class_map = {}
166
+ self.extra_files = []
167
+ self.failed_results_re = /^\s+\d+\) (?:Failure|Error):\n(.*?)\((.*?)\)/
168
+ self.files_to_test = new_hash_of_arrays
169
+ self.find_order = []
170
+ self.known_files = nil
171
+ self.libs = %w[. lib test].join(File::PATH_SEPARATOR)
172
+ self.order = :random
173
+ self.output = $stderr
174
+ self.sleep = 1
175
+ self.find_directories = ['.']
176
+ self.unit_diff = "unit_diff -u"
156
177
 
157
178
  self.add_mapping(/^lib\/.*\.rb$/) do |filename, _|
158
179
  possible = File.basename(filename).gsub '_', '_?'
@@ -178,6 +199,8 @@ class Autotest
178
199
  reset
179
200
  add_sigint_handler
180
201
 
202
+ self.last_mtime = Time.now if $f
203
+
181
204
  loop do # ^c handler
182
205
  begin
183
206
  get_to_green
@@ -214,10 +237,10 @@ class Autotest
214
237
  def run_tests
215
238
  hook :run_command
216
239
 
217
- self.find_files_to_test # failed + changed/affected
240
+ self.find_files_to_test
218
241
  cmd = self.make_test_cmd self.files_to_test
219
242
 
220
- puts cmd
243
+ puts cmd unless $q
221
244
 
222
245
  old_sync = $stdout.sync
223
246
  $stdout.sync = true
@@ -262,7 +285,7 @@ class Autotest
262
285
  unless hook :interrupt then
263
286
  puts "Interrupt a second time to quit"
264
287
  self.interrupted = true
265
- sleep 1.5
288
+ Kernel.sleep 1.5
266
289
  end
267
290
  raise Interrupt, nil # let the run loop catch it
268
291
  end
@@ -294,9 +317,9 @@ class Autotest
294
317
  # file.
295
318
 
296
319
  def consolidate_failures(failed)
297
- filters = Hash.new { |h,k| h[k] = [] }
320
+ filters = new_hash_of_arrays
298
321
 
299
- class_map = Hash[*self.files.keys.grep(/^test/).map { |f|
322
+ class_map = Hash[*self.find_order.grep(/^test/).map { |f| # TODO: ugly
300
323
  [path_to_classname(f), f]
301
324
  }.flatten]
302
325
  class_map.merge!(self.extra_class_map)
@@ -319,18 +342,23 @@ class Autotest
319
342
 
320
343
  def find_files
321
344
  result = {}
322
- targets = ['.'] + self.extra_files
345
+ targets = self.find_directories + self.extra_files
323
346
 
324
- Find.find(*targets) do |f|
325
- Find.prune if f =~ self.exceptions
347
+ targets.each do |target|
348
+ order = []
349
+ Find.find(target) do |f|
350
+ Find.prune if f =~ self.exceptions
326
351
 
327
- next if test ?d, f
328
- next if f =~ /(swp|~|rej|orig)$/ # temporary/patch files
329
- next if f =~ /\/\.?#/ # Emacs autosave/cvs merge files
352
+ next if test ?d, f
353
+ next if f =~ /(swp|~|rej|orig)$/ # temporary/patch files
354
+ next if f =~ /\/\.?#/ # Emacs autosave/cvs merge files
330
355
 
331
- filename = f.sub(/^\.\//, '')
356
+ filename = f.sub(/^\.\//, '')
332
357
 
333
- result[filename] = File.stat(filename).mtime rescue next
358
+ result[filename] = File.stat(filename).mtime rescue next
359
+ order << filename
360
+ end
361
+ self.find_order.push(*order.sort)
334
362
  end
335
363
 
336
364
  return result
@@ -343,26 +371,16 @@ class Autotest
343
371
  # file.
344
372
 
345
373
  def find_files_to_test(files=find_files)
346
- updated = files.select { |filename, mtime|
347
- self.files[filename] < mtime
348
- }
374
+ updated = files.select { |filename, mtime| self.last_mtime < mtime }
349
375
 
350
376
  p updated if $v unless updated.empty? or self.last_mtime.to_i == 0
351
377
 
352
- # TODO: keep an mtime at app level and drop the files hash
353
- updated.each do |filename, mtime|
354
- self.files[filename] = mtime
378
+ updated.map { |f,m| test_files_for(f) }.flatten.uniq.each do |filename|
379
+ self.files_to_test[filename] # creates key with default value
355
380
  end
356
381
 
357
- updated.each do |filename, mtime|
358
- tests_for_file(filename).each do |f|
359
- self.files_to_test[f] # creates key with default value
360
- end
361
- end
362
-
363
- previous = self.last_mtime
364
- self.last_mtime = self.files.values.max
365
- self.last_mtime > previous
382
+ self.last_mtime = files.values.max
383
+ not updated.empty?
366
384
  end
367
385
 
368
386
  ##
@@ -370,25 +388,36 @@ class Autotest
370
388
  # there are failures record this.
371
389
 
372
390
  def handle_results(results)
373
- failed = results.scan(/^\s+\d+\) (?:Failure|Error):\n(.*?)\((.*?)\)/)
374
- completed = results =~ /\d+ tests, \d+ assertions, \d+ failures, \d+ errors/
391
+ failed = results.scan(self.failed_results_re)
392
+ completed = results =~ self.completed_re
375
393
 
376
394
  self.files_to_test = consolidate_failures failed if completed
377
395
 
378
- hook completed && self.files_to_test.empty? ? :green : :red unless $TESTING
396
+ color = completed && self.files_to_test.empty? ? :green : :red
397
+ hook color unless $TESTING
379
398
 
380
399
  self.tainted = true unless self.files_to_test.empty?
381
400
  end
382
401
 
402
+ ##
403
+ # Lazy accessor for the known_files hash.
404
+
405
+ def known_files
406
+ unless @known_files then
407
+ @known_files = Hash[*find_order.map { |f| [f, true] }.flatten]
408
+ end
409
+ @known_files
410
+ end
411
+
383
412
  ##
384
413
  # Generate the commands to test the supplied files
385
414
 
386
415
  def make_test_cmd files_to_test
387
416
  cmds = []
388
- full, partial = files_to_test.partition { |k,v| v.empty? }
417
+ full, partial = reorder(files_to_test).partition { |k,v| v.empty? }
389
418
 
390
419
  unless full.empty? then
391
- classes = full.map {|k,v| k}.flatten.uniq.sort.join(' ')
420
+ classes = full.map {|k,v| k}.flatten.uniq.join(' ')
392
421
  cmds << "#{ruby} -I#{libs} -rtest/unit -e \"%w[#{classes}].each { |f| require f }\" | #{unit_diff}"
393
422
  end
394
423
 
@@ -400,12 +429,32 @@ class Autotest
400
429
  return cmds.join("#{SEP} ")
401
430
  end
402
431
 
432
+ def new_hash_of_arrays
433
+ Hash.new { |h,k| h[k] = [] }
434
+ end
435
+
436
+ def reorder files_to_test
437
+ case self.order
438
+ when :alpha then
439
+ files_to_test.sort_by { |k,v| k }
440
+ when :reverse then
441
+ files_to_test.sort_by { |k,v| k }.reverse
442
+ when :random then
443
+ files_to_test.sort_by { |k,v| rand }
444
+ when :natural then
445
+ (self.find_order & files_to_test.keys).map { |f| [f, files_to_test[f]] }
446
+ else
447
+ raise "unknown order type: #{self.order.inspect}"
448
+ end
449
+ end
450
+
403
451
  ##
404
452
  # Rerun the tests from cold (reset state)
405
453
 
406
454
  def rerun_all_tests
407
455
  reset
408
456
  run_tests
457
+
409
458
  hook :all_good if all_good
410
459
  end
411
460
 
@@ -414,12 +463,14 @@ class Autotest
414
463
  # interrupts will kill autotest.
415
464
 
416
465
  def reset
417
- @interrupted = @wants_to_quit = false
418
- @files.clear
419
- @files_to_test.clear
420
- @last_mtime = Time.at(0)
421
- find_files_to_test # failed + changed/affected
422
- @tainted = false
466
+ self.files_to_test.clear
467
+ self.find_order.clear
468
+ self.interrupted = false
469
+ self.known_files = nil
470
+ self.last_mtime = T0
471
+ self.tainted = false
472
+ self.wants_to_quit = false
473
+
423
474
  hook :reset
424
475
  end
425
476
 
@@ -430,9 +481,7 @@ class Autotest
430
481
  ruby = File.join(Config::CONFIG['bindir'],
431
482
  Config::CONFIG['ruby_install_name'])
432
483
 
433
- unless File::ALT_SEPARATOR.nil? then
434
- ruby.gsub! File::SEPARATOR, File::ALT_SEPARATOR
435
- end
484
+ ruby.gsub! File::SEPARATOR, File::ALT_SEPARATOR if File::ALT_SEPARATOR
436
485
 
437
486
  return ruby
438
487
  end
@@ -442,13 +491,16 @@ class Autotest
442
491
  # a +test_mapping+ that matches the file and executing the mapping's
443
492
  # proc.
444
493
 
445
- def tests_for_file(filename)
494
+ def test_files_for(filename)
446
495
  result = @test_mappings.find { |file_re, ignored| filename =~ file_re }
496
+
497
+ p :test_file_for => [filename, result.first] if result and $DEBUG
498
+
447
499
  result = result.nil? ? [] : Array(result.last.call(filename, $~))
448
500
 
449
501
  output.puts "Dunno! #{filename}" if ($v or $TESTING) and result.empty?
450
502
 
451
- result.sort.uniq
503
+ result.sort.uniq.select { |f| known_files[f] }
452
504
  end
453
505
 
454
506
  ##
@@ -457,7 +509,7 @@ class Autotest
457
509
  def wait_for_changes
458
510
  hook :waiting
459
511
  begin
460
- sleep @sleep
512
+ Kernel.sleep self.sleep
461
513
  end until find_files_to_test
462
514
  end
463
515
 
@@ -468,9 +520,7 @@ class Autotest
468
520
  # Returns all known files in the codebase matching +regexp+.
469
521
 
470
522
  def files_matching regexp
471
- @files.keys.select { |k|
472
- k =~ regexp
473
- }
523
+ self.find_order.select { |k| k =~ regexp }
474
524
  end
475
525
 
476
526
  ##
@@ -485,14 +535,16 @@ class Autotest
485
535
  # end
486
536
 
487
537
  def add_mapping(regexp, &proc)
488
- @test_mappings[regexp] = proc
538
+ @test_mappings << [regexp, proc]
489
539
  end
490
540
 
491
541
  ##
492
542
  # Removed a file mapping matching +regexp+.
493
543
 
494
544
  def remove_mapping regexp
495
- @test_mappings.delete regexp
545
+ @test_mappings.delete_if do |k,v|
546
+ k == regexp
547
+ end
496
548
  end
497
549
 
498
550
  ##
@@ -537,7 +589,7 @@ class Autotest
537
589
  ##
538
590
  # Return a compiled regexp of exceptions for find_files or nil if no
539
591
  # filtering should take place. This regexp is generated from
540
- # @exception_list.
592
+ # +exception_list+.
541
593
 
542
594
  def exceptions
543
595
  unless defined? @exceptions then
@@ -560,6 +612,14 @@ class Autotest
560
612
  # event.
561
613
 
562
614
  def hook(name)
615
+ deprecated = {
616
+ :run => :initialize, # TODO: remove 2008-03-14 (pi day!)
617
+ }
618
+
619
+ if deprecated[name] and not HOOKS[name].empty? then
620
+ warn "hook #{name} has been deprecated, use #{deprecated[name]}"
621
+ end
622
+
563
623
  HOOKS[name].inject(false) do |handled,plugin|
564
624
  plugin[self] || handled
565
625
  end
@@ -7,6 +7,13 @@ class Autotest::Rails < Autotest
7
7
 
8
8
  add_exception %r%^\./(?:db|doc|log|public|script|tmp|vendor)%
9
9
 
10
+ clear_mappings
11
+
12
+ self.add_mapping(/^lib\/.*\.rb$/) do |filename, _|
13
+ impl = File.basename(filename, '.rb')
14
+ files_matching %r%^test/unit/#{impl}_test.rb$%
15
+ end
16
+
10
17
  add_mapping %r%^test/fixtures/(.*)s.yml% do |_, m|
11
18
  ["test/unit/#{m[1]}_test.rb",
12
19
  "test/controllers/#{m[1]}_controller_test.rb",
@@ -62,12 +69,6 @@ class Autotest::Rails < Autotest
62
69
  end
63
70
  end
64
71
 
65
- # Given the string filename as the path, determine
66
- # the corresponding tests for it, in an array.
67
- def tests_for_file(filename)
68
- super.select { |f| @files.has_key? f }
69
- end
70
-
71
72
  # Convert the pathname s to the name of class.
72
73
  def path_to_classname(s)
73
74
  sep = File::SEPARATOR
@@ -1,9 +1,9 @@
1
1
  # -*- ruby -*-
2
2
 
3
3
  module Autotest::Timestamp
4
- Autotest.add_hook :waiting do |at|
4
+ Autotest.add_hook :waiting do
5
5
  puts
6
- puts "# Waiting at #{Time.now.strftime "%Y-%m-%d %H:%M:%S"}"
6
+ puts "# Waiting since #{Time.now.strftime "%Y-%m-%d %H:%M:%S"}"
7
7
  puts
8
8
  end
9
9
  end
@@ -82,14 +82,8 @@ class UnitDiff
82
82
  output.puts input.gets # the rest of "Finished in..."
83
83
  output.puts
84
84
  next
85
- when /^\s*$/ then
85
+ when /^\s*$/, /^\(?\s*\d+\) (Failure|Error):/, /^\d+\)/ then
86
86
  print_lines = false
87
- type = nil
88
- current = []
89
- data << current
90
- when /^\(?\s*\d+\) (Failure|Error):/ then
91
- print_lines = false # if line =~ /Failure|Error/
92
- type = $1
93
87
  current = []
94
88
  data << current
95
89
  when /^Finished in \d/ then
@@ -111,6 +105,7 @@ class UnitDiff
111
105
  header = []
112
106
  expect = []
113
107
  butwas = []
108
+ footer = []
114
109
  found = false
115
110
  state = :header
116
111
 
@@ -118,19 +113,43 @@ class UnitDiff
118
113
  case state
119
114
  when :header then
120
115
  header << result.shift
121
- state = :expect if result.first =~ /^</
116
+ state = :expect if result.first =~ /^<|^Expected/
122
117
  when :expect then
123
- state = :butwas if result.first.sub!(/ expected but was/, '')
124
- expect << result.shift
118
+ if result.first =~ /^Expected (.*?) to equal (.*?):$/ then
119
+ expect << $1
120
+ butwas << $2
121
+ state = :footer
122
+ result.shift
123
+ elsif result.first =~ /^Expected (.*?)$/ then
124
+ expect << "#{$1}\n"
125
+ result.shift
126
+ elsif result.first =~ /^to equal / then
127
+ state = :spec_butwas
128
+ bw = result.shift.sub(/^to equal (.*):?$/, '\1')
129
+ butwas << bw
130
+ else
131
+ state = :butwas if result.first.sub!(/ expected but was/, '')
132
+ expect << result.shift
133
+ end
125
134
  when :butwas then
126
135
  butwas = result[0..-1]
127
136
  result.clear
137
+ when :spec_butwas then
138
+ if result.first =~ /^\s+\S+ at |^:\s*$/
139
+ state = :footer
140
+ else
141
+ butwas << result.shift
142
+ end
143
+ when :footer then
144
+ butwas.last.sub!(/:$/, '')
145
+ footer = result.map {|l| l.chomp }
146
+ result.clear
128
147
  else
129
148
  raise "unknown state #{state}"
130
149
  end
131
150
  end
132
151
 
133
- return header, expect, nil if butwas.empty?
152
+ return header, expect, nil, footer if butwas.empty?
134
153
 
135
154
  expect.last.chomp!
136
155
  expect.first.sub!(/^<\"/, '')
@@ -141,7 +160,7 @@ class UnitDiff
141
160
  butwas.first.sub!( /^<\"/, '')
142
161
  butwas.last.sub!(/\">$/, '')
143
162
 
144
- return header, expect, butwas
163
+ return header, expect, butwas, footer
145
164
  end
146
165
 
147
166
  ##
@@ -164,12 +183,12 @@ class UnitDiff
164
183
  first = []
165
184
  second = []
166
185
 
167
- if result.first !~ /Failure/ then
186
+ if result.first =~ /Error/ then
168
187
  output.push result.join('')
169
188
  next
170
189
  end
171
190
 
172
- prefix, expect, butwas = parse_diff(result)
191
+ prefix, expect, butwas, result_footer = parse_diff(result)
173
192
 
174
193
  output.push prefix.compact.map {|line| line.strip}.join("\n")
175
194
 
@@ -188,7 +207,7 @@ class UnitDiff
188
207
  if result.empty? then
189
208
  output.push "[no difference--suspect ==]"
190
209
  else
191
- output.push result.split("\n")
210
+ output.push result.map { |line| line.chomp }
192
211
  end
193
212
 
194
213
  if $k then
@@ -200,6 +219,7 @@ class UnitDiff
200
219
  end
201
220
  end
202
221
 
222
+ output.push result_footer
203
223
  output.push ''
204
224
  else
205
225
  output.push expect.join('')
@@ -56,7 +56,7 @@ end
56
56
 
57
57
  class ZenTest
58
58
 
59
- VERSION = '3.8.0'
59
+ VERSION = '3.9.0'
60
60
 
61
61
  include ZenTestMapping
62
62
 
@@ -27,6 +27,10 @@ end
27
27
 
28
28
  class TestAutotest < Test::Unit::TestCase
29
29
 
30
+ def deny test
31
+ assert ! test
32
+ end
33
+
30
34
  RUBY = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) unless defined? RUBY
31
35
 
32
36
  def setup
@@ -42,10 +46,13 @@ class TestAutotest < Test::Unit::TestCase
42
46
  klassname.sub!(/^(\w+)(Autotest)$/, '\2::\1') unless klassname == "Autotest"
43
47
  @a = klassname.split(/::/).inject(Object) { |k,n| k.const_get(n) }.new
44
48
  @a.output = StringIO.new
45
- @a.files.clear
46
- @a.files[@impl] = Time.at(1)
47
- @a.files[@test] = Time.at(2)
48
49
  @a.last_mtime = Time.at(2)
50
+
51
+ @files = {}
52
+ @files[@impl] = Time.at(1)
53
+ @files[@test] = Time.at(2)
54
+
55
+ @a.find_order = @files.keys.sort
49
56
  end
50
57
 
51
58
  def test_add_exception
@@ -88,9 +95,11 @@ class TestAutotest < Test::Unit::TestCase
88
95
  end
89
96
 
90
97
  def test_consolidate_failures_experiment
91
- @a.files.clear
92
- @a.files[@impl] = Time.at(1)
93
- @a.files[@test] = Time.at(2)
98
+ @files.clear
99
+ @files[@impl] = Time.at(1)
100
+ @files[@test] = Time.at(2)
101
+
102
+ @a.find_order = @files.keys.sort
94
103
 
95
104
  input = [['test_fail1', @test_class], ['test_fail2', @test_class], ['test_error1', @test_class], ['test_error2', @test_class]]
96
105
  result = @a.consolidate_failures input
@@ -105,7 +114,7 @@ class TestAutotest < Test::Unit::TestCase
105
114
  end
106
115
 
107
116
  def test_consolidate_failures_multiple_possibilities
108
- @a.files[@other_test] = Time.at(42)
117
+ @files[@other_test] = Time.at(42)
109
118
  result = @a.consolidate_failures([['test_unmatched', @test_class]])
110
119
  expected = { @test => ['test_unmatched']}
111
120
  assert_equal expected, result
@@ -114,11 +123,14 @@ class TestAutotest < Test::Unit::TestCase
114
123
  end
115
124
 
116
125
  def test_consolidate_failures_nested_classes
117
- @a.files.clear
118
- @a.files['lib/outer.rb'] = Time.at(5)
119
- @a.files['lib/outer/inner.rb'] = Time.at(5)
120
- @a.files[@inner_test] = Time.at(5)
121
- @a.files[@outer_test] = Time.at(5)
126
+ @files.clear
127
+ @files['lib/outer.rb'] = Time.at(5)
128
+ @files['lib/outer/inner.rb'] = Time.at(5)
129
+ @files[@inner_test] = Time.at(5)
130
+ @files[@outer_test] = Time.at(5)
131
+
132
+ @a.find_order = @files.keys.sort
133
+
122
134
  result = @a.consolidate_failures([['test_blah1', @inner_test_class]])
123
135
  expected = { @inner_test => ['test_blah1'] }
124
136
  assert_equal expected, result
@@ -154,10 +166,10 @@ class TestAutotest < Test::Unit::TestCase
154
166
  # TODO: lots of filename edgecases for find_files_to_test
155
167
  def test_find_files_to_test
156
168
  @a.last_mtime = Time.at(0)
157
- assert @a.find_files_to_test(@a.files)
169
+ assert @a.find_files_to_test(@files)
158
170
 
159
- @a.last_mtime = @a.files.values.sort.last + 1
160
- assert ! @a.find_files_to_test(@a.files)
171
+ @a.last_mtime = @files.values.sort.last + 1
172
+ deny @a.find_files_to_test(@files)
161
173
  end
162
174
 
163
175
  def test_find_files_to_test_dunno
@@ -181,12 +193,12 @@ class TestAutotest < Test::Unit::TestCase
181
193
  assert_equal empty, @a.files_to_test
182
194
 
183
195
  # ensure we do nothing when nothing changes...
184
- files = { @impl => @a.files[@impl] } # same time
185
- assert ! @a.find_files_to_test(files)
196
+ files = { @impl => @files[@impl] } # same time
197
+ deny @a.find_files_to_test(files)
186
198
  assert_equal empty, @a.files_to_test
187
199
  assert_equal "", @a.output.string
188
200
 
189
- files = { @impl => @a.files[@impl] } # same time
201
+ files = { @impl => @files[@impl] } # same time
190
202
  assert(! @a.find_files_to_test(files))
191
203
  assert_equal empty, @a.files_to_test
192
204
  assert_equal "", @a.output.string
@@ -197,11 +209,48 @@ class TestAutotest < Test::Unit::TestCase
197
209
  util_find_files_to_test(@test, @test => [])
198
210
  end
199
211
 
212
+ def test_reorder_alpha
213
+ @a.order = :alpha
214
+ expected = @files.sort
215
+
216
+ assert_equal expected, @a.reorder(@files)
217
+ end
218
+
219
+ def test_reorder_reverse
220
+ @a.order = :reverse
221
+ expected = @files.sort.reverse
222
+
223
+ assert_equal expected, @a.reorder(@files)
224
+ end
225
+
226
+ def test_reorder_random
227
+ srand 42
228
+ @a.order = :random
229
+ expected = ["test/test_blah.rb", "lib/blah.rb"].map { |f| [f, @files[f]] }
230
+
231
+ assert_equal expected, @a.reorder(@files)
232
+ end
233
+
234
+ def test_reorder_natural
235
+ srand 42
236
+
237
+ @files['lib/untested_blah.rb'] = Time.at(2)
238
+ @a.find_order = @files.keys.sort_by { rand }
239
+
240
+ @a.order = :natural
241
+ expected = @a.find_order.map { |f| [f, @files[f]] }
242
+
243
+ assert_equal expected, @a.reorder(@files)
244
+ end
245
+
200
246
  def test_handle_results
201
247
  @a.files_to_test.clear
202
- @a.files.clear
203
- @a.files[@impl] = Time.at(1)
204
- @a.files[@test] = Time.at(2)
248
+ @files.clear
249
+ @files[@impl] = Time.at(1)
250
+ @files[@test] = Time.at(2)
251
+
252
+ @a.find_order = @files.keys.sort
253
+
205
254
  empty = {}
206
255
  assert_equal empty, @a.files_to_test, "must start empty"
207
256
 
@@ -246,7 +295,7 @@ test_error2(#{@test_class}):
246
295
  from -e:1
247
296
  '
248
297
  @a.files_to_test[@test] = Time.at(42)
249
- @a.files[@test] = []
298
+ @files[@test] = []
250
299
  expected = { @test => Time.at(42) }
251
300
  assert_equal expected, @a.files_to_test
252
301
  @a.handle_results(s3)
@@ -256,7 +305,7 @@ test_error2(#{@test_class}):
256
305
 
257
306
  @a.handle_results(s1)
258
307
  assert_equal empty, @a.files_to_test
259
- assert ! @a.tainted
308
+ deny @a.tainted
260
309
  end
261
310
 
262
311
  def test_hook_overlap
@@ -287,14 +336,14 @@ test_error2(#{@test_class}):
287
336
 
288
337
  def test_hook_response
289
338
  Autotest.clear_hooks
290
- assert ! @a.hook(:blah)
339
+ deny @a.hook(:blah)
291
340
 
292
341
  Autotest.add_hook(:blah) { false }
293
- assert ! @a.hook(:blah)
342
+ deny @a.hook(:blah)
294
343
 
295
344
  Autotest.add_hook(:blah) { false }
296
- assert ! @a.hook(:blah)
297
-
345
+ deny @a.hook(:blah)
346
+
298
347
  Autotest.add_hook(:blah) { true }
299
348
  assert @a.hook(:blah)
300
349
  end
@@ -340,14 +389,14 @@ test_error2(#{@test_class}):
340
389
  assert_equal expect, actual
341
390
  end
342
391
 
343
- def test_tests_for_file
344
- assert_equal [@test], @a.tests_for_file(@impl)
345
- assert_equal [@test], @a.tests_for_file(@test)
392
+ def test_test_files_for
393
+ assert_equal [@test], @a.test_files_for(@impl)
394
+ assert_equal [@test], @a.test_files_for(@test)
346
395
 
347
- assert_equal ['test/test_unknown.rb'], @a.tests_for_file('test/test_unknown.rb')
348
- assert_equal [], @a.tests_for_file('lib/unknown.rb')
349
- assert_equal [], @a.tests_for_file('unknown.rb')
350
- assert_equal [], @a.tests_for_file('test_unknown.rb')
396
+ assert_equal [], @a.test_files_for('test/test_unknown.rb')
397
+ assert_equal [], @a.test_files_for('lib/unknown.rb')
398
+ assert_equal [], @a.test_files_for('unknown.rb')
399
+ assert_equal [], @a.test_files_for('test_unknown.rb')
351
400
  end
352
401
 
353
402
  def util_exceptions
@@ -360,12 +409,12 @@ test_error2(#{@test_class}):
360
409
 
361
410
  assert @a.find_files_to_test(files)
362
411
  assert_equal expected, @a.files_to_test
363
- assert_equal t, @a.files[f]
412
+ assert_equal t, @a.last_mtime
364
413
  assert_equal "", @a.output.string
365
414
  end
366
415
 
367
416
  def util_mappings
368
- @a.test_mappings.keys.sort_by { |x| x.to_s }
417
+ @a.test_mappings.map { |k,v| k }.sort_by { |x| x.to_s }
369
418
  end
370
419
 
371
420
  def util_path_to_classname(e,i)
@@ -42,152 +42,183 @@ class TestRailsAutotest < TestAutotest
42
42
  test/views/articles_view_test.rb
43
43
  test/views/layouts_view_test.rb)
44
44
 
45
- @a.files.clear
45
+ @files.clear
46
46
 
47
47
  (@rails_unit_tests +
48
48
  @rails_controller_tests +
49
49
  @rails_view_tests +
50
50
  @rails_functional_tests +
51
- @extra_files).flatten.each_with_index do |path, t|
52
- @a.files[path] = Time.at(t+1)
51
+ @extra_files +
52
+ [@impl]).flatten.each_with_index do |path, t|
53
+ @files[path] = Time.at(t+1)
53
54
  end
54
- @a.last_mtime = @a.files.values.sort.last
55
+
56
+ @a.find_order = @files.keys
57
+ @a.last_mtime = @files.values.sort.last
55
58
  end
56
59
 
57
60
  # Overridden from superclass... the scenario just doesn't happen the same way.
58
61
  def test_consolidate_failures_multiple_matches
59
62
  @test2 = 'test/unit/route_again_test.rb'
60
- @a.files[@test2] = Time.at(42)
61
- @a.files['app/views/routes/edit.rhtml'] = Time.at(42)
62
- @a.files['app/views/routes/list.rhtml'] = Time.at(42)
63
+ @files[@test2] = Time.at(42)
64
+ @files['app/views/routes/edit.rhtml'] = Time.at(42)
65
+ @files['app/views/routes/list.rhtml'] = Time.at(42)
66
+
67
+ @a.find_order = @files.keys
68
+
63
69
  result = @a.consolidate_failures([['test_unmatched', @test_class]])
64
70
  expected = {"test/unit/route_test.rb"=>["test_unmatched"]}
65
71
  assert_equal expected, result
66
72
  assert_equal '', @a.output.string
67
73
  end
68
74
 
69
- def test_tests_for_file
75
+ def test_reorder_random
76
+ srand 42
77
+ @a.order = :random
78
+ expected = ["test/views/admin/themes_view_test.rb",
79
+ "test/functional/articles_controller_test.rb",
80
+ "app/models/route.rb",
81
+ "test/views/articles_view_test.rb",
82
+ "test/views/route_view_test.rb",
83
+ "test/controllers/articles_controller_test.rb",
84
+ "test/functional/admin/themes_controller_test.rb",
85
+ "test/functional/route_controller_test.rb",
86
+ "test/unit/route_test.rb",
87
+ "test/functional/dummy_controller_test.rb",
88
+ "test/controllers/admin/themes_controller_test.rb",
89
+ "test/views/layouts_view_test.rb",
90
+ "test/controllers/dummy_controller_test.rb",
91
+ "test/controllers/route_controller_test.rb"]
92
+ expected.map! { |f| [f, @files[f]] }
93
+
94
+ assert_equal expected, @a.reorder(@files)
95
+ end
96
+
97
+ def test_test_files_for
70
98
  empty = []
71
- assert_equal empty, @a.tests_for_file('blah.rb')
72
- assert_equal empty, @a.tests_for_file('test_blah.rb')
99
+ assert_equal empty, @a.test_files_for('blah.rb')
100
+ assert_equal empty, @a.test_files_for('test_blah.rb')
73
101
 
74
102
  # controllers
75
- util_tests_for_file('app/controllers/admin/themes_controller.rb',
103
+ util_test_files_for('app/controllers/admin/themes_controller.rb',
76
104
  'test/controllers/admin/themes_controller_test.rb',
77
105
  'test/functional/admin/themes_controller_test.rb')
78
106
 
79
- util_tests_for_file('app/controllers/application.rb',
107
+ util_test_files_for('app/controllers/application.rb',
80
108
  @rails_controller_tests,
81
109
  @rails_view_tests,
82
110
  @rails_functional_tests)
83
111
 
84
- util_tests_for_file('app/controllers/route_controller.rb',
112
+ util_test_files_for('app/controllers/route_controller.rb',
85
113
  'test/controllers/route_controller_test.rb',
86
114
  'test/functional/route_controller_test.rb')
87
115
 
88
- util_tests_for_file('app/controllers/notest_controller.rb')
116
+ util_test_files_for('app/controllers/notest_controller.rb')
89
117
 
90
118
  # helpers
91
- util_tests_for_file('app/helpers/application_helper.rb',
119
+ util_test_files_for('app/helpers/application_helper.rb',
92
120
  @rails_view_tests,
93
121
  @rails_functional_tests)
94
122
 
95
- util_tests_for_file('app/helpers/route_helper.rb',
123
+ util_test_files_for('app/helpers/route_helper.rb',
96
124
  'test/views/route_view_test.rb',
97
125
  'test/functional/route_controller_test.rb')
98
126
 
99
127
  # model
100
- util_tests_for_file('app/models/route.rb',
128
+ util_test_files_for('app/models/route.rb',
101
129
  @test)
102
130
 
103
- util_tests_for_file('app/models/notest.rb')
131
+ util_test_files_for('app/models/notest.rb')
104
132
 
105
133
  # views
106
- util_tests_for_file('app/views/layouts/default.rhtml',
134
+ util_test_files_for('app/views/layouts/default.rhtml',
107
135
  'test/views/layouts_view_test.rb')
108
136
 
109
- util_tests_for_file('app/views/route/index.rhtml',
137
+ util_test_files_for('app/views/route/index.rhtml',
110
138
  'test/views/route_view_test.rb',
111
139
  'test/functional/route_controller_test.rb')
112
140
 
113
- util_tests_for_file('app/views/route/xml.rxml',
141
+ util_test_files_for('app/views/route/xml.rxml',
114
142
  'test/views/route_view_test.rb',
115
143
  'test/functional/route_controller_test.rb')
116
144
 
117
- util_tests_for_file('app/views/shared/notest.rhtml')
145
+ util_test_files_for('app/views/shared/notest.rhtml')
118
146
 
119
- util_tests_for_file('app/views/articles/flag.rhtml',
147
+ util_test_files_for('app/views/articles/flag.rhtml',
120
148
  'test/views/articles_view_test.rb',
121
149
  'test/functional/articles_controller_test.rb')
122
150
 
123
151
  # tests
124
- util_tests_for_file('test/fixtures/routes.yml',
152
+ util_test_files_for('test/fixtures/routes.yml',
125
153
  @test,
126
154
  'test/controllers/route_controller_test.rb',
127
155
  'test/views/route_view_test.rb',
128
156
  'test/functional/route_controller_test.rb')
129
157
 
130
- util_tests_for_file('test/test_helper.rb',
158
+ util_test_files_for('test/test_helper.rb',
131
159
  @rails_unit_tests, @rails_controller_tests,
132
160
  @rails_view_tests, @rails_functional_tests)
133
161
 
134
- util_tests_for_file(@test, @test)
162
+ util_test_files_for(@test, @test)
135
163
 
136
- util_tests_for_file('test/controllers/route_controller_test.rb',
164
+ util_test_files_for('test/controllers/route_controller_test.rb',
137
165
  'test/controllers/route_controller_test.rb')
138
166
 
139
- util_tests_for_file('test/views/route_view_test.rb',
167
+ util_test_files_for('test/views/route_view_test.rb',
140
168
  'test/views/route_view_test.rb')
141
169
 
142
- util_tests_for_file('test/functional/route_controller_test.rb',
170
+ util_test_files_for('test/functional/route_controller_test.rb',
143
171
  'test/functional/route_controller_test.rb')
144
172
 
145
- util_tests_for_file('test/functional/admin/themes_controller_test.rb',
173
+ util_test_files_for('test/functional/admin/themes_controller_test.rb',
146
174
  'test/functional/admin/themes_controller_test.rb')
147
175
 
148
176
  # global conf thingies
149
- util_tests_for_file('config/boot.rb',
177
+ util_test_files_for('config/boot.rb',
150
178
  @rails_unit_tests, @rails_controller_tests,
151
179
  @rails_view_tests, @rails_functional_tests)
152
180
 
153
- util_tests_for_file('config/database.yml',
181
+ util_test_files_for('config/database.yml',
154
182
  @rails_unit_tests, @rails_controller_tests,
155
183
  @rails_view_tests, @rails_functional_tests)
156
184
 
157
- util_tests_for_file('config/environment.rb',
185
+ util_test_files_for('config/environment.rb',
158
186
  @rails_unit_tests, @rails_controller_tests,
159
187
  @rails_view_tests, @rails_functional_tests)
160
188
 
161
- util_tests_for_file('config/environments/test.rb',
189
+ util_test_files_for('config/environments/test.rb',
162
190
  @rails_unit_tests, @rails_controller_tests,
163
191
  @rails_view_tests, @rails_functional_tests)
164
192
 
165
- util_tests_for_file('config/routes.rb',
193
+ util_test_files_for('config/routes.rb',
166
194
  @rails_controller_tests,
167
195
  @rails_view_tests, @rails_functional_tests)
168
196
 
169
197
  # ignored crap
170
- util_tests_for_file('vendor/plugins/cartographer/lib/keys.rb')
198
+ util_test_files_for('vendor/plugins/cartographer/lib/keys.rb')
171
199
 
172
- util_tests_for_file('Rakefile')
200
+ util_test_files_for('Rakefile')
173
201
  end
174
202
 
175
203
  def test_consolidate_failures_multiple_matches_before
176
204
  @test_class = 'BlahTest'
177
- @a.files.clear
178
- @a.files['app/model/blah.rb'] = Time.at(42)
179
- @a.files['app/model/different_blah.rb'] = Time.at(42)
180
- @a.files['test/unit/blah_test.rb'] = Time.at(42)
181
- @a.files['test/unit/different_blah_test.rb'] = Time.at(42)
205
+ @files.clear
206
+ @files['app/model/blah.rb'] = Time.at(42)
207
+ @files['app/model/different_blah.rb'] = Time.at(42)
208
+ @files['test/unit/blah_test.rb'] = Time.at(42)
209
+ @files['test/unit/different_blah_test.rb'] = Time.at(42)
210
+
211
+ @a.find_order = @files.keys
212
+
182
213
  result = @a.consolidate_failures([['test_matched', @test_class]])
183
214
  expected = { 'test/unit/blah_test.rb' => [ 'test_matched' ] }
184
215
  assert_equal expected, result
185
216
  assert_equal "", @a.output.string
186
217
  end
187
218
 
188
- def util_tests_for_file(file, *expected)
219
+ def util_test_files_for(file, *expected)
189
220
  assert_equal(expected.flatten.sort.uniq,
190
- @a.tests_for_file(file).sort.uniq, "tests for #{file}")
221
+ @a.test_files_for(file).sort.uniq, "tests for #{file}")
191
222
  end
192
223
 
193
224
  def test_path_to_classname
@@ -200,7 +231,8 @@ class TestRailsAutotest < TestAutotest
200
231
  util_path_to_classname 'BlahTest', 'test/controllers/blah_test.rb'
201
232
  util_path_to_classname 'BlahTest', 'test/helpers/blah_test.rb'
202
233
 
203
- util_path_to_classname 'OuterTest::InnerTest', 'test/controllers/outer/inner_test.rb'
234
+ util_path_to_classname('OuterTest::InnerTest',
235
+ 'test/controllers/outer/inner_test.rb')
204
236
  end
205
237
  end
206
238
 
@@ -25,6 +25,85 @@ class TestUnitDiff < Test::Unit::TestCase
25
25
  util_unit_diff(header, input, expected, :parse_input)
26
26
  end
27
27
 
28
+ def test_input_mini_rspec
29
+ header = <<-HEADER
30
+ Started
31
+ .......F
32
+ Finished in 0.1 seconds
33
+
34
+ HEADER
35
+
36
+ failure = <<-FAILURE
37
+ 1)
38
+ The unless expression should fail FAILED
39
+ Expected nil to equal "baz":
40
+ FAILURE
41
+
42
+ backtrace = <<-BACKTRACE
43
+ PositiveExpectation#== at spec/mini_rspec.rb:217
44
+ main.__script__ {} at spec/language/unless_spec.rb:49
45
+ Proc#call at kernel/core/proc.rb:127
46
+ SpecRunner#it at spec/mini_rspec.rb:368
47
+ main.it at spec/mini_rspec.rb:412
48
+ main.__script__ {} at spec/language/unless_spec.rb:48
49
+ Proc#call at kernel/core/proc.rb:127
50
+ SpecRunner#describe at spec/mini_rspec.rb:378
51
+ main.describe at spec/mini_rspec.rb:408
52
+ main.__script__ at spec/language/unless_spec.rb:3
53
+ CompiledMethod#as_script at kernel/bootstrap/primitives.rb:41
54
+ main.load at kernel/core/compile.rb:150
55
+ main.__script__ {} at last_mspec.rb:11
56
+ Array#each {} at kernel/core/array.rb:545
57
+ Integer(Fixnum)#times at kernel/core/integer.rb:15
58
+ Array#each at kernel/core/array.rb:545
59
+ main.__script__ at last_mspec.rb:16
60
+ CompiledMethod#as_script at kernel/bootstrap/primitives.rb:41
61
+ main.load at kernel/core/compile.rb:150
62
+ main.__script__ at kernel/loader.rb:145
63
+ BACKTRACE
64
+
65
+ footer = "\n8 examples, 1 failures\n"
66
+ input = header + failure + backtrace + footer
67
+
68
+ expected_backtrace = backtrace.split("\n").map {|l| "#{l}\n"}
69
+ expected = [[["1)\n", "The unless expression should fail FAILED\n",
70
+ "Expected nil to equal \"baz\":\n",
71
+ *expected_backtrace]],
72
+ ["\n", "8 examples, 1 failures\n"]]
73
+ util_unit_diff(header, input, expected, :parse_input)
74
+ end
75
+
76
+ def test_input_mini_rspec_multiline
77
+ header = <<-HEADER
78
+ Started
79
+ .......F
80
+ Finished in 0.1 seconds
81
+
82
+ HEADER
83
+
84
+ failure = <<-FAILURE
85
+ 1)
86
+ Compiler compiles a case without an argument FAILED
87
+ Expected #<TestGenerator [[:push, :false], [:gif, #<Label 5>], [:push_literal, "foo"], [:string_dup], [:goto, #<Label 19>], [:set_label, #<Label 5>], [:push, :nil], [:gif, #<Label 10>], [:push_literal, "foo"], [:string_dup], [:goto, #<Label 19>], [:set_label, #<Label 10>], [:push, 2], [:push, 1], [:send, :==, 1, false], [:gif, #<Label 17>], [:push_literal, "bar"], [:string_dup], [:goto, #<Label 19>], [:set_label, #<Label 17>], [:push_literal, "baz"], [:string_dup], [:set_label, #<Label 19>]]
88
+ to equal #<TestGenerator [[:push, false], [:gif, #<Label 5>], [:push, "foo"], [:string_dup], [:goto, #<Label 6>], [:set_label, #<Label 5>], [:push, nil], [:set_label, #<Label 6>], [:pop], [:push, nil], [:gif, #<Label 12>], [:push, "foo"], [:string_dup], [:goto, #<Label 13>], [:set_label, #<Label 12>], [:push, nil], [:set_label, #<Label 13>], [:pop], [:push, 2], [:push, 1], [:send, :==, 1], [:gif, #<Label 21>], [:push, "bar"], [:string_dup], [:goto, #<Label 23>], [:set_label, #<Label 21>], [:push_literal, "baz"], [:string_dup], [:set_label, #<Label 23>], [:sret]]:
89
+ FAILURE
90
+
91
+ backtrace = <<-BACKTRACE
92
+ PositiveExpectation#== at spec/mini_rspec.rb:216
93
+ main.gen at ./compiler2/spec/helper.rb:125
94
+ main.__script__ {} at compiler2/spec/control_spec.rb:448
95
+ BACKTRACE
96
+
97
+ footer = "\n8 examples, 1 failures\n"
98
+ input = header + failure + backtrace + footer
99
+
100
+ expected_backtrace = backtrace.split("\n").map {|l| "#{l}\n"}
101
+ expected_failure = failure.split("\n").map {|l| "#{l}\n"}
102
+ expected = [[[*(expected_failure + expected_backtrace)]],
103
+ ["\n", "8 examples, 1 failures\n"]]
104
+ util_unit_diff(header, input, expected, :parse_input)
105
+ end
106
+
28
107
  def test_unit_diff_empty # simulates broken pipe at the least
29
108
  input = ""
30
109
  expected = ""
@@ -38,7 +117,7 @@ class TestUnitDiff < Test::Unit::TestCase
38
117
  "<\"<body>\">.\n"
39
118
  ]
40
119
 
41
- expected = [[" 1) Failure:\n", "test_test1(TestBlah) [./blah.rb:25]:\n"], ["<html>"], ["<body>"]]
120
+ expected = [[" 1) Failure:\n", "test_test1(TestBlah) [./blah.rb:25]:\n"], ["<html>"], ["<body>"], []]
42
121
 
43
122
  assert_equal expected, @diff.parse_diff(input)
44
123
  end
@@ -50,7 +129,7 @@ class TestUnitDiff < Test::Unit::TestCase
50
129
  "<\"line4\\nline5\\nline6\\n\">.\n"
51
130
  ]
52
131
 
53
- expected = [[" 1) Failure:\n", "test_test1(TestBlah) [./blah.rb:25]:\n"], ["line1\\nline2\\nline3\\n"], ["line4\\nline5\\nline6\\n"]]
132
+ expected = [[" 1) Failure:\n", "test_test1(TestBlah) [./blah.rb:25]:\n"], ["line1\\nline2\\nline3\\n"], ["line4\\nline5\\nline6\\n"], []]
54
133
 
55
134
  assert_equal expected, @diff.parse_diff(input)
56
135
  end
@@ -65,7 +144,8 @@ class TestUnitDiff < Test::Unit::TestCase
65
144
  expected = [[" 2) Failure:\n",
66
145
  "test_test2(TestBlah) [./blah.rb:29]:\n"],
67
146
  ["line1"],
68
- ["line2\\nline3\\n\\n"]
147
+ ["line2\\nline3\\n\\n"],
148
+ []
69
149
  ]
70
150
 
71
151
  assert_equal expected, @diff.parse_diff(input)
@@ -77,7 +157,7 @@ class TestUnitDiff < Test::Unit::TestCase
77
157
  "Unknown expected data.\n",
78
158
  "<false> is not true.\n"]
79
159
 
80
- expected = [[" 13) Failure:\n", "test_case_stmt(TestRubyToRubyC) [./r2ctestcase.rb:1198]:\n", "Unknown expected data.\n"], ["<false> is not true.\n"], nil]
160
+ expected = [[" 13) Failure:\n", "test_case_stmt(TestRubyToRubyC) [./r2ctestcase.rb:1198]:\n", "Unknown expected data.\n"], ["<false> is not true.\n"], nil, []]
81
161
 
82
162
  assert_equal expected, @diff.parse_diff(input)
83
163
  end
@@ -90,7 +170,7 @@ class TestUnitDiff < Test::Unit::TestCase
90
170
  expected = [["1) Failure:\n",
91
171
  "test_util_capture(AssertionsTest) [test/test_zentest_assertions.rb:53]:\n"],
92
172
  ["out"],
93
- ["out"]]
173
+ ["out"], []]
94
174
 
95
175
  assert_equal expected, @diff.parse_diff(input)
96
176
  end
@@ -103,7 +183,34 @@ class TestUnitDiff < Test::Unit::TestCase
103
183
  expected = [["1) Failure:\n",
104
184
  "test_util_capture(AssertionsTest) [test/test_zentest_assertions.rb:53]:\n"],
105
185
  ["out"],
106
- ["out\\n"]]
186
+ ["out\\n"], []]
187
+
188
+ assert_equal expected, @diff.parse_diff(input)
189
+ end
190
+
191
+ def test_parse_diff_mini_rspec
192
+ input = ["1)\n", "The unless expression should fail FAILED\n",
193
+ "Expected nil to equal \"baz\":\n",
194
+ " PositiveExpectation#== at spec/mini_rspec.rb:217\n"]
195
+
196
+ expected = [["1)\n", "The unless expression should fail FAILED\n"],
197
+ ["nil"],
198
+ ["\"baz\""],
199
+ [" PositiveExpectation#== at spec/mini_rspec.rb:217"]]
200
+
201
+ assert_equal expected, @diff.parse_diff(input)
202
+ end
203
+
204
+ def test_parse_diff_mini_rspec_multiline
205
+ input = ["1)\n", "The unless expression should fail FAILED\n",
206
+ "Expected #<TestGenerator [[:push, :true],\n", " [:dup]\n", "]\n",
207
+ "to equal #<TestGenerator [[:pop],\n", " [:dup]\n", "]:\n",
208
+ " PositiveExpectation#== at spec/mini_rspec.rb:217\n"]
209
+
210
+ expected = [["1)\n", "The unless expression should fail FAILED\n"],
211
+ ["#<TestGenerator [[:push, :true],\n", " [:dup]\n", "]"],
212
+ ["#<TestGenerator [[:pop],\n", " [:dup]\n", "]"],
213
+ [" PositiveExpectation#== at spec/mini_rspec.rb:217"]]
107
214
 
108
215
  assert_equal expected, @diff.parse_diff(input)
109
216
  end
@@ -160,7 +267,7 @@ class TestUnitDiff < Test::Unit::TestCase
160
267
  def util_unit_diff(header, input, expected, msg=:unit_diff)
161
268
  output = StringIO.new("")
162
269
  actual = @diff.send(msg, StringIO.new(input), output)
163
- assert_equal header, output.string
270
+ assert_equal header, output.string, "header output"
164
271
  assert_equal expected, actual
165
272
  end
166
273
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ZenTest
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.8.0
4
+ version: 3.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2008-01-14 00:00:00 -08:00
13
+ date: 2008-01-31 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -20,10 +20,12 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.4.0
23
+ version: 1.5.0
24
24
  version:
25
25
  description: "ZenTest provides 4 different tools and 1 library: zentest, unit_diff, autotest, multiruby, and Test::Rails. ZenTest scans your target and unit-test code and writes your missing code based on simple naming rules, enabling XP at a much quicker pace. ZenTest only works with Ruby and Test::Unit. unit_diff is a command-line filter to diff expected results from actual results and allow you to quickly see exactly what is wrong. autotest is a continous testing facility meant to be used during development. As soon as you save a file, autotest will run the corresponding dependent tests. multiruby runs anything you want on multiple versions of ruby. Great for compatibility checking! Test::Rails helps you build industrial-strength Rails code."
26
- email: ryand-ruby@zenspider.com
26
+ email:
27
+ - ryand-ruby@zenspider.com
28
+ - drbrain@segment7.net
27
29
  executables:
28
30
  - autotest
29
31
  - multiruby
@@ -127,7 +129,7 @@ rubyforge_project: zentest
127
129
  rubygems_version: 1.0.1
128
130
  signing_key:
129
131
  specification_version: 2
130
- summary: "ZenTest provides 4 different tools and 1 library: zentest, unit_diff, autotest, multiruby, and Test::Rails."
132
+ summary: "ZenTest provides 4 different tools and 1 library: zentest, unit_diff, autotest, multiruby, and Test::Rails"
131
133
  test_files:
132
134
  - test/test_autotest.rb
133
135
  - test/test_help.rb