ZenTest 3.2.0 → 3.3.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.
Files changed (50) hide show
  1. data/History.txt +21 -0
  2. data/Manifest.txt +8 -24
  3. data/Rakefile +32 -8
  4. data/bin/autotest +4 -1
  5. data/bin/multiruby +20 -6
  6. data/bin/ruby_fork +6 -0
  7. data/bin/ruby_fork_client +6 -0
  8. data/example_dot_autotest.rb +148 -0
  9. data/lib/autotest.rb +201 -254
  10. data/lib/rails_autotest.rb +48 -110
  11. data/lib/ruby_fork.rb +178 -0
  12. data/lib/test/rails.rb +2 -2
  13. data/lib/test/rails/controller_test_case.rb +1 -1
  14. data/lib/test/rails/helper_test_case.rb +60 -0
  15. data/lib/test/rails/pp_html_document.rb +74 -0
  16. data/lib/test/rails/rake_tasks.rb +13 -12
  17. data/lib/test/rails/view_test_case.rb +2 -2
  18. data/lib/test/zentest_assertions.rb +39 -0
  19. data/lib/unit_diff.rb +6 -3
  20. data/lib/zentest.rb +1 -1
  21. data/test/test_autotest.rb +160 -208
  22. data/test/test_rails_autotest.rb +115 -138
  23. data/test/test_ruby_fork.rb +172 -0
  24. data/test/test_unit_diff.rb +69 -1
  25. data/test/test_zentest_assertions.rb +66 -0
  26. metadata +13 -27
  27. data/test/data/normal/lib/.#photo.rb +0 -0
  28. data/test/data/normal/lib/blah.rb +0 -0
  29. data/test/data/normal/lib/photo.rb +0 -0
  30. data/test/data/normal/test/#test_photo.rb# +0 -0
  31. data/test/data/normal/test/test_camelcase.rb +0 -0
  32. data/test/data/normal/test/test_photo.rb +0 -0
  33. data/test/data/normal/test/test_route.rb +0 -0
  34. data/test/data/normal/test/test_user.rb +0 -0
  35. data/test/data/rails/app/controllers/admin/theme_controller.rb +0 -0
  36. data/test/data/rails/app/controllers/route_controller.rb +0 -0
  37. data/test/data/rails/app/models/flickr_photo.rb +0 -0
  38. data/test/data/rails/app/models/route.rb +0 -0
  39. data/test/data/rails/app/views/route/index.rhtml +0 -0
  40. data/test/data/rails/config/environment.rb +0 -0
  41. data/test/data/rails/config/routes.rb +0 -0
  42. data/test/data/rails/test/controllers/route_controller_test.rb +0 -0
  43. data/test/data/rails/test/fixtures/routes.yml +0 -0
  44. data/test/data/rails/test/functional/admin/themes_controller_test.rb +0 -0
  45. data/test/data/rails/test/functional/dummy_controller_test.rb +0 -0
  46. data/test/data/rails/test/functional/route_controller_test.rb +0 -0
  47. data/test/data/rails/test/unit/flickr_photo_test.rb +0 -0
  48. data/test/data/rails/test/unit/photo_test.rb +0 -0
  49. data/test/data/rails/test/unit/route_test.rb +0 -0
  50. data/test/data/rails/test/views/route_view_test.rb +0 -0
@@ -1,3 +1,4 @@
1
+ require 'test/unit' if $0 == __FILE__
1
2
  require 'test_autotest'
2
3
  require 'rails_autotest'
3
4
 
@@ -6,190 +7,166 @@ class TestRailsAutotest < TestAutotest
6
7
  def setup
7
8
  super
8
9
 
9
- @at = RailsAutotest.new
10
+ @test_class = 'RouteTest'
11
+ @test = 'test/unit/route_test.rb'
12
+ @impl = 'app/models/route.rb'
10
13
 
11
- @rails_tests_dir = 'test/data/rails'
14
+ @rails_unit_tests = [@test]
12
15
 
