ZenTest 3.6.1 → 3.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,57 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'fileutils'
4
+
5
+ module Autotest::CCTray
6
+ MAX = 30
7
+ STATUS = {
8
+ :all_good => "Success",
9
+ :green => "Success",
10
+ :red => "Failure",
11
+ }
12
+ DIR = File.expand_path("~/Sites/dashboard")
13
+
14
+ def self.project_name= name
15
+ @@project_name = name
16
+ end
17
+
18
+ def self.update_status status
19
+ dir = File.join(DIR, @@project_name)
20
+ serial = Time.now.to_i
21
+ file = "status.#{serial}.xml"
22
+ FileUtils.mkdir_p dir
23
+ Dir.chdir dir do
24
+ File.open(file, 'w') do |f|
25
+ f.puts %(<Project name="#{@@project_name}" activity="Sleeping" lastBuildStatus="#{STATUS[status]}" lastBuildLabel="build.#{serial}" lastBuildTime="#{Time.now.xmlschema}" webUrl="http://localhost/~ryan/dashboard/#{@@project_name}/"/>)
26
+ end
27
+ files = Dir["*.xml"].sort_by { |f| File.mtime f }.reverse
28
+ (files - files.first(MAX)).each do |f|
29
+ File.unlink f
30
+ end
31
+ end
32
+
33
+ Dir.chdir DIR do
34
+ new_file = "cctray.xml.#{$$}"
35
+ old_file = "cctray.xml"
36
+ File.open(from_file, "w") do |out|
37
+ out.puts "<Projects>"
38
+ Dir["*"].each do |d|
39
+ next unless File.directory? d
40
+ Dir.chdir d do
41
+ latest = Dir["*.xml"].sort_by { |f| File.mtime f }.last
42
+ out.puts File.read(latest)
43
+ end
44
+ end
45
+ out.puts "</Projects>"
46
+ end
47
+ File.rename new_file, old_file
48
+ end
49
+ end
50
+
51
+ [:run, :red, :green, :all_good].each do |status|
52
+ Autotest.add_hook status do |at|
53
+ STATUS[Time.now] = at.files_to_test.size
54
+ update_status status
55
+ end
56
+ end
57
+ end
@@ -5,7 +5,7 @@ module Autotest::RedGreen
5
5
  BAR = "=" * 80
6
6
 
7
7
  Autotest.add_hook :ran_command do |at|
8
- if at.results.last.match(/^.* (\d+) failures, (\d+) errors$/)
8
+ if at.results.last =~ /^.* (\d+) failures, (\d+) errors$/
9
9
  code = ($1 != "0" or $2 != "0") ? 31 : 32
10
10
  puts "\e[#{code}m#{BAR}\e[0m\n\n"
11
11
  end
@@ -1,5 +1,5 @@
1
1
  ##
2
- # Autotest::Screen is test result notify GUN Screen's statusline.
2
+ # Autotest::Screen is test result notify GNU Screen's statusline.
3
3
  #
4
4
  # === screenshots
5
5
  # * <img src="http://f.hatena.ne.jp/images/fotolife/s/secondlife/20061109/20061109015543.png" />
@@ -1,4 +1,5 @@
1
1
  require 'test/unit'
2
+ require 'rubygems'
2
3
  require 'rubygems/version'
3
4
  require 'test_help' # hopefully temporary, required for Test::Rails to work
4
5
  # until we get rid of test_help so Test::Unit::TestCase
@@ -7,7 +7,7 @@
7
7
  #
8
8
  # * Allows testing of individual AJAX templates.
9
9
  # * Allows testing of individual partials.
10
- # * Large library of helful assertions.
10
+ # * Large library of helpful assertions.
11
11
  #
12
12
  # = Naming
13
13
  #
@@ -3,6 +3,18 @@
3
3
 
4
4
  module Test::Unit::Assertions
5
5
 
6
+ ##
7
+ # TODO: should this go in this file?
8
+ # Asserts that model indeed has a given callback
9
+ #
10
+ # assert_callback(Model, :before_save, :something)
11
+
12
+ def assert_callback(model_class, callback, method_name, message=nil)
13
+ vars = model_class.instance_variable_get(:@inheritable_attributes)
14
+ assert vars.has_key?(callback), message
15
+ assert_include vars[callback], method_name, message
16
+ end
17
+
6
18
  ##
7
19
  # Asserts that +obj+ responds to #empty? and #empty? returns true.
