ZenTest 3.9.2 → 3.9.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,24 @@
1
+ === 3.9.3 / 2008-06-09
2
+
3
+ * 12 minor enhancements:
4
+
5
+ * Added $RUBY env support to autotest so you can swap what ruby to run.
6
+ * Added ALL_HOOKS array to autotest for hook devs.
7
+ * Added EXCLUDED_VERSIONS to multiruby. Integrated with hoe.
8
+ * Added miniunit compatibility to unit_diff's output.
9
+ * Multiruby now determines the latest versions 1.8/1.9 automatically.
10
+ * Removed deprecated :run hook.
11
+ * Fixed zentest_assertions to be compatible with miniunit. Will phase out.
12
+ * Minor autotest plugin cleanup / fixes.
13
+ * Moved assert_callback to test/rails/test_case.rb
14
+ * Reversed assert_includes' arguments.
15
+ * Updated requirements info for other ruby impls.
16
+ * util_capture now returns strings, not iostrings.
17
+
18
+ * 1 bug fixes:
19
+
20
+ * (add|remove)_(mappings|exceptions) now all return nil to help fix autotest hooks.
21
+
1
22
  === 3.9.2 / 2008-03-20
2
23
 
3
24
  * 4 minor enhancements:
data/README.txt CHANGED
@@ -64,10 +64,10 @@ implementation.
64
64
 
65
65
  == REQUIREMENTS
66
66
 
67
- * Ruby 1.6+
68
- * Test::Unit
67
+ * Ruby 1.6+, JRuby 1.1.2+, or rubinius
68
+ * Test::Unit or miniunit
69
69
  * Hoe
70
- * Rake or rubygems for install/uninstall
70
+ * rubygems
71
71
  * diff.exe on windoze. Try http://gnuwin32.sourceforge.net/packages.html
72
72
 
73
73
  == INSTALL
File without changes
@@ -7,6 +7,15 @@ def run(cmd)
7
7
  raise "ERROR: Command failed with exit code #{$?}" unless system cmd
8
8
  end
9
9
 
10
+ def extract_latest_version url
11
+ file = URI.parse(url).read
12
+ versions = file.scan(/href="(ruby.*tar.gz)"/).flatten.reject { |s|
13
+ s =~ /preview/
14
+ }.sort_by { |s|
15
+ s.split(/\D+/).map { |i| i.to_i }
16
+ }.flatten.last
17
+ end
18
+
10
19
  root_dir = File.expand_path(ENV['MULTIRUBY'] ||
11
20
  File.join(ENV['HOME'], ".multiruby"))
12
21
 
@@ -22,22 +31,25 @@ Dir.chdir root_dir do
22
31
  puts "creating #{dir}"
23
32
  Dir.mkdir dir
24
33
  if dir == "versions" then
25
- puts " Downloading initial ruby tarballs to ~/.multiruby/versions:"
34
+ warn " Downloading initial ruby tarballs to ~/.multiruby/versions:"
26
35
  Dir.chdir dir do
27
- files = %w[ ruby-1.8.6-p111.tar.gz 1.9/ruby-1.9.0-0.tar.gz ]
28
- files.each do |file|
29
- require 'open-uri'
30
- open("http://ftp.ruby-lang.org/pub/ruby/#{file}") do |f|
31
- base = File.basename file
32
- puts " #{base} via HTTP... this might take a while."
36
+ require 'open-uri'
37
+ base_url = "http://ftp.ruby-lang.org/pub/ruby"
38
+
39
+ %w(1.8 1.9).each do |v|
40
+ warn " Determining latest version for #{v}"
41
+ base = extract_latest_version("#{base_url}/#{v}/")
42
+ url = File.join base_url, v, base
43
+ warn " Fetching #{base} via HTTP... this might take a while."
44
+ open(url) do |f|
33
45
  File.open base, 'w' do |out|
34
46
  out.write f.read
35
47
  end
36
48
  end
37
49
  end
38
50
  end
39
- puts " ...done"
40
- puts " Put other ruby tarballs in ~/.multiruby/versions to use them."
51
+ warn " ...done"
52
+ warn " Put other ruby tarballs in ~/.multiruby/versions to use them."
41
53
  end
42
54
  end
43
55
  end
@@ -89,6 +101,11 @@ end
89
101
 
90
102
  versions = ENV['VERSIONS'].split(/:/) if ENV.has_key? 'VERSIONS'
91
103
 
104
+ if ENV.has_key? 'EXCLUDED_VERSIONS' then
105
+ excludes = Regexp.union(*ENV['EXCLUDED_VERSIONS'].split(/:/))
106
+ versions = versions.delete_if { |v| v =~ excludes }
107
+ end
108
+
92
109
  results = {}
93
110
  versions.each do |version|
94
111
  ruby = "#{root_dir}/install/#{version}/bin/ruby"
File without changes
File without changes
File without changes
@@ -59,6 +59,9 @@ class Autotest
59
59
 
60
60
  T0 = Time.at 0
61
61
 
62
+ ALL_HOOKS = [ :all_good, :initialize, :interrupt, :quit, :ran_command,
63
+ :reset, :run_command, :waiting ]
64
+
62
65
  HOOKS = Hash.new { |h,k| h[k] = [] }
63
66
  unless defined? WINDOZE then
64
67
  WINDOZE = /win32/ =~ RUBY_PLATFORM