13
- @rails_unit_tests = ['test/unit/route_test.rb']
16
+ @rails_controller_tests = %w(test/controllers/admin/themes_controller_test.rb
17
+ test/controllers/articles_controller_test.rb
18
+ test/controllers/dummy_controller_test.rb
19
+ test/controllers/route_controller_test.rb)
14
20
 
15
- @rails_controller_tests = [
16
- 'test/controllers/admin/themes_controller_test.rb',
17
- 'test/controllers/articles_controller_test.rb',
18
- 'test/controllers/dummy_controller_test.rb',
19
- 'test/controllers/route_controller_test.rb',
20
- ]
21
+ @rails_view_tests = %w(test/views/admin/themes_view_test.rb
22
+ test/views/articles_view_test.rb
23
+ test/views/layouts_view_test.rb
24
+ test/views/route_view_test.rb)
21
25
 
22
- @rails_view_tests = [
23
- 'test/views/admin/themes_view_test.rb',
24
- 'test/views/articles_view_test.rb',
25
- 'test/views/layouts_view_test.rb',
26
- 'test/views/route_view_test.rb',
27
- ]
28
-
29
- @rails_functional_tests = [
30
- 'test/functional/admin/themes_controller_test.rb',
31
- 'test/functional/articles_controller_test.rb',
32
- 'test/functional/dummy_controller_test.rb',
33
- 'test/functional/route_controller_test.rb',
34
- ]
26
+ @rails_functional_tests = %w(test/functional/admin/themes_controller_test.rb
27
+ test/functional/articles_controller_test.rb
28
+ test/functional/dummy_controller_test.rb
29
+ test/functional/route_controller_test.rb)
35
30
 
36
31
  # These files aren't put in @file_map, so add them to it
37
- @extra_files = [
38
- 'test/controllers/admin/themes_controller_test.rb',
39
- 'test/controllers/articles_controller_test.rb',
40
- 'test/controllers/dummy_controller_test.rb',
41
- 'test/views/admin/themes_view_test.rb',
42
- 'test/views/articles_view_test.rb',
43
- 'test/views/layouts_view_test.rb',
44
- 'test/functional/articles_controller_test.rb',
45
- 'test/functional/dummy_controller_test.rb',
46
- ]
32
+ @extra_files = %w(test/controllers/admin/themes_controller_test.rb
33
+ test/controllers/articles_controller_test.rb
34
+ test/controllers/dummy_controller_test.rb
35
+ test/functional/articles_controller_test.rb
36
+ test/functional/dummy_controller_test.rb
37
+ test/views/admin/themes_view_test.rb
38
+ test/views/articles_view_test.rb
39
+ test/views/layouts_view_test.rb)
40
+
41
+ @a.files.clear
42
+
43
+ (@rails_unit_tests +
44
+ @rails_controller_tests +
45
+ @rails_view_tests +
46
+ @rails_functional_tests +
47
+ @extra_files).flatten.each_with_index do |path, t|
48
+ @a.files[path] = Time.at(t+1)
49
+ end
50
+ @a.last_mtime = @a.files.values.sort.last
47
51
  end
48
52
 
49
- # Remove test_failed_test_files tests from RailsAutoTest because these
50
- # tests are regular-mode dependent.
51
- superclass.instance_methods.each do |meth|
52
- undef_method meth if meth =~ /^test_failed_test_files/
53
+ # Overridden from superclass... the scenario just doesn't happen the same way.
54
+ def test_consolidate_failures_multiple_matches
55
+ @test2 = 'test/unit/route_again_test.rb'
56
+ @a.files[@test2] = Time.at(42)
57
+ result = @a.consolidate_failures([['test_unmatched', @test_class]])
58
+ expected = {"test/unit/route_test.rb"=>["test_unmatched"]}
59
+ assert_equal expected, result
60
+ assert_equal '', @a.output.string
53
61
  end
54
62
 
55
- def test_map_file_names
56
- # util_add_map(sourcefile, unit_tests, controller_tests,
57
- # view_tests, functional_tsets)
63
+ def test_tests_for_file
64
+ empty = []
65
+ assert_equal empty, @a.tests_for_file('blah.rb')
66
+ assert_equal empty, @a.tests_for_file('test_blah.rb')
58
67
 