8
20
 
@@ -188,7 +188,7 @@ class UnitDiff
188
188
  if result.empty? then
189
189
  output.push "[no difference--suspect ==]"
190
190
  else
191
- output.push result.map { |line| line.chomp }
191
+ output.push result.split("\n")
192
192
  end
193
193
 
194
194
  if $k then
@@ -56,7 +56,7 @@ end
56
56
 
57
57
  class ZenTest
58
58
 
59
- VERSION = '3.6.1'
59
+ VERSION = '3.7.0'
60
60
 
61
61
  include ZenTestMapping
62
62
 
@@ -128,21 +128,24 @@ class ZenTest
128
128
  klass = self.get_class(klass) if klass.kind_of? String
129
129
 
130
130
  # WTF? public_instance_methods: default vs true vs false = 3 answers
131
+ # to_s on all results if ruby >= 1.9
131
132
  public_methods = klass.public_instance_methods(false)
132
- klass_methods = klass.singleton_methods(full)
133
- klass_methods -= Class.public_methods(true)
134
- klass_methods -= %w(suite new)
135
- klass_methods = klass_methods.map { |m| "self." + m }
136
- public_methods += klass_methods
137
133
  public_methods -= Kernel.methods unless full
134
+ public_methods.map! { |m| m.to_s }
138
135
  public_methods -= %w(pretty_print pretty_print_cycle)
139
- klassmethods = {}
140
- public_methods.each do |meth|
136
+
137
+ klass_methods = klass.singleton_methods(full)
138
+ klass_methods -= Class.public_methods(true)
139
+ klass_methods = klass_methods.map { |m| "self.#{m}" }
140
+ klass_methods -= %w(self.suite new)
141
+
142
+ result = {}
143
+ (public_methods + klass_methods).each do |meth|
141
144
  puts "# found method #{meth}" if $DEBUG
142
- klassmethods[meth] = true
145
+ result[meth] = true
143
146
  end
144
147
 
145
- return klassmethods
148
+ return result
146
149
  end
147
150
 
148
151
  # Return the methods for class klass, as a hash with the
@@ -165,7 +168,7 @@ class ZenTest
165
168
  end
166
169
 
167
170
  the_methods.each do |meth|
168
- klassmethods[meth] = true
171
+ klassmethods[meth.to_s] = true
169
172
  end
170
173
  end
171
174
  end
@@ -326,14 +329,20 @@ class ZenTest
326
329
  @missing_methods[klassname][methodname] = true
327
330
  end
328
331
 
332
+ # looks up the methods and the corresponding test methods
333
+ # in the collection already built. To reduce duplication
334
+ # and hide implementation details.
335
+ def methods_and_tests(klassname, testklassname)
336
+ return @klasses[klassname], @test_klasses[testklassname]
337
+ end
338
+
329
339
  # Checks, for the given class klassname, that each method
330
340
  # has a corrsponding test method. If it doesn't this is
331
341
  # added to the information for that class
332
342
  def analyze_impl(klassname)
333
343
  testklassname = self.convert_class_name(klassname)
334
344
  if @test_klasses[testklassname] then
335
- methods = @klasses[klassname]
336
- testmethods = @test_klasses[testklassname]
345
+ methods, testmethods = methods_and_tests(klassname,testklassname)
337
346
 
338
347
  # check that each method has a test method
339
348
  @klasses[klassname].each_key do | methodname |
@@ -371,8 +380,7 @@ class ZenTest
371
380
  end
372
381
 
373
382
  if @klasses[klassname] then
374
- methods = @klasses[klassname]
375
- testmethods = @test_klasses[testklassname]
383
+ methods, testmethods = methods_and_tests(klassname,testklassname)
376
384
 
377
385
  # check that each test method has a method
378
386
  testmethods.each_key do | testmethodname |
@@ -414,6 +422,19 @@ class ZenTest
414
422
  end # @klasses[klassname]
415
423
  end
416
424
 
425
+ # create a given method at a given
426
+ # indentation. Returns an array containing
427
+ # the lines of the method.
428
+ def create_method(indentunit, indent, name)
429
+ meth = []
430
+ meth.push indentunit*indent + "def #{name}"
431
+ meth.last << "(*args)" unless name =~ /^test/
432
+ indent += 1
433
+ meth.push indentunit*indent + "raise NotImplementedError, 'Need to write #{name}'"
434
+ indent -= 1
435
+ meth.push indentunit*indent + "end"
436
+ return meth
437
+ end
417
438
 