@@ -195,7 +198,6 @@ class Autotest
195
198
 
196
199
  def run
197
200
  hook :initialize
198
- hook :run # TODO: phase out
199
201
  reset
200
202
  add_sigint_handler
201
203
 
@@ -484,8 +486,9 @@ class Autotest
484
486
  # Determine and return the path of the ruby executable.
485
487
 
486
488
  def ruby
487
- ruby = File.join(Config::CONFIG['bindir'],
488
- Config::CONFIG['ruby_install_name'])
489
+ ruby = ENV['RUBY']
490
+ ruby ||= File.join(Config::CONFIG['bindir'],
491
+ Config::CONFIG['ruby_install_name'])
489
492
 
490
493
  ruby.gsub! File::SEPARATOR, File::ALT_SEPARATOR if File::ALT_SEPARATOR
491
494
 
@@ -540,6 +543,7 @@ class Autotest
540
543
 
541
544
  def add_mapping(regexp, &proc)
542
545
  @test_mappings << [regexp, proc]
546
+ nil
543
547
  end
544
548
 
545
549
  ##
@@ -549,6 +553,7 @@ class Autotest
549
553
  @test_mappings.delete_if do |k,v|
550
554
  k == regexp
551
555
  end
556
+ nil
552
557
  end
553
558
 
554
559
  ##
@@ -558,6 +563,7 @@ class Autotest
558
563
 
559
564
  def clear_mappings
560
565
  @test_mappings.clear
566
+ nil
561
567
  end
562
568
 
563
569
  ############################################################
@@ -570,6 +576,7 @@ class Autotest
570
576
  def add_exception regexp
571
577
  raise "exceptions already compiled" if defined? @exceptions
572
578
  @exception_list << regexp
579
+ nil
573
580
  end
574
581
 
575
582
  ##
@@ -579,6 +586,7 @@ class Autotest
579
586
  def remove_exception regexp
580
587
  raise "exceptions already compiled" if defined? @exceptions
581
588
  @exception_list.delete regexp
589
+ nil
582
590
  end
583
591
 
584
592
  ##
@@ -588,6 +596,7 @@ class Autotest
588
596
  def clear_exceptions
589
597
  raise "exceptions already compiled" if defined? @exceptions
590
598
  @exception_list.clear
599
+ nil
591
600
  end
592
601
 
593
602
  ##
@@ -617,15 +626,15 @@ class Autotest
617
626
 
618
627
  def hook(name)
619
628
  deprecated = {
620
- :run => :initialize, # TODO: remove 2008-03-14 (pi day!)
629
+ # none currently
621
630
  }
622
631
 
623
632
  if deprecated[name] and not HOOKS[name].empty? then
624
633
  warn "hook #{name} has been deprecated, use #{deprecated[name]}"
625
634
  end
626
635
 
627
- HOOKS[name].inject(false) do |handled,plugin|
628
- plugin[self] || handled
636
+ HOOKS[name].any? do |plugin|
637
+ plugin[self]
629
638
  end
630
639
  end
631
640
 
File without changes
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Autotest::Growl
4
4
  def self.growl title, msg, pri = 0, img = nil
5
- title += " in #{Dir.pwd.split(/\//)[-3..-1].join("/")}"
5
+ title += " in #{Dir.pwd.split(/\//).last(3).join("/")}"
6
6
  msg += " at #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}"
7
7
  # TODO: parameterize default image
8
8
  img ||= "/Applications/Mail.app/Contents/Resources/Caution.tiff"
File without changes
File without changes
@@ -12,6 +12,7 @@ class Autotest::Rails < Autotest
12
12
  self.add_mapping(/^lib\/.*\.rb$/) do |filename, _|
13
13
  impl = File.basename(filename, '.rb')
14
14
  files_matching %r%^test/unit/#{impl}_test.rb$%
15
+ # TODO: (unit|functional|integration) maybe?
15
16
  end
16
17
 
17
18
  add_mapping %r%^test/fixtures/(.*)s.yml% do |_, m|
@@ -12,5 +12,11 @@ module Autotest::RCov
12
12
  Autotest.add_hook :all_good do |at|
13
13
  system "rake #{@@command} PATTERN=#{@@pattern}"
14
14
  end
15
+
16
+ Autotest.add_hook :initialize do |at|
17
+ at.add_exception 'coverage'
18
+ at.add_exception 'coverage.info'
19
+ false
20
+ end
15
21
  end
16
22
 
@@ -1,13 +1,21 @@
1
1
  # -*- ruby -*-
2
2
 
3
3
  # special thanks to Pat Eyler, Sean Carley, and Rob Sanheim
4
+ # and to Peter Havens for rspec patches
4
5
  module Autotest::RedGreen
5
- BAR = "=" * 80
6
+ BAR = "=" * 78
7
+ REDCODE = 31
8
+ GREENCODE = 32
6
9
 
7
10
  Autotest.add_hook :ran_command do |at|
8
- if at.results.last =~ /^.* (\d+) failures, (\d+) errors$/
9
- code = ($1 != "0" or $2 != "0") ? 31 : 32
10
- puts "\e[#{code}m#{BAR}\e[0m\n\n"
11
- end
11
+ green = case at.results.last
12
+ when /^.* (\d+) failures, (\d+) errors$/ # Test::Unit
13
+ ($1 == "0" and $2 == "0")
14
+ when /^\d+\s+examples?,\s+(\d+)\s+failure/ # RSpec
15
+ ($1 == "0")
16
+ end
17
+
18
+ code = green ? GREENCODE : REDCODE
19
+ puts "\e[#{ code }m#{ BAR }\e[0m\n\n" unless green.nil?
12
20
  end
