ZenTest 3.1.0 → 3.2.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,15 @@
1
+ *** 3.2.0 / 2006-04-10
2
+
3
+ + 1 major enhancement:
4
+ + Added Test::Rails.
5
+ + 1 minor enhancement:
6
+ + Extended autotest for Test::Rails.
7
+ + 4 bug fixes:
8
+ + Autotest now detects changes in rhtml.
9
+ + Improved autotest's file mapping and choice of ruby.
10
+ + We've got RDoc, yes we do!
11
+ + Removed redundancies in rakefile. Using gem spec for most stuff now.
12
+
1
13
  *** 3.1.0 / 2006-03-29
2
14
 
3
15
  + 2 major enhancements
@@ -15,10 +27,10 @@
15
27
  + autotest can now run cvs/svn/p4 up periodically to be a mini-tinderbox.
16
28
  + autotest now has real help.
17
29
  + 4 bug fixes
18
- - ZenTest is now zentest. Yay for consistency! (do a rake uninstall to clean)
19
- - ZenTest excludes pretty_print methods.
20
- - Fixed unary operator issues (they were backwards... oops!) for ZenTest.
21
- - unit_diff now runs diff.exe on Windoze. dunno if that will work.
30
+ + ZenTest is now zentest. Yay for consistency! (do a rake uninstall to clean)
31
+ + ZenTest excludes pretty_print methods.
32
+ + Fixed unary operator issues (they were backwards... oops!) for ZenTest.
33
+ + unit_diff now runs diff.exe on Windoze. dunno if that will work.
22
34
 
23
35
  *** 3.0.0 / 2006-03-06
24
36
 
@@ -5,6 +5,7 @@ README.txt
5
5
  Rakefile
6
6
  bin/autotest
7
7
  bin/multiruby
8
+ bin/rails_test_audit
8
9
  bin/unit_diff
9
10
  bin/zentest
10
11
  example.txt
@@ -12,11 +13,20 @@ example1.rb
12
13
  example2.rb
13
14
  lib/autotest.rb
14
15
  lib/rails_autotest.rb
16
+ lib/test/rails.rb
17
+ lib/test/rails/controller_test_case.rb
18
+ lib/test/rails/functional_test_case.rb
19
+ lib/test/rails/ivar_proxy.rb
20
+ lib/test/rails/rake_tasks.rb
21
+ lib/test/rails/test_case.rb
22
+ lib/test/rails/view_test_case.rb
23
+ lib/test/zentest_assertions.rb
15
24
  lib/unit_diff.rb
16
25
  lib/zentest.rb
17
26
  test/data/normal/lib/.#photo.rb
18
27
  test/data/normal/lib/blah.rb
19
28
  test/data/normal/lib/photo.rb
29
+ test/data/normal/test/#test_photo.rb#
20
30
  test/data/normal/test/test_camelcase.rb
21
31
  test/data/normal/test/test_photo.rb
22
32
  test/data/normal/test/test_route.rb
@@ -25,8 +35,10 @@ test/data/rails/app/controllers/admin/theme_controller.rb
25
35
  test/data/rails/app/controllers/route_controller.rb
26
36
  test/data/rails/app/models/flickr_photo.rb
27
37
  test/data/rails/app/models/route.rb
38
+ test/data/rails/app/views/route/index.rhtml
28
39
  test/data/rails/config/environment.rb
29
40
  test/data/rails/config/routes.rb
41
+ test/data/rails/test/controllers/route_controller_test.rb
30
42
  test/data/rails/test/fixtures/routes.yml
31
43
  test/data/rails/test/functional/admin/themes_controller_test.rb
32
44
  test/data/rails/test/functional/dummy_controller_test.rb
@@ -34,6 +46,7 @@ test/data/rails/test/functional/route_controller_test.rb
34
46
  test/data/rails/test/unit/flickr_photo_test.rb
35
47
  test/data/rails/test/unit/photo_test.rb
36
48
  test/data/rails/test/unit/route_test.rb
49
+ test/data/rails/test/views/route_view_test.rb
37
50
  test/test_autotest.rb