59
68
  # controllers
60
- util_add_map("app/controllers/admin/themes_controller.rb",
61
- [], ["test/controllers/admin/themes_controller_test.rb"],
62
- [], ["test/functional/admin/themes_controller_test.rb"])
69
+ util_tests_for_file('app/controllers/admin/themes_controller.rb',
70
+ 'test/controllers/admin/themes_controller_test.rb',
71
+ 'test/functional/admin/themes_controller_test.rb')
63
72
 
64
- util_add_map("app/controllers/application.rb",
65
- [], ["test/controllers/dummy_controller_test.rb"],
66
- [], ["test/functional/dummy_controller_test.rb"])
73
+ util_tests_for_file('app/controllers/application.rb',
74
+ 'test/controllers/dummy_controller_test.rb',
75
+ 'test/functional/dummy_controller_test.rb')
67
76
 
68
- util_add_map("app/controllers/route_controller.rb",
69
- [], ["test/controllers/route_controller_test.rb"],
70
- [], ["test/functional/route_controller_test.rb"])
77
+ util_tests_for_file('app/controllers/route_controller.rb',
78
+ 'test/controllers/route_controller_test.rb',
79
+ 'test/functional/route_controller_test.rb')
71
80
 
72
- util_add_map("app/controllers/notest_controller.rb")
81
+ util_tests_for_file('app/controllers/notest_controller.rb')
73
82
 
74
83
  # helpers
75
- util_add_map("app/helpers/application_helper.rb",
76
- [], [], @rails_view_tests, @rails_functional_tests)
84
+ util_tests_for_file('app/helpers/application_helper.rb',
85
+ @rails_view_tests + @rails_functional_tests)
77
86
 
78
- util_add_map("app/helpers/route_helper.rb",
79
- [], [], ["test/views/route_view_test.rb"],
80
- ["test/functional/route_controller_test.rb"])
87
+ util_tests_for_file('app/helpers/route_helper.rb',
88
+ 'test/views/route_view_test.rb',
89
+ 'test/functional/route_controller_test.rb')
81
90
 
82
91
  # model
83
- util_add_map("app/models/route.rb",
84
- ["test/unit/route_test.rb"], [], [], [])
92
+ util_tests_for_file('app/models/route.rb',
93
+ @test)
85
94
 
86
- util_add_map("app/models/notest.rb")
95
+ util_tests_for_file('app/models/notest.rb')
87
96
 
88
97
  # views
89
- util_add_map("app/views/layouts/default.rhtml", [], [],
90
- ["test/views/layouts_view_test.rb"], [])
98
+ util_tests_for_file('app/views/layouts/default.rhtml',
99
+ 'test/views/layouts_view_test.rb')
91
100
 
92
- util_add_map("app/views/route/index.rhtml",
93
- [], [], ["test/views/route_view_test.rb"],
94
- ["test/functional/route_controller_test.rb"])
101
+ util_tests_for_file('app/views/route/index.rhtml',
102
+ 'test/views/route_view_test.rb',
103
+ 'test/functional/route_controller_test.rb')
95
104
 
96
- util_add_map("app/views/route/xml.rxml",
97
- [], [], ["test/views/route_view_test.rb"],
98
- ["test/functional/route_controller_test.rb"])
105
+ util_tests_for_file('app/views/route/xml.rxml',
106
+ 'test/views/route_view_test.rb',
107
+ 'test/functional/route_controller_test.rb')
99
108
 
100
- util_add_map("app/views/shared/notest.rhtml")
109
+ util_tests_for_file('app/views/shared/notest.rhtml')
101
110
 
102
- util_add_map("app/views/articles/flag.rhtml",
103
- [], [], ["test/views/articles_view_test.rb"],
104
- ["test/functional/articles_controller_test.rb"])
111
+ util_tests_for_file('app/views/articles/flag.rhtml',
112
+ 'test/views/articles_view_test.rb',
113
+ 'test/functional/articles_controller_test.rb')
105
114
 
106
115
  # tests