13
21
  end
@@ -54,11 +54,6 @@ class Autotest::Screen
54
54
  message 'Run Tests' if execute?
55
55
  end
56
56
 
57
- Autotest.add_hook :interrupt do |at|
58
- message 'Run Tests' if execute?
59
- end
60
-
61
-
62
57
  Autotest.add_hook :quit do |at|
63
58
  clear if execute?
64
59
  end
@@ -246,7 +246,7 @@ class Test::Rails::ControllerTestCase < Test::Rails::FunctionalTestCase
246
246
  def assert_assigned(ivar, value = NOTHING)
247
247
  ivar = ivar.to_s
248
248
  @assigns_asserted << ivar
249
- assert_includes ivar, assigns, "#{ivar.inspect} missing from assigns"
249
+ assert_includes assigns, ivar, "#{ivar.inspect} missing from assigns"
250
250
  unless value.equal? NOTHING then
251
251
  assert_equal value, assigns[ivar],
252
252
  "assert_assigned #{ivar.intern.inspect}"
@@ -289,7 +289,7 @@ class Test::Rails::ControllerTestCase < Test::Rails::FunctionalTestCase
289
289
 
290
290
  def deny_assigned(ivar)
291
291
  ivar = ivar.to_s
292
- deny_includes ivar, assigns
292
+ deny_includes assigns, ivar
293
293
  end
294
294
 
295
295
  ##
@@ -13,3 +13,16 @@ class Test::Rails::TestCase < Test::Unit::TestCase
13
13
 
14
14
  end
15
15
 
16
+ module Test::Unit::Assertions
17
+ ##
18
+ # TODO: should this go in this file?
19
+ # Asserts that model indeed has a given callback
20
+ #
21
+ # assert_callback(Model, :before_save, :something)
22
+
23
+ def assert_callback(model_class, callback, method_name, message=nil)
24
+ vars = model_class.instance_variable_get(:@inheritable_attributes)
25
+ assert vars.has_key?(callback), message
26
+ assert_include vars[callback], method_name, message
27
+ end
28
+ end
@@ -1,124 +1,127 @@
1
+ require 'test/unit/assertions'
2
+
1
3
  ##
2
4
  # Extra assertions for Test::Unit
3
5
 
4
- Test::Unit::Assertions = MiniTest::Unit::TestCase if defined? MiniTest # HACK
5
-
6
6
  module Test::Unit::Assertions
7
+ has_miniunit = defined? ::Mini
8
+
9
+ if has_miniunit then
10
+ alias :assert_include :assert_includes
11
+ alias :deny :refute
12
+ alias :deny_empty :refute_empty
13
+ alias :deny_equal :refute_equal
14
+ alias :deny_include :refute_includes
15
+ alias :deny_includes :refute_includes
16
+ alias :deny_nil :refute_nil
17
+ alias :util_capture :capture_io
18
+ else
19
+
20
+ alias :refute_nil :assert_not_nil
21
+
22
+ ##
23
+ # Asserts that +obj+ responds to #empty? and #empty? returns true.
24
+
25
+ def assert_empty(obj)
26
+ assert_respond_to obj, :empty?
27
+ assert_block "#{obj.inspect} expected to be empty." do obj.empty? end
28
+ end
7
29
 
8
- ##
9
- # TODO: should this go in this file?
10
- # Asserts that model indeed has a given callback
11
- #
12
- # assert_callback(Model, :before_save, :something)
13
-
14
- def assert_callback(model_class, callback, method_name, message=nil)
15
- vars = model_class.instance_variable_get(:@inheritable_attributes)
16
- assert vars.has_key?(callback), message
17
- assert_include vars[callback], method_name, message
18
- end
19
-
20
- ##
21
- # Asserts that +obj+ responds to #empty? and #empty? returns true.
22
-
23
- def assert_empty(obj)
24
- assert_respond_to obj, :empty?
25
- assert_block "#{obj.inspect} expected to be empty." do obj.empty? end
26
- end
30
+ ##
31
+ # Like assert_in_delta but better dealing with errors proportional
32
+ # to the sizes of +a+ and +b+.
27
33
 
28
- ##
29
- # Like assert_in_delta but better dealing with errors proportional
30
- # to the sizes of +a+ and +b+.
34
+ def assert_in_epsilon(a, b, epsilon, message = nil)
35
+ return assert(true) if a == b # count assertion
31
36
 
32
- def assert_in_epsilon(a, b, epsilon, message = nil)
33
- return assert(true) if a == b # count assertion
37
+ error = ((a - b).to_f / ((b.abs > a.abs) ? b : a)).abs
38
+ message ||= "#{a} expected to be within #{epsilon * 100}% of #{b}, was #{error}"
34
39
 
35
- error = ((a - b).to_f / ((b.abs > a.abs) ? b : a)).abs
36
- message ||= "#{a} expected to be within #{epsilon * 100}% of #{b}, was #{error}"
40
+ assert_block message do error <= epsilon end
41
+ end
37
42
 
38
- assert_block message do error <= epsilon end
39
- end
43
+ ##
44
+ # Asserts that +collection+ includes +obj+.
40
45
 