38
51
  test/test_rails_autotest.rb
39
52
  test/test_unit_diff.rb
data/README.txt CHANGED
@@ -5,7 +5,8 @@
5
5
 
6
6
  == DESCRIPTION
7
7
 
8
- ZenTest provides 3 different tools: zentest, unit_diff, and autotest.
8
+ ZenTest provides 4 different tools and 1 library: zentest, unit_diff,
9
+ autotest, multiruby, and Test::Rails.
9
10
 
10
11
  ZenTest scans your target and unit-test code and writes your missing
11
12
  code based on simple naming rules, enabling XP at a much quicker
@@ -21,7 +22,11 @@ corresponding dependent tests.
21
22
  multiruby runs anything you want on multiple versions of ruby. Great
22
23
  for compatibility checking!
23
24
 
24
- There are two strategies intended for ZenTest: test conformance
25
+ Test::Rails helps you build industrial-strength Rails code.
26
+
27
+ == STRATEGERY
28
+
29
+ There are two strategeries intended for ZenTest: test conformance
25
30
  auditing and rapid XP.
26
31
 
27
32
  For auditing, ZenTest provides an excellent means of finding methods
@@ -33,15 +38,16 @@ ZenTest can also be used to evaluate generated code and execute your
33
38
  tests, allowing for very rapid development of both tests and
34
39
  implementation.
35
40
 
36
- == FEATURES/PROBLEMS
41
+ == FEATURES
37
42
 
38
43
  * Scans your ruby code and tests and generates missing methods for you.
39
44
  * Includes a very helpful filter for Test::Unit output called unit_diff.
40
45
  * Continually and intelligently test only those files you change with autotest.
41
46
  * Test against multiple versions with multiruby.
42
- - Not the best doco in the world (my fault)
47
+ * Enhance and automatically audit your rails tests using Test::Rails.
43
48
  * Includes a LinuxJournal article on testing with ZenTest written by Pat Eyler.
44
49
  * See also: http://blog.zenspider.com/archives/zentest/
50
+ * See also: http://blog.segment7.net/articles/category/zentest
45
51
 
46
52
  == SYNOPSYS
47
53
 
@@ -53,46 +59,7 @@ implementation.
53
59
 
54
60
  multiruby ./TestMyProject.rb
55
61
 
56
- == RULES
57
-
58
- ZenTest uses the following rules to figure out what code should be
59
- generated:
60
-
61
- * Definition:
62
- * CUT = Class Under Test
63
- * TC = Test Class (for CUT)
64
- * TC's name is the same as CUT w/ "Test" prepended at every scope level.
65
- * Example: TestA::TestB vs A::B.
66
- * CUT method names are used in CT, with "test_" prependend and optional "_ext" extensions for differentiating test case edge boundaries.
67
- * Example:
68
- * A::B#blah
69
- * TestA::TestB#test_blah_normal
70
- * TestA::TestB#test_blah_missing_file
71
- * All naming conventions are bidirectional with the exception of test extensions.
72
-
73
- == METHOD MAPPING
74
-
75
- Method names are mapped bidirectionally in the following way:
76
-
77
- method test_method
78
- method? test_method_eh (too much exposure to Canadians :)
79
- method! test_method_bang
80
- method= test_method_equals
81
- [] test_index
82
- * test_times
83
- == test_equals2
84
- === test_equals3
85
-
86
- Further, any of the test methods should be able to have arbitrary
87
- extensions put on the name to distinguish edge cases:
88
-
89
- method test_method
90
- method test_method_simple
91
- method test_method_no_network
92
-
93
- To allow for unmapped test methods (ie, non-unit tests), name them:
94
-
95
- test_integration_.*
62
+ (and other stuff for Test::Rails)
96
63
 
97
64
  == REQUIREMENTS
98
65
 
@@ -102,8 +69,14 @@ To allow for unmapped test methods (ie, non-unit tests), name them:
102
69
 
103
70
  == INSTALL
104
71
 
105
- * make test
106
- * sudo make install
72
+ Using Rubygems:
73
+
74
+ * sudo gem install ZenTest
75
+
76
+ Using Rake:
77
+
78
+ * rake test
79
+ * sudo rake install
107
80
 