107
- util_add_map("test/fixtures/routes.yml",
108
- ["test/unit/route_test.rb"],
109
- ["test/controllers/route_controller_test.rb"],
110
- ["test/views/route_view_test.rb"],
111
- ["test/functional/route_controller_test.rb"])
116
+ util_tests_for_file('test/fixtures/routes.yml',
117
+ @test,
118
+ 'test/controllers/route_controller_test.rb',
119
+ 'test/views/route_view_test.rb',
120
+ 'test/functional/route_controller_test.rb')
112
121
 
113
- util_add_map("test/test_helper.rb",
114
- @rails_unit_tests, @rails_controller_tests,
115
- @rails_view_tests, @rails_functional_tests)
122
+ util_tests_for_file('test/test_helper.rb',
123
+ @rails_unit_tests, @rails_controller_tests,
124
+ @rails_view_tests, @rails_functional_tests)
116
125
 
117
- util_add_map("test/unit/route_test.rb",
118
- ["test/unit/route_test.rb"], [], [], [])
126
+ util_tests_for_file(@test, @test)
119
127
 
120
- util_add_map("test/controllers/route_controller_test.rb",
121
- [], ["test/controllers/route_controller_test.rb"], [], [])
128
+ util_tests_for_file('test/controllers/route_controller_test.rb',
129
+ 'test/controllers/route_controller_test.rb')
122
130
 
123
- util_add_map("test/views/route_view_test.rb",
124
- [], [], ["test/views/route_view_test.rb"], [])
131
+ util_tests_for_file('test/views/route_view_test.rb',
132
+ 'test/views/route_view_test.rb')
125
133
 
126
- util_add_map("test/functional/route_controller_test.rb",
127
- [], [], [], ["test/functional/route_controller_test.rb"])
134
+ util_tests_for_file('test/functional/route_controller_test.rb',
135
+ 'test/functional/route_controller_test.rb')
128
136
 
129
- util_add_map("test/functional/admin/themes_controller_test.rb",
130
- [], [], [], ["test/functional/admin/themes_controller_test.rb"])
137
+ util_tests_for_file('test/functional/admin/themes_controller_test.rb',
138
+ 'test/functional/admin/themes_controller_test.rb')
131
139
 
132
140
  # global conf thingies
133
- util_add_map("config/boot.rb",
134
- @rails_unit_tests, @rails_controller_tests,
135
- @rails_view_tests, @rails_functional_tests)
141
+ util_tests_for_file('config/boot.rb',
142
+ @rails_unit_tests, @rails_controller_tests,
143
+ @rails_view_tests, @rails_functional_tests)
136
144
 
137
- util_add_map("config/database.yml",
138
- @rails_unit_tests, @rails_controller_tests,
139
- @rails_view_tests, @rails_functional_tests)
145
+ util_tests_for_file('config/database.yml',
146
+ @rails_unit_tests, @rails_controller_tests,
147
+ @rails_view_tests, @rails_functional_tests)
140
148
 
141
- util_add_map("config/environment.rb",
142
- @rails_unit_tests, @rails_controller_tests,
143
- @rails_view_tests, @rails_functional_tests)
149
+ util_tests_for_file('config/environment.rb',
150
+ @rails_unit_tests, @rails_controller_tests,
151
+ @rails_view_tests, @rails_functional_tests)
144
152
 
145
- util_add_map("config/environments/test.rb",
146
- @rails_unit_tests, @rails_controller_tests,
147
- @rails_view_tests, @rails_functional_tests)
153
+ util_tests_for_file('config/environments/test.rb',
154
+ @rails_unit_tests, @rails_controller_tests,
155
+ @rails_view_tests, @rails_functional_tests)
148
156
 
149
- util_add_map("config/routes.rb",
150
- [], @rails_controller_tests, @rails_view_tests,
151
- @rails_functional_tests)
157
+ util_tests_for_file('config/routes.rb',
158
+ @rails_controller_tests,
159
+ @rails_view_tests, @rails_functional_tests)
152
160
 
153
161
  # ignored crap