41
- ##
42
- # Asserts that +obj+ responds to #include? and that obj includes +item+.
46
+ def assert_include collection, obj, msg = nil
47
+ assert_respond_to collection, :include?
43
48
 
44
- def assert_include(item, obj, message = nil)
45
- assert_respond_to obj, :include?
46
- message ||= "#{obj.inspect}\ndoes not include\n#{item.inspect}."
47
- assert_block message do obj.include? item end
48
- end
49
+ message ||= "#{collection.inspect}\ndoes not include\n#{obj.inspect}."
50
+ assert_block message do collection.include?(obj) end
51
+ end
49
52
 
50
- alias assert_includes assert_include
53
+ alias assert_includes assert_include
51
54
 
52
- ##
53
- # Asserts that +boolean+ is not false or nil.
55
+ ##
56
+ # Asserts that +boolean+ is not false or nil.
54
57
 
55
- def deny(boolean, message = nil)
56
- _wrap_assertion do
57
- assert_block(build_message(message, "<?> is not false or nil.", boolean)) { not boolean }
58
+ def deny(boolean, message = nil)
59
+ _wrap_assertion do
60
+ assert_block(build_message(message, "Failed refutation, no message given.")) { not boolean }
61
+ end
58
62
  end
59
- end
60
63
 
61
- ##
62
- # Asserts that +obj+ responds to #empty? and #empty? returns false.
64
+ ##
65
+ # Asserts that +obj+ responds to #empty? and #empty? returns false.
63
66
 
64
- def deny_empty(obj)
65
- assert_respond_to obj, :empty?
66
- assert_block "#{obj.inspect} expected to have stuff." do !obj.empty? end
67
- end
67
+ def deny_empty(obj)
68
+ assert_respond_to obj, :empty?
69
+ assert_block "#{obj.inspect} expected to have stuff." do !obj.empty? end
70
+ end
68
71
 
69
- ##
70
- # Alias for assert_not_equal
72
+ ##
73
+ # Alias for assert_not_equal
71
74
 
72
- alias deny_equal assert_not_equal # rescue nil
75
+ alias deny_equal assert_not_equal # rescue nil # rescue for miniunit
73
76
 
74
- ##
75
- # Asserts that +obj+ responds to #include? and that obj does not include
76
- # +item+.
77
+ ##
78
+ # Asserts that +obj+ responds to #include? and that obj does not include
79
+ # +item+.
77
80
 
78
- def deny_include(item, obj, message = nil)
79
- assert_respond_to obj, :include?
80
- message ||= "#{obj.inspect} includes #{item.inspect}."
81
- assert_block message do !obj.include? item end
82
- end
81
+ def deny_include(collection, obj, message = nil)
82
+ assert_respond_to collection, :include?
83
+ message ||= "#{collection.inspect} includes #{obj.inspect}."
84
+ assert_block message do !collection.include? obj end
85
+ end
83
86
 
84
- alias deny_includes deny_include
85
-
86
- ##
87
- # Asserts that +obj+ is not nil.
88
-
89
- alias deny_nil assert_not_nil
90
-
91
- ##
92
- # Captures $stdout and $stderr to StringIO objects and returns them.
93
- # Restores $stdout and $stderr when done.
94
- #
95
- # Usage:
96
- # def test_puts
97
- # out, err = capture do
98
- # puts 'hi'
99
- # STDERR.puts 'bye!'
100
- # end
101
- # assert_equal "hi\n", out.string
102
- # assert_equal "bye!\n", err.string
103
- # end
104
-
105
- def util_capture
106
- require 'stringio'
107
- orig_stdout = $stdout.dup
108
- orig_stderr = $stderr.dup
109
- captured_stdout = StringIO.new
110
- captured_stderr = StringIO.new
111
- $stdout = captured_stdout
112
- $stderr = captured_stderr
113
- yield
114
- captured_stdout.rewind
115
- captured_stderr.rewind
116
- return captured_stdout, captured_stderr
117
- ensure
118
- $stdout = orig_stdout
119
- $stderr = orig_stderr
87
+ alias deny_includes deny_include
88
+
89
+ ##
90
+ # Asserts that +obj+ is not nil.
91
+
92
+ alias deny_nil assert_not_nil
93
+
94
+ ##
95
+ # Captures $stdout and $stderr to StringIO objects and returns them.
96
+ # Restores $stdout and $stderr when done.
97
+ #
98
+ # Usage:
99
+ # def test_puts
100
+ # out, err = capture do
101
+ # puts 'hi'
102
+ # STDERR.puts 'bye!'
103
+ # end
104
+ # assert_equal "hi\n", out.string
105
+ # assert_equal "bye!\n", err.string
106
+ # end
107
+
108
+ def util_capture
109
+ require 'stringio'
110
+ orig_stdout = $stdout.dup
111
+ orig_stderr = $stderr.dup
112
+ captured_stdout = StringIO.new
113
+ captured_stderr = StringIO.new
114
+ $stdout = captured_stdout
115
+ $stderr = captured_stderr
116
+ yield
117
+ captured_stdout.rewind
118
+ captured_stderr.rewind
119
+ return captured_stdout.string, captured_stderr.string
120
+ ensure
121
+ $stdout = orig_stdout
122
+ $stderr = orig_stderr
123
+ end
120
124
  end
121
-
122
125
  end