108
81
  == LICENSE
109
82
 
data/Rakefile CHANGED
@@ -16,25 +16,35 @@ spec = Gem::Specification.new do |s|
16
16
  s.authors = ['Ryan Davis', 'Eric Hodel']
17
17
  s.email = 'ryand-ruby@zenspider.com'
18
18
 
19
- s.files = File.read('Manifest.txt').split($/)
19
+ s.files = IO.readlines("Manifest.txt").map {|f| f.chomp }
20
20
  s.require_path = 'lib'
21
- s.executables = %w[ZenTest unit_diff autotest multiruby]
21
+
22
+ s.executables = s.files.grep(/^bin\//).map { |f| File.basename f }
22
23
 
23
24
  paragraphs = File.read("README.txt").split(/\n\n+/)
24
- s.instance_variable_set "@description", paragraphs[3..9].join("\n\n")
25
- s.instance_variable_set "@summary", paragraphs[11]
25
+ s.instance_variable_set "@description", paragraphs[3..10].join("\n\n")
26
+ s.instance_variable_set "@summary", paragraphs[12]
26
27
 
27
28
  if $DEBUG then
28
29
  puts "ZenTest #{s.version}"
29
30
  puts
31
+ puts s.executables.sort.inspect
32
+ puts
33
+ puts "** summary:"
30
34
  puts s.summary
31
35
  puts
36
+ puts "** description:"
32
37
  puts s.description
33
38
  end
34
39
 
35
- s.files = IO.readlines("Manifest.txt").map {|f| f.chomp }
36
40
  s.homepage = "http://www.zenspider.com/ZSS/Products/ZenTest/"
37
41
  s.rubyforge_project = "zentest"
42
+ s.has_rdoc = true
43
+ end
44
+
45
+ desc 'Build Gem'
46
+ Rake::GemPackageTask.new spec do |pkg|
47
+ pkg.need_tar = true
38
48
  end
39
49
 
40
50
  desc 'Run tests'
@@ -57,19 +67,19 @@ Rake::RDocTask.new :rdoc do |rd|
57
67
  rd.rdoc_files.add 'lib', 'README.txt', 'History.txt', 'LinuxJournalArticle.txt'
58
68
  rd.main = 'README.txt'
59
69
  rd.options << '-d' if `which dot` =~ /\/dot/ unless RUBY_PLATFORM =~ /win32/
60
- rd.options << '-t "ZenTest RDoc"'
61
- end
62
-
63
- desc 'Build Gem'
64
- Rake::GemPackageTask.new spec do |pkg|
65
- pkg.need_tar = true
70
+ rd.options << '-t ZenTest RDoc'
66
71
  end
67
72
 
68
73
  $prefix = ENV['PREFIX'] || Config::CONFIG['prefix']
69
74
  $bin = File.join($prefix, 'bin')
70
75
  $lib = Config::CONFIG['sitelibdir']
71
- $bins = %w(zentest autotest unit_diff multiruby)
72
- $libs = %w(zentest.rb autotest.rb rails_autotest.rb unit_diff.rb)
76
+ $bins = spec.executables
77
+ $libs = spec.files.grep(/^lib\//).map { |f| f.sub(/^lib\//, '') }.sort
78
+
79
+ task :blah do
80
+ p $bins
81
+ p $libs
82
+ end
73
83
 
74
84
  task :install do
75
85
  $bins.each do |f|
@@ -77,7 +87,9 @@ task :install do
77
87
  end
78
88
 
79
89
  $libs.each do |f|
80
- install File.join("lib", f), $lib, :mode => 0444
90
+ dir = File.join($lib, File.dirname(f))
91
+ mkdir_p dir unless test ?d, dir
92
+ install File.join("lib", f), dir, :mode => 0444
81
93
  end
82
94
  end
83
95
 
@@ -93,9 +105,14 @@ task :uninstall do
93
105
  $libs.each do |f|
94
106
  rm_f File.join($lib, f)
95
107
  end
108
+
109
+ rm_rf File.join($lib, "test")
96
110
  end
97
111
 
98
112
  desc 'Clean up'
99
113
  task :clean => [ :clobber_rdoc, :clobber_package ] do
100
114
  rm_f Dir["**/*~"]
101
115
  end
116
+
117
+ # vim:syntax=ruby
118
+
@@ -0,0 +1,80 @@
1
+ #!/usr/local/bin/ruby -w
2
+
3
+ # TODO: Probably has dup code with ZenTest.
4
+ # TODO: Map controller assert_assigns to view test ivar assignments.
5
+ # TODO: Make this a rake task, rake test:audit.
6
+
7
+ # test_cases[test_case][test][ivar] = value
8
+ def build_test_cases(type)
9
+ test_cases = Hash.new { |h,k|
10
+ h[k] = Hash.new { |h,k|
11
+ h[k] = Hash.new { |h,k|
12
+ h[k] = {} } } }
13
+
14
+ test_case = nil
15
+ test = nil
16
+
17
+ fixtures = Hash.new { |h,k| h[k] = [] }
18
+
19
+ Dir["test/#{type}/*rb"].each do |test|
20
+ File.open test do |fp|
21
+ fp.each_line do |line|
22
+ case line
23
+ when /^class (.*)(View|Controller)Test </
24
+ test_case = $1
25
+ when /^\s+def (test_\S+)/
26
+ test = $1
27
+ when /^\s+controller\[(.+?)\] = (.*)$/,
28
+ /^\s+assert_assigned (.*?), (.*)/
29
+ ivar = $1
30
+ value = $2
31
+ test_cases[test_case][test][ivar] = value
32
+ when /fixtures (.*)/ then
33
+ fixtures[test_case].push(*$1.split(', '))
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ return test_cases, fixtures
40
+ end
41
+
42
+ view_test_cases, view_fixtures = build_test_cases 'views'
43
+ controller_test_cases, controller_fixtures = build_test_cases 'controller'
44
+
45
+ out = []
46
+
47
+ view_test_cases.sort_by { |tc,_| tc }.each do |test_case, tests|
48
+ out << "require 'test/test_helper'"
49
+ out << nil
50
+ out << "class #{test_case}ControllerTest < Test::Rails::ControllerTestCase"
51
+ out << nil
52
+
53
+ fixtures = controller_fixtures[test_case] - view_fixtures[test_case]
54
+
55
+ unless fixtures.empty? then
56
+ fixtures.each do |fixture|
57
+ out << " fixtures #{fixture}"
58
+ end
59
+ out << nil
60
+ end
61
+
62
+ tests.sort_by { |t,_| t }.each do |test, ivars|
63
+ ivars = view_test_cases[test_case][test].keys -
64
+ controller_test_cases[test_case][test].keys
65
+
66
+ next if ivars.empty?
67
+
68
+ out << " def #{test}"
69
+ ivars.sort.each do |ivar|
70
+ value = view_test_cases[test_case][test][ivar]
71
+ out << " assert_assigned #{ivar}, #{value}"
72
+ end
73
+ out << " end"
74
+ out << nil
75
+ end
76
+ out << "end"
77
+ out << nil
78
+ end
79
+
80
+ puts out.join("\n")
@@ -15,18 +15,17 @@
15
15
  # -v display version
16
16
 
17
17
  require 'unit_diff'
18
+ require 'zentest'
18
19
 
19
20
  ############################################################
20
21
 
21
- UNIT_DIFF_VERSION = '1.1.0'
22
-
23
22
  if defined? $v then
24
- puts "#{File.basename $0} v. #{UNIT_DIFF_VERSION}"
25
- exit
23
+ puts "#{File.basename $0} v. #{ZenTest::VERSION}"
24
+ exit 0
26
25
  end
27
26
 
28
27
  if defined? $h then
29
- File.open(File.basename($0)) do |f|
28
+ File.open($0) do |f|
30
29
  begin; end until f.readline =~ /usage:/
31
30
  f.readline
32
31
  while line = f.readline and line.sub!(/^# ?/, '')
@@ -37,4 +36,3 @@ if defined? $h then
37
36
  end
38
37
 
39
38
  puts UnitDiff.unit_diff(ARGF)
40
-
@@ -1,6 +1,7 @@
1
1
  $TESTING = defined? $TESTING
2
2
 
3
3
  require 'find'
4
+ require 'rbconfig'
4
5
 
5
6
  ##
6
7
  # Autotest continuously runs your tests as you work on your project.
@@ -21,7 +22,7 @@ require 'find'
21
22
  # * Implementation files must be stored in lib/
22
23
  # * Implementation files must match up with a test file named
23
24
  # test_.*implementation.rb
24
-
25
+ #--
25
26
  # New (proposed) strategy:
26
27
  #
27
28
  # 1) find all files and associate them from impl <-> test
@@ -62,7 +63,7 @@ class Autotest
62
63
  end
63
64
 
64
65
  return filters.map do |klass, methods|
65
- ["'/^(#{methods.join('|')})/'", /#{klass}/]
66
+ ["'/^(#{methods.join('|')})$/'", /#{klass}/]
66
67
  end
67
68
  end
68
69
 
@@ -175,7 +176,7 @@ class Autotest
175
176
  puts "# Rerunning failures: #{failed_files.join ' '}"
176
177
 
177
178
  test_filter = " -n #{filter}" unless filter == "'/^(default_test)/'"
178
- cmd = "ruby -Ilib:test #{failed_files.join ' '}#{test_filter} | unit_diff -u"
179
+ cmd = "#{ruby} -Ilib:test #{failed_files.join ' '}#{test_filter} | unit_diff -u"
179
180
 
180
181
  puts "+ #{cmd}"
181
182
  result = `#{cmd}`
@@ -190,6 +191,14 @@ class Autotest
190
191
  end
191
192
  end
192
193
 
194
+ ##
195
+ # The path to this ruby for running tests.
196
+
197
+ def ruby
198
+ return File.join(Config::CONFIG['bindir'],
199
+ Config::CONFIG['ruby_install_name'])
200
+ end
201
+
193
202
  ##
194
203
  # Repeatedly scans for updated files and runs their tests.
195
204
 
@@ -248,7 +257,7 @@ class Autotest
248
257
  map_file_names(updated).each do |tests|
249
258
  next if tests.empty?
250
259
  puts '# Testing updated files'
251
- cmd = "ruby -Ilib:test -e '#{tests.inspect}.each { |f| load f }' | unit_diff -u"
260
+ cmd = "#{ruby} -Ilib:test -e '#{tests.inspect}.each { |f| load f }' | unit_diff -u"
252
261
  puts "+ #{cmd}"
253
262
  results = `#{cmd}`
254
263
  puts results
@@ -274,12 +283,16 @@ class Autotest
274
283
 
275
284
  # REFACTOR: I don't think the two routines merit real differences
276
285
  retest_failed failed, tests
277
- end
278
286
 
279
- reset_times if ever_failed
287
+ break
288
+ end
280
289
 
281
- puts '# All passed'
282
- puts "# Waiting for changes"
290
+ if ever_failed
291
+ reset_times
292
+ else # We'll immediately test everything, so don't print this out.
293
+ puts '# All passed'
294
+ puts "# Waiting for changes"
295
+ end
283
296
 
284
297
  return ever_failed
285
298
  end
@@ -304,7 +317,6 @@ class Autotest
304
317
  updated = []
305
318
 
306
319
  Find.find '.' do |f|
307
-
308
320
  if @exceptions then
309
321
  if f =~ @exceptions then
310
322
  Find.prune if Kernel.test ?d, f
@@ -316,7 +328,7 @@ class Autotest
316
328
 
317
329
  next if File.directory? f
318
330
  next if f =~ /(?:swp|~|rej|orig)$/ # temporary/patch files
319
- next if f =~ /\/\.#/ # Emacs autosave/cvs merge files
331
+ next if f =~ /\/\.?#/ # Emacs autosave/cvs merge files
320
332
 
321
333
  f = f.sub(/^\.\//, '')
322
334