154
- util_add_map("vendor/plugins/cartographer/lib/keys.rb")
155
-
156
- util_add_map("Rakefile")
162
+ util_tests_for_file('vendor/plugins/cartographer/lib/keys.rb')
157
163
 
158
- (@file_map.keys + @extra_files).each { |file| @at.files[file] = Time.at 0 }
159
-
160
- util_test_map_file_names @rails_tests_dir
164
+ util_tests_for_file('Rakefile')
161
165
  end
162
166
 
163
- def test_updated_files_rails
164
- expected = [
165
- "app/controllers/admin/theme_controller.rb",
166
- "app/controllers/route_controller.rb",
167
- "app/models/flickr_photo.rb",
168
- "app/models/route.rb",
169
- "app/views/route/index.rhtml",
170
- "config/environment.rb",
171
- "config/routes.rb",
172
- "test/controllers/route_controller_test.rb",
173
- "test/fixtures/routes.yml",
174
- "test/functional/admin/themes_controller_test.rb",
175
- "test/functional/dummy_controller_test.rb",
176
- "test/functional/route_controller_test.rb",
177
- "test/unit/flickr_photo_test.rb",
178
- "test/unit/photo_test.rb",
179
- "test/unit/route_test.rb",
180
- "test/views/route_view_test.rb",
181
- ]
182
-
183
- Dir.chdir @rails_tests_dir do
184
- assert_equal expected, @at.updated_files.sort
185
- end
167
+ def util_tests_for_file(file, *expected)
168
+ assert_equal(expected.flatten.sort.uniq,
169
+ @a.tests_for_file(file).sort.uniq, "tests for #{file}")
186
170
  end
187
-
188
- def util_add_map(file, *tests)
189
- tests = [[], [], [], []] if tests.empty?
190
-
191
- super(file, *tests)
192
- end
193
-
194
171
  end
195
172
 