123
126
 
124
127
  class Object # :nodoc:
@@ -115,15 +115,21 @@ class UnitDiff
115
115
  header << result.shift
116
116
  state = :expect if result.first =~ /^<|^Expected/
117
117
  when :expect then
118
- if result.first =~ /^Expected (.*?) to equal (.*?):$/ then
118
+ case result.first
119
+ when /^Expected (.*?) to equal (.*?):$/ then
119
120
  expect << $1
120
121
  butwas << $2
121
122
  state = :footer
122
123
  result.shift
123
- elsif result.first =~ /^Expected (.*?)$/ then
124
+ when /^Expected (.*?), not (.*)$/m then
125
+ expect << $1
126
+ butwas << $2
127
+ state = :footer
128
+ result.shift
129
+ when /^Expected (.*?)$/ then
124
130
  expect << "#{$1}\n"
125
131
  result.shift
126
- elsif result.first =~ /^to equal / then
132
+ when /^to equal / then
127
133
  state = :spec_butwas
128
134
  bw = result.shift.sub(/^to equal (.*):?$/, '\1')
129
135
  butwas << bw
@@ -56,7 +56,7 @@ end
56
56
 
57
57
  class ZenTest
58
58
 
59
- VERSION = '3.9.2'
59
+ VERSION = '3.9.3'
60
60
 
61
61
  include ZenTestMapping
62
62
 
@@ -27,9 +27,13 @@ end
27
27
 
28
28
  class TestAutotest < Test::Unit::TestCase
29
29
 
30
- def deny test
31
- assert ! test
32
- end
30
+ def deny test, msg=nil
31
+ if msg then
32
+ assert ! test, msg
33
+ else
34
+ assert ! test
35
+ end
36
+ end unless respond_to? :deny
33
37
 
34
38
  RUBY = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) unless defined? RUBY
35
39
 