418
439
  # Walk each known class and test that each method has
419
440
  # a test method
@@ -477,25 +498,13 @@ class ZenTest
477
498
  meths = []
478
499
 
479
500
  cls_methods.sort.each do |method|
480
- meth = []
481
- meth.push indentunit*indent + "def #{method}"
482
- meth.last << "(*args)" unless method =~ /^test/
483
- indent += 1
484
- meth.push indentunit*indent + "raise NotImplementedError, 'Need to write #{method}'"
485
- indent -= 1
486
- meth.push indentunit*indent + "end"
501
+ meth = create_method(indentunit, indent, method)
487
502
  meths.push meth.join("\n")
488
503
  end
489
504
 
490
505
  methods.keys.sort.each do |method|
491
506
  next if method =~ /pretty_print/
492
- meth = []
493
- meth.push indentunit*indent + "def #{method}"
494
- meth.last << "(*args)" unless method =~ /^test/
495
- indent += 1
496
- meth.push indentunit*indent + "raise NotImplementedError, 'Need to write #{method}'"
497
- indent -= 1
498
- meth.push indentunit*indent + "end"
507
+ meth = create_method(indentunit, indent, method)
499
508
  meths.push meth.join("\n")
500
509
  end
501
510
 
@@ -59,7 +59,7 @@ module ZenTestMapping
59
59
  # taking into account names composed of metacharacters
60
60
  # (used for arithmetic, etc
61
61
  def normal_to_test(name)
62
- name = name.dup # wtf?
62
+ name = name.to_s.dup # wtf?
63
63
  is_cls_method = name.sub!(/^self\./, '')
64
64
  name = @@method_map[name] if @@method_map.has_key? name
65
65
  name = name.sub(/=$/, '_equals')
@@ -74,6 +74,8 @@ module ZenTestMapping
74
74
  # symbolic names which may have been anglicised by
75
75
  # #normal_to_test().
76
76
  def test_to_normal(name, klassname=nil)
77
+ name = name.to_s
78
+
77
79
  known_methods = (@inherited_methods[klassname] || {}).keys.sort.reverse
78
80
 
79
81
  mapped_re = @@orig_method_map.values.sort_by { |k| k.length }.map {|s| Regexp.escape(s)}.reverse.join("|")