@@ -0,0 +1,172 @@
1
+ $TESTING = true
2
+
3
+ require 'test/unit'
4
+ require 'test/zentest_assertions'
5
+ require 'ruby_fork'
6
+
7
+ class TestRubyFork < Test::Unit::TestCase
8
+
9
+ def test_parse_client_args
10
+ expected = util_make_settings
11
+ settings = RubyFork.parse_client_args []
12
+ assert_equal expected, settings
13
+ end
14
+
15
+ def test_parse_client_args_help
16
+ util_capture do
17
+ assert_raises SystemExit do
18
+ RubyFork.parse_client_args ['-h']
19
+ end
20
+
21
+ assert_raises SystemExit do
22
+ RubyFork.parse_client_args ['--help']
23
+ end
24
+ end
25
+ end
26
+
27
+ def test_parse_client_args_port
28
+ expected = util_make_settings [], [], [], 5
29
+
30
+ settings = RubyFork.parse_client_args ['-p', '5']
31
+ assert_equal expected, settings
32
+
33
+ settings = RubyFork.parse_client_args ['--port', '5']
34
+ assert_equal expected, settings
35
+ end
36
+
37
+ def test_parse_server_args
38
+ settings = RubyFork.parse_server_args []
39
+ expected = util_make_settings nil, nil, nil, nil, false
40
+ assert_equal expected, settings
41
+ end
42
+
43
+ def test_parse_server_args_daemonize
44
+ expected = util_make_settings [], [], [], RubyFork::PORT, true
45
+
46
+ settings = RubyFork.parse_server_args ['-d']
47
+ assert_equal expected, settings
48
+
49
+ settings = RubyFork.parse_server_args ['--daemonize']
50
+ assert_equal expected, settings
51
+ end
52
+
53
+ def test_parse_server_args_execute
54
+ expected = util_make_settings [], ['foo']
55
+
56
+ settings = RubyFork.parse_server_args ['-e', 'foo']
57
+ assert_equal expected, settings
58
+
59
+ expected = util_make_settings [], ['foo', 'bar']
60
+
61
+ settings = RubyFork.parse_server_args ['-e', 'foo', '-e', 'bar']
62
+ assert_equal expected, settings
63
+ end
64
+
65
+ def test_parse_server_args_include
66
+ expected = util_make_settings nil, nil, ['lib'], nil, false
67
+
68
+ settings = RubyFork.parse_server_args ['-I', 'lib']
69
+ assert_equal expected, settings
70
+
71
+ expected = util_make_settings nil, nil, ['lib', 'test'], nil, false
72
+
73
+ settings = RubyFork.parse_server_args ['-I', 'lib', '-I', 'test']
74
+ assert_equal expected, settings
75
+
76
+ expected = util_make_settings nil, nil, ['lib:test'], nil, false
77
+
78
+ settings = RubyFork.parse_server_args ['-I', 'lib:test']
79
+ assert_equal expected, settings
80
+ end
81
+
82
+ def test_parse_server_args_help
83
+ util_capture do
84
+ assert_raises SystemExit do
85
+ RubyFork.parse_server_args ['-h']
86
+ end
87
+
88
+ assert_raises SystemExit do
89
+ RubyFork.parse_server_args ['--help']
90
+ end
91
+ end
92
+ end
93
+
94
+ def test_parse_server_args_port
95
+ expected = util_make_settings nil, nil, nil, 5, false
96
+
97
+ settings = RubyFork.parse_server_args ['-p', '5']
98
+ assert_equal expected, settings
99
+
100
+ settings = RubyFork.parse_server_args ['--port', '5']
101
+ assert_equal expected, settings
102
+ end
103
+
104
+ def test_parse_server_args_execute
105
+ expected = util_make_settings ['zentest'], nil, nil, nil, false
106
+
107
+ settings = RubyFork.parse_server_args ['-r', 'zentest']
108
+ assert_equal expected, settings
109
+
110
+ expected = util_make_settings ['zentest', 'unit_diff'], nil, nil, nil, false
111
+
112
+ settings = RubyFork.parse_server_args ['-r', 'zentest', '-r', 'unit_diff']
113
+ assert_equal expected, settings
114
+ end
115
+
116
+ def test_setup_environment_extra_paths
117
+ load_path = $LOAD_PATH.dup
118
+
119
+ RubyFork.setup_environment :extra_paths => ['no_such_dir'],
120
+ :requires => [], :code => []
121
+
122
+ assert_equal 'no_such_dir', $LOAD_PATH.first
123
+ ensure
124
+ $LOAD_PATH.replace load_path
125
+ end
126
+
127
+ def test_setup_environment_extra_paths_with_colon
128
+ load_path = $LOAD_PATH.dup
129
+
130
+ RubyFork.setup_environment :extra_paths => ['no_such_dir:other_bad_dir'],
131
+ :requires => [], :code => []
132
+
133
+ assert_equal 'other_bad_dir', $LOAD_PATH[0]
134
+ assert_equal 'no_such_dir', $LOAD_PATH[1]
135
+ ensure
136
+ $LOAD_PATH.replace load_path
137
+ end
138
+
139
+ def test_setup_environment_requires
140
+ assert_raises LoadError do
141
+ RubyFork.setup_environment :extra_paths => [],
142
+ :requires => ['no_such_file'], :code => []
143
+ end
144
+ end
145
+
146
+ def test_setup_environment_code
147
+ RubyFork.setup_environment :extra_paths => [],
148
+ :requires => [], :code => ['$trf_env_code = 0']
149
+
150
+ assert_equal 0, $trf_env_code
151
+ end
152
+
153
+ def util_make_settings(requires = nil, code = nil, extra_paths = nil,
154
+ port = nil, daemonize = nil)
155
+ settings = {
156
+ :requires => [],
157
+ :code => [],
158
+ :extra_paths => [],
159
+ :port => RubyFork::PORT,
160
+ }
161
+
162
+ settings[:code] = code unless code.nil?
163
+ settings[:daemonize] = daemonize unless daemonize.nil?
164
+ settings[:extra_paths] = extra_paths unless extra_paths.nil?
165
+ settings[:port] = port unless port.nil?
166
+ settings[:requires] = requires unless requires.nil?
167
+
168
+ return settings
169
+ end
170
+
171
+ end
172
+