@@ -313,30 +317,24 @@ test_error2(#{@test_class}):
313
317
  deny @a.tainted
314
318
  end
315
319
 
316
- def test_hook_overlap
317
- Autotest.clear_hooks
320
+ def test_hook_overlap_returning_false
321
+ util_reset_hooks_returning false
318
322
 
319
- @a.instance_variable_set :@blah1, false
320
- @a.instance_variable_set :@blah2, false
321
- @a.instance_variable_set :@blah3, false
322
-
323
- Autotest.add_hook(:blah) do |at|
324
- at.instance_variable_set :@blah1, true
325
- end
323
+ @a.hook :blah
326
324
 
327
- Autotest.add_hook(:blah) do |at|
328
- at.instance_variable_set :@blah2, true
329
- end
325
+ assert @a.instance_variable_get(:@blah1), "Hook1 should work on blah"
326
+ assert @a.instance_variable_get(:@blah2), "Hook2 should work on blah"
327
+ assert @a.instance_variable_get(:@blah3), "Hook3 should work on blah"
328
+ end
330
329
 
331
- Autotest.add_hook(:blah) do |at|
332
- at.instance_variable_set :@blah3, true
333
- end
330
+ def test_hook_overlap_returning_true
331
+ util_reset_hooks_returning true
334
332
 
335
333
  @a.hook :blah
336
334
 
337
335
  assert @a.instance_variable_get(:@blah1), "Hook1 should work on blah"
338
- assert @a.instance_variable_get(:@blah2), "Hook2 should work on blah"
339
- assert @a.instance_variable_get(:@blah3), "Hook3 should work on blah"
336
+ deny @a.instance_variable_get(:@blah2), "Hook2 should NOT work on blah"
337
+ deny @a.instance_variable_get(:@blah3), "Hook3 should NOT work on blah"
340
338
  end
341
339
 
342
340
  def test_hook_response
@@ -425,4 +423,27 @@ test_error2(#{@test_class}):
425
423
  def util_path_to_classname(e,i)
426
424
  assert_equal e, @a.path_to_classname(i)
427
425
  end
426
+
427
+ def util_reset_hooks_returning val
428
+ Autotest.clear_hooks
429
+
430
+ @a.instance_variable_set :@blah1, false
431
+ @a.instance_variable_set :@blah2, false
432
+ @a.instance_variable_set :@blah3, false
433
+
434
+ Autotest.add_hook(:blah) do |at|
435
+ at.instance_variable_set :@blah1, true
436
+ val
437
+ end
438
+
439
+ Autotest.add_hook(:blah) do |at|
440
+ at.instance_variable_set :@blah2, true
441
+ val
442
+ end
443
+
444
+ Autotest.add_hook(:blah) do |at|
445
+ at.instance_variable_set :@blah3, true
446
+ val
447
+ end
448
+ end
428
449
  end
@@ -33,15 +33,15 @@ class TestRailsHelperTestCase < Test::Unit::TestCase
33
33
  def test_self_inherited
34
34
  assert defined? TRHelperTest
35
35
 
36
- assert_includes 'tr_helper', TRHelperTest.instance_methods
36
+ assert_includes TRHelperTest.instance_methods, 'tr_helper'
37
37
  end
38
38
 
39
39
  def test_self_inherited_namespaced
40
40
  assert defined? Widgets
41
41
  assert defined? Widgets::SomeHelperTest
42
42
 
43
- assert_includes 'widgets_some_helper',
44
- Widgets::SomeHelperTest.instance_methods
43
+ assert_includes(Widgets::SomeHelperTest.instance_methods,
44
+ 'widgets_some_helper')
45
45
  end
46
46
 
47
47
  end if $TESTING_RTC
@@ -45,12 +45,12 @@ class TestRailsViewTestCase < Test::Rails::ViewTestCase
45
45
 
46
46
  assert_equal 4, @assert_select.length
47
47
 
48
- assert_equal ["form[action='/game/save']"], @assert_select.shift
49
- assert_equal ["input[type='text'][name='game[amount]']"],
50
- @assert_select.shift
48
+ assert_equal @assert_select.shift, ["form[action='/game/save']"]
49
+ assert_equal(@assert_select.shift,
50
+ ["input[type='text'][name='game[amount]']"])
51
51
 
52
- assert_equal ["form[action='/game/save']"], @assert_select.shift
53
- assert_equal ["label[for='game_amount']"], @assert_select.shift
52
+ assert_equal @assert_select.shift, ["form[action='/game/save']"]
53
+ assert_equal @assert_select.shift, ["label[for='game_amount']"]
54
54
  end
55
55
 
56
56
  def test_assert_form
@@ -167,10 +167,12 @@ class TestRailsViewTestCase < Test::Rails::ViewTestCase
167
167
 
168
168
  assert_equal 2, @assert_select.length
169
169
 
170
- assert_include ["select[name='game[location_id]'] option[value='2']",
171
- { :text => 'Guaymas' }], @assert_select
172
- assert_include ["select[name='game[location_id]'] option[value='1']",
173
- { :text => 'Ballet' }], @assert_select
170
+ assert_include(@assert_select,
171
+ ["select[name='game[location_id]'] option[value='2']",
172
+ { :text => 'Guaymas' }])
173
+ assert_include(@assert_select,
174
+ ["select[name='game[location_id]'] option[value='1']",
175
+ { :text => 'Ballet' }])
174
176
  end
175
177
 
176
178
  def test_assert_select_tag_form
@@ -179,12 +181,14 @@ class TestRailsViewTestCase < Test::Rails::ViewTestCase
179
181
 
180
182
  assert_equal 4, @assert_select.length
181
183
 
182
- assert_include ["form[action='/game/save']"], @assert_select
183
- assert_include ["select[name='game[location_id]'] option[value='2']",
184
- { :text => 'Guaymas' }], @assert_select
185
- assert_include ["form[action='/game/save']"], @assert_select
186
- assert_include ["select[name='game[location_id]'] option[value='1']",
187
- { :text => 'Ballet' }], @assert_select
184
+ assert_include @assert_select, ["form[action='/game/save']"]
185
+ assert_include(@assert_select,
186
+ ["select[name='game[location_id]'] option[value='2']",
187
+ { :text => 'Guaymas' }])
188
+ assert_include @assert_select, ["form[action='/game/save']"]
189
+ assert_include(@assert_select,
190
+ ["select[name='game[location_id]'] option[value='1']",
191
+ { :text => 'Ballet' }])
188
192
  end
189
193
 
190
194
  def test_assert_submit
@@ -25,7 +25,24 @@ 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
28
+ def test_input_miniunit
29
+ header = "Loaded suite -e\nStarted\nF\nFinished in 0.035332 seconds.\n\n"
30
+ input = "#{header} 1) Failure:
31
+ test_blah(TestBlah) [./blah.rb:25]:
32
+ Expected ['a', 'b', 'c'], not ['a', 'c', 'b'].
33
+
34
+ 1 tests, 1 assertions, 1 failures, 0 errors
35
+ "
36
+
37
+ expected = [[[" 1) Failure:\n",
38
+ "test_blah(TestBlah) [./blah.rb:25]:\n",
39
+ "Expected ['a', 'b', 'c'], not ['a', 'c', 'b'].\n"]],
40
+ ["\n", "1 tests, 1 assertions, 1 failures, 0 errors\n"]]
41
+
42
+ util_unit_diff(header, input, expected, :parse_input)
43
+ end
44
+
45
+ def test_input_mspec
29
46
  header = <<-HEADER
30
47
  Started
31
48
  .......F
@@ -40,15 +57,15 @@ Expected nil to equal "baz":
40
57
  FAILURE
41
58
 
42
59
  backtrace = <<-BACKTRACE
43
- PositiveExpectation#== at spec/mini_rspec.rb:217
60
+ PositiveExpectation#== at spec/mspec.rb:217
44
61
  main.__script__ {} at spec/language/unless_spec.rb:49
45
62
  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
63
+ SpecRunner#it at spec/mspec.rb:368
64
+ main.it at spec/mspec.rb:412
48
65
  main.__script__ {} at spec/language/unless_spec.rb:48
49
66
  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
67
+ SpecRunner#describe at spec/mspec.rb:378
68
+ main.describe at spec/mspec.rb:408
52
69
  main.__script__ at spec/language/unless_spec.rb:3
53
70
  CompiledMethod#as_script at kernel/bootstrap/primitives.rb:41
54
71
  main.load at kernel/core/compile.rb:150
@@ -73,7 +90,7 @@ Expected nil to equal "baz":
73
90
  util_unit_diff(header, input, expected, :parse_input)
74
91
  end
75
92
 
76
- def test_input_mini_rspec_multiline
93
+ def test_input_mspec_multiline
77
94
  header = <<-HEADER
78
95
  Started
79
96
  .......F
@@ -89,7 +106,7 @@ to equal #<TestGenerator [[:push, false], [:gif, #<Label 5>], [:push, "foo"], [:
89
106
  FAILURE
90
107
 
91
108
  backtrace = <<-BACKTRACE
92
- PositiveExpectation#== at spec/mini_rspec.rb:216
109
+ PositiveExpectation#== at spec/mspec.rb:216
93
110
  main.gen at ./compiler2/spec/helper.rb:125
94
111
  main.__script__ {} at compiler2/spec/control_spec.rb:448
95
112
  BACKTRACE
@@ -117,11 +134,39 @@ backtrace = <<-BACKTRACE
117
134
  "<\"<body>\">.\n"
118
135
  ]
119
136
 
120
- expected = [[" 1) Failure:\n", "test_test1(TestBlah) [./blah.rb:25]:\n"], ["<html>"], ["<body>"], []]
137
+ expected = [[" 1) Failure:\n", "test_test1(TestBlah) [./blah.rb:25]:\n"],
138
+ ["<html>"],
139
+ ["<body>"],
140
+ []]
121
141
 
122
142
  assert_equal expected, @diff.parse_diff(input)
123
143
  end
124
144
 
145
+ def test_parse_diff_miniunit
146
+ input = [" 1) Failure:\n",
147
+ "test_blah(TestBlah) [./blah.rb:25]:\n",
148
+ "Expected ['a', 'b', 'c'], not ['a', 'c', 'b'].\n"]
149
+
150
+ expected = [[" 1) Failure:\n", "test_blah(TestBlah) [./blah.rb:25]:\n"],
151
+ ["['a', 'b', 'c']"],
152
+ ["['a', 'c', 'b']"],
153
+ []]
154
+
155
+ assert_equal expected, @diff.parse_diff(input)
156
+ end
157
+
158
+ def test_parse_diff_miniunit_multiline
159
+ input = [" 1) Failure:\n",
160
+ "test_blah(TestBlah) [./blah.rb:25]:\n",
161
+ "Expected ['a',\n'b',\n'c'], not ['a',\n'c',\n'b'].\n"]
162
+
163
+ expected = [[" 1) Failure:\n", "test_blah(TestBlah) [./blah.rb:25]:\n"],
164
+ ["['a',\n'b',\n'c']"],
165
+ ["['a',\n'c',\n'b']"],
166
+ []]
167
+
168
+ assert_equal expected, @diff.parse_diff(input)
169
+ end
125
170
  def test_parse_diff1
126
171
  input = [" 1) Failure:\n",
127
172
  "test_test1(TestBlah) [./blah.rb:25]:\n",
@@ -188,29 +233,29 @@ backtrace = <<-BACKTRACE
188
233
  assert_equal expected, @diff.parse_diff(input)
189
234
  end
190
235
 
191
- def test_parse_diff_mini_rspec
236
+ def test_parse_diff_mspec
192
237
  input = ["1)\n", "The unless expression should fail FAILED\n",
193
238
  "Expected nil to equal \"baz\":\n",
194
- " PositiveExpectation#== at spec/mini_rspec.rb:217\n"]
239
+ " PositiveExpectation#== at spec/mspec.rb:217\n"]
195
240
 
196
241
  expected = [["1)\n", "The unless expression should fail FAILED\n"],
197
242
  ["nil"],
198
243
  ["\"baz\""],
199
- [" PositiveExpectation#== at spec/mini_rspec.rb:217"]]
244
+ [" PositiveExpectation#== at spec/mspec.rb:217"]]
200
245
 
201
246
  assert_equal expected, @diff.parse_diff(input)
202
247
  end
203
248
 
204
- def test_parse_diff_mini_rspec_multiline
249
+ def test_parse_diff_mspec_multiline
205
250
  input = ["1)\n", "The unless expression should fail FAILED\n",
206
251
  "Expected #<TestGenerator [[:push, :true],\n", " [:dup]\n", "]\n",
207
252
  "to equal #<TestGenerator [[:pop],\n", " [:dup]\n", "]:\n",
208
- " PositiveExpectation#== at spec/mini_rspec.rb:217\n"]
253
+ " PositiveExpectation#== at spec/mspec.rb:217\n"]
209
254
 
210
255
  expected = [["1)\n", "The unless expression should fail FAILED\n"],
211
256
  ["#<TestGenerator [[:push, :true],\n", " [:dup]\n", "]"],
212
257
  ["#<TestGenerator [[:pop],\n", " [:dup]\n", "]"],
213
- [" PositiveExpectation#== at spec/mini_rspec.rb:217"]]
258
+ [" PositiveExpectation#== at spec/mspec.rb:217"]]
214
259
 
215
260
  assert_equal expected, @diff.parse_diff(input)
216
261
  end
@@ -229,7 +229,7 @@ end
229
229
  # Accessors & Adders:
230
230
 
231
231
  def test_initialize
232
- assert_not_nil(@tester, "Tester must be initialized")
232
+ refute_nil(@tester, "Tester must be initialized")
233
233
  # TODO: should do more at this stage
234
234
  end
235
235
 
@@ -2,80 +2,115 @@ require 'test/unit'
2
2
  require 'test/zentest_assertions'
3
3
 
4
4
  class TestZenTestAssertions < Test::Unit::TestCase