@@ -269,6 +269,7 @@ test_error2(#{@test_class}):
269
269
  # non-rails
270
270
  util_path_to_classname 'TestBlah', 'test/test_blah.rb'
271
271
  util_path_to_classname 'TestOuter::TestInner', 'test/outer/test_inner.rb'
272
+ util_path_to_classname 'TestRuby2Ruby', 'test/test_ruby2ruby.rb'
272
273
  end
273
274
 
274
275
  def test_tests_for_file
@@ -2,7 +2,7 @@
2
2
  module ActionController; end
3
3
  module ActionController::Flash; end
4
4
  class ActionController::Flash::FlashHash < Hash; end
5
- class ActionController::TestSession; end
5
+ class ActionController::TestSession < Hash; end
6
6
 
7
7
  class ActionController::TestRequest
8
8
  attr_accessor :session
@@ -5,7 +5,7 @@ $TESTING_RTC = true
5
5
 
6
6
  module Rails
7
7
  module VERSION
8
- STRING = '99.99.99'
8
+ STRING = '99.99.99' unless defined? STRING # HACK
9
9
  end
10
10
  end
11
11
 
@@ -165,10 +165,10 @@ class TestRailsViewTestCase < Test::Rails::ViewTestCase
165
165
 
166
166
  assert_equal 2, @assert_select.length
167
167
 
168
- assert_equal ["select[name='game[location_id]'] option[value='2']",
169
- { :text => 'Guaymas' }], @assert_select.shift
170
- assert_equal ["select[name='game[location_id]'] option[value='1']",
171
- { :text => 'Ballet' }], @assert_select.shift
168
+ assert_include ["select[name='game[location_id]'] option[value='2']",
169
+ { :text => 'Guaymas' }], @assert_select
170
+ assert_include ["select[name='game[location_id]'] option[value='1']",
171
+ { :text => 'Ballet' }], @assert_select
172
172
  end
173
173
 
174
174
  def test_assert_select_tag_form
@@ -177,12 +177,12 @@ class TestRailsViewTestCase < Test::Rails::ViewTestCase
177
177
 
178
178
  assert_equal 4, @assert_select.length
179
179
 
180
- assert_equal ["form[action='/game/save']"], @assert_select.shift
181
- assert_equal ["select[name='game[location_id]'] option[value='2']",
182
- { :text => 'Guaymas' }], @assert_select.shift
183
- assert_equal ["form[action='/game/save']"], @assert_select.shift
184
- assert_equal ["select[name='game[location_id]'] option[value='1']",
185
- { :text => 'Ballet' }], @assert_select.shift
180
+ assert_include ["form[action='/game/save']"], @assert_select
181
+ assert_include ["select[name='game[location_id]'] option[value='2']",
182
+ { :text => 'Guaymas' }], @assert_select
183
+ assert_include ["form[action='/game/save']"], @assert_select
184
+ assert_include ["select[name='game[location_id]'] option[value='1']",
185
+ { :text => 'Ballet' }], @assert_select
186
186
  end
187
187
 
188
188
  def test_assert_submit
@@ -7,6 +7,10 @@ $TESTING = true
7
7
  # I do this so I can still run ZenTest against the tests and itself...
8
8
  require 'zentest' unless defined? $ZENTEST
9
9
 
10
+ class TrueClass # stupid YAML is breaking my tests. Enters via Test::Rails
11
+ remove_method :taguri, :taguri=, :to_yaml rescue nil
12
+ end
13
+
10
14
  # These are just classes set up for quick testing.
11
15
  # TODO: need to test a compound class name Mod::Cls
12
16
 
@@ -340,9 +344,24 @@ end
340
344
  assert_equal(expected, missing)
341
345
  end
342
346
 
347
+ def test_create_method
348
+ list = @tester.create_method(" ", 1, "wobble")
349
+ assert_equal([" def wobble(*args)",
350
+ " raise NotImplementedError, 'Need to write wobble'",
351
+ " end"],list)
352
+ end
353
+
354
+ def test_methods_and_tests
355
+ @tester.process_class("ZenTest")
356
+ @tester.process_class("TestZenTest")
357
+ m,t = @tester.methods_and_tests("ZenTest", "TestZenTest")
358
+ assert(m.include?("methods_and_tests"))
359
+ assert(t.include?("test_methods_and_tests"))
360
+ end
361
+
343
362
  def test_generate_code_simple
344
363
  self.util_simple_setup
345
-
364
+
346
365
  @tester.analyze
347
366
  str = @tester.generate_code[1..-1].join("\n")
348
367
  exp = @generated_code
@@ -367,6 +386,7 @@ end
367
386
 
368
387
  def test_get_inherited_methods_for_subclass_full
369
388
  expect = Object.instance_methods + %w( inherited overridden )
389
+ expect.map! { |m| m.to_s }
370
390
  result = @tester.get_inherited_methods_for("LowlyOne", true)
371
391
 
372
392
  assert_equal(expect.sort, result.keys.sort)
@@ -380,7 +400,7 @@ end
380
400
  end
381
401
 
382
402
  def test_get_inherited_methods_for_superclass_full
383
- expect = Object.instance_methods
403
+ expect = Object.instance_methods.map { |m| m.to_s }
384
404
  result = @tester.get_inherited_methods_for("SuperDuper", true)
385
405
 
386
406
  assert_equal(expect.sort, result.keys.sort)
@@ -5,9 +5,9 @@ $TESTING = true
5
5
  # I do this so I can still run ZenTest against the tests and itself...
6
6
  require 'zentest' unless defined? $ZENTEST
7
7
 
8
- class TestZenTestMapping < Test::Unit::TestCase
8
+ class TestZentestMapping < Test::Unit::TestCase
9
9
  def setup
10
- @tester = ZenTest.new # FIX: just inject the module
10
+ @tester = ZenTest.new
11
11
  end
12
12
 
13
13
  def util_simple_setup
metadata CHANGED
@@ -1,34 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: ZenTest
5
3
  version: !ruby/object:Gem::Version
6
- version: 3.6.1
7
- date: 2007-07-23 00:00:00 -07:00
8
- summary: "ZenTest provides 4 different tools and 1 library: zentest, unit_diff, autotest, multiruby, and Test::Rails."
9
- require_paths:
10
- - lib
11
- email: ryand-ruby@zenspider.com
12
- homepage: http://www.zenspider.com/ZSS/Products/ZenTest/
13
- rubyforge_project: zentest
14
- 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."
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 3.7.0
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Ryan Davis
31
8
  - Eric Hodel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2007-12-22 00:00:00 -08:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: hoe
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.4.0
24
+ version:
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
27
+ executables:
28
+ - autotest
29
+ - multiruby
30
+ - rails_test_audit
31
+ - unit_diff
32
+ - zentest
33
+ extensions: []
34
+
35
+ extra_rdoc_files:
36
+ - History.txt
37
+ - LinuxJournalArticle.txt
38
+ - Manifest.txt
39
+ - README.txt
40
+ - example.txt
32
41
  files:
33
42
  - History.txt
34
43
  - LinuxJournalArticle.txt
@@ -38,8 +47,6 @@ files:
38
47
  - bin/autotest
39
48
  - bin/multiruby
40
49
  - bin/rails_test_audit
41
- - bin/ruby_fork
42
- - bin/ruby_fork_client
43
50
  - bin/unit_diff
44
51
  - bin/zentest
45
52
  - example.txt
@@ -49,6 +56,7 @@ files:
49
56
  - lib/autotest.rb
50
57
  - lib/autotest/autoupdate.rb
51
58
  - lib/autotest/camping.rb
59
+ - lib/autotest/cctray.rb
52
60
  - lib/autotest/discover.rb
53
61
  - lib/autotest/emacs.rb
54
62
  - lib/autotest/fixtures.rb
@@ -67,7 +75,6 @@ files:
67
75
  - lib/autotest/snarl.rb
68
76
  - lib/autotest/timestamp.rb
69
77
  - lib/functional_test_matrix.rb
70
- - lib/ruby_fork.rb
71
78
  - lib/test/rails.rb
72
79
  - lib/test/rails/controller_test_case.rb
73
80
  - lib/test/rails/functional_test_case.rb
@@ -88,11 +95,37 @@ files:
88
95
  - test/test_rails_controller_test_case.rb
89
96
  - test/test_rails_helper_test_case.rb
90
97
  - test/test_rails_view_test_case.rb
91
- - test/test_ruby_fork.rb
92
98
  - test/test_unit_diff.rb
93
99
  - test/test_zentest.rb
94
100
  - test/test_zentest_assertions.rb
95
101
  - test/test_zentest_mapping.rb
102
+ has_rdoc: true
103
+ homepage: http://www.zenspider.com/ZSS/Products/ZenTest/
104
+ post_install_message:
105
+ rdoc_options:
106
+ - --main
107
+ - README.txt
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: "0"
115
+ version:
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: "0"
121
+ version:
122
+ requirements: []
123
+
124
+ rubyforge_project: zentest
125
+ rubygems_version: 1.0.1
126
+ signing_key:
127
+ specification_version: 2
128
+ summary: "ZenTest provides 4 different tools and 1 library: zentest, unit_diff, autotest, multiruby, and Test::Rails."
96
129
  test_files:
97
130
  - test/test_autotest.rb
98
131
  - test/test_help.rb
@@ -100,39 +133,7 @@ test_files:
100
133
  - test/test_rails_controller_test_case.rb
101
134
  - test/test_rails_helper_test_case.rb
102
135
  - test/test_rails_view_test_case.rb
103
- - test/test_ruby_fork.rb
104
136
  - test/test_unit_diff.rb
105
137
  - test/test_zentest.rb
106
138
  - test/test_zentest_assertions.rb
107
139
  - test/test_zentest_mapping.rb
108
- rdoc_options:
109
- - --main
110
- - README.txt
111
- extra_rdoc_files:
112
- - History.txt
113
- - LinuxJournalArticle.txt
114
- - Manifest.txt
115
- - README.txt
116
- - example.txt
117
- executables:
118
- - autotest
119
- - multiruby
120
- - rails_test_audit
121
- - ruby_fork
122
- - ruby_fork_client
123
- - unit_diff
124
- - zentest
125
- extensions: []
126
-
127
- requirements: []
128
-
129
- dependencies:
130
- - !ruby/object:Gem::Dependency
131
- name: hoe
132
- version_requirement:
133
- version_requirements: !ruby/object:Gem::Version::Requirement
134
- requirements:
135
- - - ">="
136
- - !ruby/object:Gem::Version
137
- version: 1.2.2
138
- version: