Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 502 lines (404 sloc) 12.309 kb
cbce3c7 Eric Hodel Make test file requires directory independent
drbrain authored
1 require File.expand_path('../helper', __FILE__)
c8197eb added rcov and unit tests
jimweirich authored
2
0534fa5 Eric Hodel Tests now inherit from Rake::TestCase instead of Test::Unit::TestCase so...
drbrain authored
3 class TestRakeApplication < Rake::TestCase
c8197eb added rcov and unit tests
jimweirich authored
4
5 def setup
43f2ec6 Jim Weirich Cleanup up tests. Added prereq and timestamp tests.
authored
6 super
cbce3c7 Eric Hodel Make test file requires directory independent
drbrain authored
7
8f02e23 Eric Hodel Rake tests now create all files in a temporary directory
drbrain authored
8 @app = Rake.application
991f432 Ruby 1.9 commit
jimweirich authored
9 @app.options.rakelib = []
43f2ec6 Jim Weirich Cleanup up tests. Added prereq and timestamp tests.
authored
10 end
c8197eb added rcov and unit tests
jimweirich authored
11
12 def test_constant_warning
0dba7c9 Eric Hodel Switch rake's tests to minitest
drbrain authored
13 _, err = capture_io do @app.instance_eval { const_warning("Task") } end
14 assert_match(/warning/i, err)
15 assert_match(/deprecated/i, err)
16 assert_match(/Task/i, err)
c8197eb added rcov and unit tests
jimweirich authored
17 end
18
19 def test_display_tasks
6f8b9a0 Jim Weirich Show tasks using :tasks
authored
20 @app.options.show_tasks = :tasks
c8197eb added rcov and unit tests
jimweirich authored
21 @app.options.show_task_pattern = //
d1f89d7 added task parameters, named parameter via desc, column limited output
jimweirich authored
22 @app.last_description = "COMMENT"
c8197eb added rcov and unit tests
jimweirich authored
23 @app.define_task(Rake::Task, "t")
0dba7c9 Eric Hodel Switch rake's tests to minitest
drbrain authored
24 out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
c8197eb added rcov and unit tests
jimweirich authored
25 assert_match(/^rake t/, out)
26 assert_match(/# COMMENT/, out)
27 end
28
e462afc Changes to get 100% code coverage in main rake.rb file.
jimweirich authored
29 def test_display_tasks_with_long_comments
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
30 @app.terminal_columns = 80
31 @app.options.show_tasks = :tasks
32 @app.options.show_task_pattern = //
33 @app.last_description = "1234567890" * 8
34 @app.define_task(Rake::Task, "t")
35
36 out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
37
38 assert_match(/^rake t/, out)
39 assert_match(/# 12345678901234567890123456789012345678901234567890123456789012345\.\.\./, out)
e462afc Changes to get 100% code coverage in main rake.rb file.
jimweirich authored
40 end
41
fba0457 Adding support to output full descriptions when not outputting to a TTY....
Gavin Stark authored
42 def test_display_tasks_with_task_name_wider_than_tty_display
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
43 @app.terminal_columns = 80
44 @app.options.show_tasks = :tasks
45 @app.options.show_task_pattern = //
46 task_name = "task name" * 80
47 @app.last_description = "something short"
48 @app.define_task(Rake::Task, task_name )
49
50 out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
51
52 # Ensure the entire task name is output and we end up showing no description
53 assert_match(/rake #{task_name} # .../, out)
fba0457 Adding support to output full descriptions when not outputting to a TTY....
Gavin Stark authored
54 end
55
56 def test_display_tasks_with_very_long_task_name_to_a_non_tty_shows_name_and_comment
6f8b9a0 Jim Weirich Show tasks using :tasks
authored
57 @app.options.show_tasks = :tasks
fba0457 Adding support to output full descriptions when not outputting to a TTY....
Gavin Stark authored
58 @app.options.show_task_pattern = //
59 @app.tty_output = false
60 description = "something short"
61 task_name = "task name" * 80
62 @app.last_description = "something short"
63 @app.define_task(Rake::Task, task_name )
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
64
0dba7c9 Eric Hodel Switch rake's tests to minitest
drbrain authored
65 out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
66
fba0457 Adding support to output full descriptions when not outputting to a TTY....
Gavin Stark authored
67 # Ensure the entire task name is output and we end up showing no description
68 assert_match(/rake #{task_name} # #{description}/, out)
69 end
70
71 def test_display_tasks_with_long_comments_to_a_non_tty_shows_entire_comment
6f8b9a0 Jim Weirich Show tasks using :tasks
authored
72 @app.options.show_tasks = :tasks
fba0457 Adding support to output full descriptions when not outputting to a TTY....
Gavin Stark authored
73 @app.options.show_task_pattern = //
74 @app.tty_output = false
75 @app.last_description = "1234567890" * 8
76 @app.define_task(Rake::Task, "t")
0dba7c9 Eric Hodel Switch rake's tests to minitest
drbrain authored
77 out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
fba0457 Adding support to output full descriptions when not outputting to a TTY....
Gavin Stark authored
78 assert_match(/^rake t/, out)
79 assert_match(/# #{@app.last_description}/, out)
f8a729b Updating based on feedback from Jim regarding Emacs command window not b...
Gavin Stark authored
80 end
81
82 def test_display_tasks_with_long_comments_to_a_non_tty_with_columns_set_truncates_comments
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
83 @app.terminal_columns = 80
84 @app.options.show_tasks = :tasks
85 @app.options.show_task_pattern = //
86 @app.tty_output = false
87 @app.last_description = "1234567890" * 8
88 @app.define_task(Rake::Task, "t")
89
90 out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
91
92 assert_match(/^rake t/, out)
93 assert_match(/# 12345678901234567890123456789012345678901234567890123456789012345\.\.\./, out)
fba0457 Adding support to output full descriptions when not outputting to a TTY....
Gavin Stark authored
94 end
95
e98aa21 Jim Weirich Changing show tasks.
authored
96 def test_describe_tasks
d8090fd Jim Weirich Fixed tests for show_tasks changes.
authored
97 @app.options.show_tasks = :describe
e462afc Changes to get 100% code coverage in main rake.rb file.
jimweirich authored
98 @app.options.show_task_pattern = //
99 @app.last_description = "COMMENT"
100 @app.define_task(Rake::Task, "t")
0dba7c9 Eric Hodel Switch rake's tests to minitest
drbrain authored
101 out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
e462afc Changes to get 100% code coverage in main rake.rb file.
jimweirich authored
102 assert_match(/^rake t$/, out)
103 assert_match(/^ {4}COMMENT$/, out)
104 end
105
a483460 Jim Weirich Added line number stuff (in progress)
authored
106 def test_show_lines
107 @app.options.show_tasks = :lines
108 @app.options.show_task_pattern = //
109 @app.last_description = "COMMENT"
110 @app.define_task(Rake::Task, "t")
89bc2c1 Jim Weirich Added line number recording to task definition.
authored
111 @app['t'].locations << "HERE:1"
0dba7c9 Eric Hodel Switch rake's tests to minitest
drbrain authored
112 out, = capture_io do @app.instance_eval { display_tasks_and_comments } end
89bc2c1 Jim Weirich Added line number recording to task definition.
authored
113 assert_match(/^rake t +[^:]+:\d+ *$/, out)
a483460 Jim Weirich Added line number stuff (in progress)
authored
114 end
115
c8197eb added rcov and unit tests
jimweirich authored
116 def test_finding_rakefile
2f25507 Eric Hodel Make fileutils tests be non-directory-dependent
drbrain authored
117 rakefile_default
118
23275bc Luis Lavena Really make matching of Rakefile case insensitive.
luislavena authored
119 assert_match(/Rakefile/i, @app.instance_eval { have_rakefile })
c8197eb added rcov and unit tests
jimweirich authored
120 end
121
122 def test_not_finding_rakefile
123 @app.instance_eval { @rakefiles = ['NEVER_FOUND'] }
9bb3cb2 Changes for Rake 0.7 3
jimweirich authored
124 assert( ! @app.instance_eval do have_rakefile end )
c8197eb added rcov and unit tests
jimweirich authored
125 assert_nil @app.rakefile
126 end
127
128 def test_load_rakefile
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
129 rakefile_unittest
130
131 @app.instance_eval do
132 handle_options
133 options.silent = true
134 load_rakefile
9bb3cb2 Changes for Rake 0.7 3
jimweirich authored
135 end
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
136
137 assert_equal "rakefile", @app.rakefile.downcase
138 assert_equal @tempdir, Dir.pwd
c8197eb added rcov and unit tests
jimweirich authored
139 end
140
6632653 Alex Chaffee don't print the rakefile directory message if it's in the same directory...
alexch authored
141 def test_load_rakefile_doesnt_print_rakefile_directory_from_same_dir
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
142 rakefile_unittest
143
144 _, err = capture_io do
145 @app.instance_eval do
146 # pretend we started from the unittest dir
147 @original_dir = File.expand_path(".")
148 raw_load_rakefile
6632653 Alex Chaffee don't print the rakefile directory message if it's in the same directory...
alexch authored
149 end
150 end
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
151
164bd2f Eric Hodel Fix failures on 1.8 and warnings on 1.9.3
drbrain authored
152 assert_empty err
6632653 Alex Chaffee don't print the rakefile directory message if it's in the same directory...
alexch authored
153 end
154
c8197eb added rcov and unit tests
jimweirich authored
155 def test_load_rakefile_from_subdir
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
156 rakefile_unittest
157 Dir.chdir 'subdir'
158
159 @app.instance_eval do
160 handle_options
161 options.silent = true
162 load_rakefile
9bb3cb2 Changes for Rake 0.7 3
jimweirich authored
163 end
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
164
165 assert_equal "rakefile", @app.rakefile.downcase
166 assert_equal @tempdir, Dir.pwd
c8197eb added rcov and unit tests
jimweirich authored
167 end
168
6632653 Alex Chaffee don't print the rakefile directory message if it's in the same directory...
alexch authored
169 def test_load_rakefile_prints_rakefile_directory_from_subdir
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
170 rakefile_unittest
171 Dir.chdir 'subdir'
172
8f02e23 Eric Hodel Rake tests now create all files in a temporary directory
drbrain authored
173 app = Rake::Application.new
174 app.options.rakelib = []
175
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
176 _, err = capture_io do
8f02e23 Eric Hodel Rake tests now create all files in a temporary directory
drbrain authored
177 app.instance_eval do
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
178 raw_load_rakefile
6632653 Alex Chaffee don't print the rakefile directory message if it's in the same directory...
alexch authored
179 end
180 end
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
181
182 assert_equal "(in #{@tempdir}\)\n", err
6632653 Alex Chaffee don't print the rakefile directory message if it's in the same directory...
alexch authored
183 end
184
185 def test_load_rakefile_doesnt_print_rakefile_directory_from_subdir_if_silent
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
186 rakefile_unittest
187 Dir.chdir 'subdir'
6632653 Alex Chaffee don't print the rakefile directory message if it's in the same directory...
alexch authored
188
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
189 _, err = capture_io do
4b4bce1 Jim Weirich added in_environment for easier environment modification testing.
authored
190 @app.instance_eval do
191 handle_options
192 options.silent = true
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
193 raw_load_rakefile
4b4bce1 Jim Weirich added in_environment for easier environment modification testing.
authored
194 end
9bb3cb2 Changes for Rake 0.7 3
jimweirich authored
195 end
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
196
164bd2f Eric Hodel Fix failures on 1.8 and warnings on 1.9.3
drbrain authored
197 assert_empty err
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
198 end
199
200 def test_load_rakefile_not_found
201 Dir.chdir @tempdir
202 ENV['RAKE_SYSTEM'] = 'not_exist'
203
204 @app.instance_eval do
205 handle_options
206 options.silent = true
207 end
208
209 ex = assert_raises(RuntimeError) do
210 @app.instance_eval do raw_load_rakefile end
211 end
212
213 assert_match(/no rakefile found/i, ex.message)
c8197eb added rcov and unit tests
jimweirich authored
214 end
215
2da66fd Jim Weirich partial implementation of system rakefiles
authored
216 def test_load_from_system_rakefile
a119d1b Eric Hodel Remove in_environment from test/test_rake_task_argument_parsing.rb
drbrain authored
217 rake_system_dir
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
218
219 @app.instance_eval do
220 handle_options
221 options.silent = true
222 options.load_system = true
223 options.rakelib = []
224 load_rakefile
2da66fd Jim Weirich partial implementation of system rakefiles
authored
225 end
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
226
227 assert_equal @system_dir, @app.system_dir
228 assert_nil @app.rakefile
8f02e23 Eric Hodel Rake tests now create all files in a temporary directory
drbrain authored
229 rescue SystemExit
230 flunk 'failed to load rakefile'
2da66fd Jim Weirich partial implementation of system rakefiles
authored
231 end
232
02e7bbb Jim Weirich test coverage for system dir
authored
233 def test_load_from_calculated_system_rakefile
2f25507 Eric Hodel Make fileutils tests be non-directory-dependent
drbrain authored
234 rakefile_default
928e0a2 Eric Hodel Remove requirement of flexmock per Ruby bug #4987
drbrain authored
235 def @app.standard_system_dir
236 "__STD_SYS_DIR__"
237 end
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
238
239 ENV['RAKE_SYSTEM'] = nil
240
241 @app.instance_eval do
242 handle_options
243 options.silent = true
244 options.load_system = true
245 options.rakelib = []
246 load_rakefile
247 end
248
249 assert_equal "__STD_SYS_DIR__", @app.system_dir
2f25507 Eric Hodel Make fileutils tests be non-directory-dependent
drbrain authored
250 rescue SystemExit
251 flunk 'failed to find system rakefile'
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
252 end
253
254 def test_terminal_columns
255 old_RAKE_COLUMNS = ENV['RAKE_COLUMNS']
256
257 ENV['RAKE_COLUMNS'] = '42'
258
259 app = Rake::Application.new
260
261 assert_equal 42, app.terminal_columns
262 ensure
263 if old_RAKE_COLUMNS then
264 ENV['RAKE_COLUMNS'].delete
265 else
266 ENV['RAKE_COLUMNS'] = old_RAKE_COLUMNS
02e7bbb Jim Weirich test coverage for system dir
authored
267 end
268 end
269
fcf0bb1 Jim Weirich some refactoring and code cleanup. Better coverage
authored
270 def test_windows
271 assert ! (@app.windows? && @app.unix?)
272 end
273
c8197eb added rcov and unit tests
jimweirich authored
274 def test_loading_imports
928e0a2 Eric Hodel Remove requirement of flexmock per Ruby bug #4987
drbrain authored
275 loader = util_loader
276
9bb3cb2 Changes for Rake 0.7 3
jimweirich authored
277 @app.instance_eval do
928e0a2 Eric Hodel Remove requirement of flexmock per Ruby bug #4987
drbrain authored
278 add_loader("dummy", loader)
9bb3cb2 Changes for Rake 0.7 3
jimweirich authored
279 add_import("x.dummy")
280 load_imports
281 end
928e0a2 Eric Hodel Remove requirement of flexmock per Ruby bug #4987
drbrain authored
282
283 # HACK no assertions
c8197eb added rcov and unit tests
jimweirich authored
284 end
285
286 def test_building_imported_files_on_demand
928e0a2 Eric Hodel Remove requirement of flexmock per Ruby bug #4987
drbrain authored
287 loader = util_loader
288
9bb3cb2 Changes for Rake 0.7 3
jimweirich authored
289 @app.instance_eval do
928e0a2 Eric Hodel Remove requirement of flexmock per Ruby bug #4987
drbrain authored
290 intern(Rake::Task, "x.dummy").enhance do loader.make_dummy end
291 add_loader("dummy", loader)
9bb3cb2 Changes for Rake 0.7 3
jimweirich authored
292 add_import("x.dummy")
293 load_imports
294 end
928e0a2 Eric Hodel Remove requirement of flexmock per Ruby bug #4987
drbrain authored
295
296 # HACK no assertions
c8197eb added rcov and unit tests
jimweirich authored
297 end
298
f6d5d5e Jim Weirich Removed Application level test for win32 specifics (already covered in
authored
299 def test_handle_options_should_strip_options_from_ARGV
bdb31e3 am - Options parsing now appropriately removed rake options from the arg...
pivotal authored
300 assert !@app.options.trace
301
302 valid_option = '--trace'
303 ARGV.clear
304 ARGV << valid_option
305
306 @app.handle_options
307
308 assert !ARGV.include?(valid_option)
309 assert @app.options.trace
310 end
311
c8197eb added rcov and unit tests
jimweirich authored
312 def test_good_run
313 ran = false
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
314
991f432 Ruby 1.9 commit
jimweirich authored
315 ARGV << '--rakelib=""'
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
316
c8197eb added rcov and unit tests
jimweirich authored
317 @app.options.silent = true
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
318
9bb3cb2 Changes for Rake 0.7 3
jimweirich authored
319 @app.instance_eval do
320 intern(Rake::Task, "default").enhance { ran = true }
321 end
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
322
323 rakefile_default
324
8f02e23 Eric Hodel Rake tests now create all files in a temporary directory
drbrain authored
325 out, err = capture_io do
326 @app.run
327 end
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
328
c8197eb added rcov and unit tests
jimweirich authored
329 assert ran
8f02e23 Eric Hodel Rake tests now create all files in a temporary directory
drbrain authored
330 assert_empty err
331 assert_equal "DEFAULT\n", out
c8197eb added rcov and unit tests
jimweirich authored
332 end
333
334 def test_display_task_run
335 ran = false
336 ARGV.clear
991f432 Ruby 1.9 commit
jimweirich authored
337 ARGV << '-f' << '-s' << '--tasks' << '--rakelib=""'
d1f89d7 added task parameters, named parameter via desc, column limited output
jimweirich authored
338 @app.last_description = "COMMENT"
c8197eb added rcov and unit tests
jimweirich authored
339 @app.define_task(Rake::Task, "default")
0dba7c9 Eric Hodel Switch rake's tests to minitest
drbrain authored
340 out, = capture_io { @app.run }
c8197eb added rcov and unit tests
jimweirich authored
341 assert @app.options.show_tasks
342 assert ! ran
343 assert_match(/rake default/, out)
344 assert_match(/# COMMENT/, out)
345 end
346
347 def test_display_prereqs
348 ran = false
349 ARGV.clear
991f432 Ruby 1.9 commit
jimweirich authored
350 ARGV << '-f' << '-s' << '--prereqs' << '--rakelib=""'
d1f89d7 added task parameters, named parameter via desc, column limited output
jimweirich authored
351 @app.last_description = "COMMENT"
c8197eb added rcov and unit tests
jimweirich authored
352 t = @app.define_task(Rake::Task, "default")
353 t.enhance([:a, :b])
354 @app.define_task(Rake::Task, "a")
355 @app.define_task(Rake::Task, "b")
0dba7c9 Eric Hodel Switch rake's tests to minitest
drbrain authored
356 out, = capture_io { @app.run }
c8197eb added rcov and unit tests
jimweirich authored
357 assert @app.options.show_prereqs
358 assert ! ran
359 assert_match(/rake a$/, out)
360 assert_match(/rake b$/, out)
361 assert_match(/rake default\n( *(a|b)\n){2}/m, out)
362 end
363
364 def test_bad_run
20542ed removed lingering reference to the no_files test directory
jimweirich authored
365 @app.intern(Rake::Task, "default").enhance { fail }
366 ARGV.clear
367 ARGV << '-f' << '-s' << '--rakelib=""'
0dba7c9 Eric Hodel Switch rake's tests to minitest
drbrain authored
368 assert_raises(SystemExit) {
369 _, err = capture_io { @app.run }
370 assert_match(/see full trace/, err)
20542ed removed lingering reference to the no_files test directory
jimweirich authored
371 }
c8197eb added rcov and unit tests
jimweirich authored
372 ensure
373 ARGV.clear
374 end
375
376 def test_bad_run_with_trace
377 @app.intern(Rake::Task, "default").enhance { fail }
378 ARGV.clear
379 ARGV << '-f' << '-s' << '-t'
0dba7c9 Eric Hodel Switch rake's tests to minitest
drbrain authored
380 assert_raises(SystemExit) {
381 _, err = capture_io { @app.run }
382 refute_match(/see full trace/, err)
c8197eb added rcov and unit tests
jimweirich authored
383 }
384 ensure
385 ARGV.clear
386 end
387
e90ce27 Michael Grosser Add --backtrace option to see the backtrace without seing the trace.
grosser authored
388 def test_bad_run_with_backtrace
389 @app.intern(Rake::Task, "default").enhance { fail }
390 ARGV.clear
391 ARGV << '-f' << '-s' << '--backtrace'
392 assert_raises(SystemExit) {
393 _, err = capture_io { @app.run }
394 refute_match(/see full trace/, err)
395 }
396 ensure
397 ARGV.clear
398 end
399
c8197eb added rcov and unit tests
jimweirich authored
400 def test_run_with_bad_options
401 @app.intern(Rake::Task, "default").enhance { fail }
402 ARGV.clear
403 ARGV << '-f' << '-s' << '--xyzzy'
0dba7c9 Eric Hodel Switch rake's tests to minitest
drbrain authored
404 assert_raises(SystemExit) {
405 capture_io { @app.run }
c8197eb added rcov and unit tests
jimweirich authored
406 }
407 ensure
408 ARGV.clear
409 end
efc4a7d Jim Weirich Added test for deprecation method
authored
410
411 def test_deprecation_message
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
412 _, err = capture_io do
413 @app.deprecate("a", "b", "c")
efc4a7d Jim Weirich Added test for deprecation method
authored
414 end
98e8772 Eric Hodel Remove InEnvironment from TestRakeApplication
drbrain authored
415 assert_match(/'a' is deprecated/i, err)
416 assert_match(/use 'b' instead/i, err)
417 assert_match(/at c$/i, err)
efc4a7d Jim Weirich Added test for deprecation method
authored
418 end
928e0a2 Eric Hodel Remove requirement of flexmock per Ruby bug #4987
drbrain authored
419
3680bf6 Eric Hodel Remove requirement for session gem from rake tests
drbrain authored
420 def test_standard_exception_handling_invalid_option
421 out, err = capture_io do
422 e = assert_raises SystemExit do
423 @app.standard_exception_handling do
424 raise OptionParser::InvalidOption, 'blah'
425 end
426 end
427
428 assert_equal 1, e.status
429 end
430
431 assert_empty out
432 assert_equal "invalid option: blah\n", err
433 end
434
435 def test_standard_exception_handling_other
436 out, err = capture_io do
437 e = assert_raises SystemExit do
438 @app.standard_exception_handling do
439 raise 'blah'
440 end
441 end
442
443 assert_equal 1, e.status
444 end
445
446 assert_empty out
447 assert_match "rake aborted!\n", err
448 assert_match "blah\n", err
449 end
450
451 def test_standard_exception_handling_system_exit
452 out, err = capture_io do
453 e = assert_raises SystemExit do
454 @app.standard_exception_handling do
455 exit 0
456 end
457 end
458
459 assert_equal 0, e.status
460 end
461
462 assert_empty out
463 assert_empty err
464 end
465
466 def test_standard_exception_handling_system_exit_nonzero
467 out, err = capture_io do
468 e = assert_raises SystemExit do
469 @app.standard_exception_handling do
470 exit 5
471 end
472 end
473
474 assert_equal 5, e.status
475 end
476
477 assert_empty out
478 assert_empty err
479 end
480
928e0a2 Eric Hodel Remove requirement of flexmock per Ruby bug #4987
drbrain authored
481 def util_loader
482 loader = Object.new
483
484 loader.instance_variable_set :@load_called, false
485 def loader.load arg
486 raise 'called more than once' if @load_called
487 raise ArgumentError, arg unless arg == 'x.dummy'
488 @load_called = true
489 end
490
491 loader.instance_variable_set :@make_dummy_called, false
492 def loader.make_dummy
493 raise 'called more than once' if @make_dummy_called
494 @make_dummy_called = true
495 end
496
497 loader
498 end
499
c8197eb added rcov and unit tests
jimweirich authored
500 end
501
Something went wrong with that request. Please try again.