5
+ @@has_mini = defined? Mini
6
+ @@exception = if @@has_mini then
7
+ Mini::Assertion
8
+ else
9
+ Test::Unit::AssertionFailedError
10
+ end
11
+
12
+ def util_assert_triggered expected
13
+ e = assert_raises @@exception do
14
+ yield
15
+ end
16
+
17
+ assert_equal expected, e.message.sub(/(---Backtrace---).*/m, '\1')
18
+ end
5
19
 
6
20
  def test_assert_empty
7
21
  assert_empty []
8
22
 
9
- e = assert_raise Test::Unit::AssertionFailedError do
23
+ msg = if @@has_mini then
24
+ "Expected [true] to be empty."
25
+ else
26
+ "[true] expected to be empty."
27
+ end
28
+
29
+ util_assert_triggered msg do
10
30
  assert_empty [true]
11
31
  end
12
-
13
- assert_equal "[true] expected to be empty.", e.message
14
32
  end
15
33
 
16
34
  def test_assert_include
17
- assert_include true, [true]
35
+ assert_include [true], true
18
36
 
19
- e = assert_raise Test::Unit::AssertionFailedError do
20
- assert_include false, [true]
21
- end
37
+ msg = if @@has_mini then
38
+ "Expected [true] to include false."
39
+ else
40
+ "[true]\ndoes not include\nfalse."
41
+ end
22
42
 
23
- assert_equal "[true]\ndoes not include\nfalse.", e.message
43
+ util_assert_triggered msg do
44
+ assert_include [true], false
45
+ end
24
46
  end
25
47
 
26
48
  def test_assert_in_epsilon
27
- assert_in_epsilon 1.234, 1.234, 0.0001
49
+ assert_in_epsilon 1.234, 1.234, 0.0001
28
50
 
29
- e = assert_raise Test::Unit::AssertionFailedError do
51
+ msg = if @@has_mini then
52
+ "Expected 1.235 - 1.234 (0.00100000000000011) to be < 0.0001234."
53
+ else
54
+ "1.235 expected to be within 0.01% of 1.234, was 0.000809716599190374"
55
+ end
56
+
57
+ util_assert_triggered msg do
30
58
  assert_in_epsilon 1.235, 1.234, 0.0001
31
59
  end
32
-
33
- assert_equal "1.235 expected to be within 0.01% of 1.234, was 0.000809716599190374", e.message
34
60
  end
35
61
 
36
62
  def test_deny
37
63
  deny false
38
64
  deny nil
39
65
 
40
- e = assert_raise Test::Unit::AssertionFailedError do
66
+ e = assert_raises Test::Unit::AssertionFailedError do
41
67
  deny true
42
68
  end
43
69
 
44
- assert_equal "<true> is not false or nil.", e.message
70
+ assert_match(/Failed refutation, no message given/, e.message)
45
71
  end
46
72
 
47
73
  def test_deny_empty
48
74
  deny_empty [true]
49
75
 
50
- e = assert_raise Test::Unit::AssertionFailedError do
76
+ msg = if @@has_mini then
77
+ "Expected [] to not be empty."
78
+ else
79
+ "[] expected to have stuff."
80
+ end
81
+
82
+ util_assert_triggered msg do
51
83
  deny_empty []
52
84
  end
53
85
 
54
- assert_equal "[] expected to have stuff.", e.message
55
86
  end
56
87
 
57
88
  def test_deny_equal
58
89
  deny_equal true, false
59
90
 
60
- assert_raise Test::Unit::AssertionFailedError do
91
+ assert_raises Test::Unit::AssertionFailedError do
61
92
  deny_equal true, true
62
93
  end
63
94
  end
64
95
 
65
96
  def test_deny_include
66
- deny_include false, [true]
97
+ deny_include [true], false
67
98
 
68
- e = assert_raise Test::Unit::AssertionFailedError do
69
- deny_include true, [true]
70
- end
99
+ msg = if @@has_mini then
100
+ "Expected [true] to not include true."
101
+ else
102
+ "[true] includes true."
103
+ end
71
104
 
72
- assert_equal "[true] includes true.", e.message
105
+ util_assert_triggered msg do
106
+ deny_include [true], true
107
+ end
73
108
  end
74
109
 
75
110
  def test_deny_nil
76
111
  deny_nil false
77
112
 
78
- assert_raise Test::Unit::AssertionFailedError do
113
+ assert_raises Test::Unit::AssertionFailedError do
79
114
  deny_nil nil
80
115
  end
81
116
  end
@@ -86,9 +121,8 @@ class TestZenTestAssertions < Test::Unit::TestCase
86
121
  $stderr.puts 'err'
87
122
  end
88
123
 
89
- assert_equal "out\n", out.string
90
- assert_equal "err\n", err.string
124
+ assert_equal "out\n", out
125
+ assert_equal "err\n", err
91
126
  end
92
-
93
127
  end
94
128
 
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.9.2
4
+ version: 3.9.3
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-03-20 00:00:00 -07:00
13
+ date: 2008-06-09 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.5.1
23
+ version: 1.5.3
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
26
  email:
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  requirements: []
130
130
 
131
131
  rubyforge_project: zentest
132
- rubygems_version: 1.0.1
132
+ rubygems_version: 1.1.1
133
133
  signing_key:
134
134
  specification_version: 2
135
135
  summary: "ZenTest provides 4 different tools and 1 library: zentest, unit_diff, autotest, multiruby, and Test::Rails"