test-unit 2.0.0 → 2.0.1
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.
- data/History.txt +30 -0
- data/Manifest.txt +20 -12
- data/README.txt +28 -12
- data/Rakefile +5 -0
- data/TODO +1 -0
- data/html/classic.html +15 -0
- data/html/index.html +25 -0
- data/html/index.html.ja +27 -0
- data/html/test-unit-classic.png +0 -0
- data/lib/test/unit.rb +62 -0
- data/lib/test/unit/assertions.rb +350 -66
- data/lib/test/unit/autorunner.rb +68 -13
- data/lib/test/unit/collector/load.rb +1 -1
- data/lib/test/unit/color-scheme.rb +85 -0
- data/lib/test/unit/color.rb +40 -5
- data/lib/test/unit/diff.rb +14 -0
- data/lib/test/unit/fixture.rb +2 -2
- data/lib/test/unit/runner/console.rb +8 -2
- data/lib/test/unit/testcase.rb +86 -2
- data/lib/test/unit/ui/console/testrunner.rb +51 -26
- data/lib/test/unit/version.rb +1 -1
- data/sample/test_user.rb +22 -0
- data/test/collector/{test_descendant.rb → test-descendant.rb} +0 -0
- data/test/collector/{test_load.rb → test-load.rb} +1 -1
- data/test/{test_attribute.rb → test-attribute.rb} +0 -0
- data/test/test-color-scheme.rb +55 -0
- data/test/{test_color.rb → test-color.rb} +10 -0
- data/test/{test_diff.rb → test-diff.rb} +0 -0
- data/test/{test_emacs_runner.rb → test-emacs-runner.rb} +0 -0
- data/test/test-fixture.rb +287 -0
- data/test/{test_notification.rb → test-notification.rb} +4 -4
- data/test/{test_omission.rb → test-omission.rb} +6 -6
- data/test/{test_pending.rb → test-pending.rb} +6 -6
- data/test/{test_priority.rb → test-priority.rb} +0 -0
- data/test/test_assertions.rb +366 -63
- data/test/test_testcase.rb +48 -0
- data/test/{testunit_test_util.rb → testunit-test-util.rb} +1 -1
- metadata +27 -29
- data/test/test_fixture.rb +0 -275
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'test/unit'
|
2
|
-
require '
|
2
|
+
require 'testunit-test-util'
|
3
3
|
|
4
|
-
class
|
4
|
+
class TestUnitNotification < Test::Unit::TestCase
|
5
5
|
include TestUnitTestUtil
|
6
6
|
|
7
7
|
class TestCase < Test::Unit::TestCase
|
@@ -18,7 +18,7 @@ class TestNotification < Test::Unit::TestCase
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_notify
|
21
|
-
result =
|
21
|
+
result = _run_test("test_notify")
|
22
22
|
assert_equal("1 tests, 0 assertions, 0 failures, 0 errors, 0 pendings, " \
|
23
23
|
"0 omissions, 2 notifications",
|
24
24
|
result.to_s)
|
@@ -27,7 +27,7 @@ class TestNotification < Test::Unit::TestCase
|
|
27
27
|
end
|
28
28
|
|
29
29
|
private
|
30
|
-
def
|
30
|
+
def _run_test(name)
|
31
31
|
super(TestCase, name)
|
32
32
|
end
|
33
33
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'test/unit'
|
2
|
-
require '
|
2
|
+
require 'testunit-test-util'
|
3
3
|
|
4
4
|
class TestUnitOmission < Test::Unit::TestCase
|
5
5
|
include TestUnitTestUtil
|
@@ -43,7 +43,7 @@ class TestUnitOmission < Test::Unit::TestCase
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def test_omit
|
46
|
-
result =
|
46
|
+
result = _run_test("test_omit")
|
47
47
|
assert_equal("1 tests, 0 assertions, 0 failures, 0 errors, 0 pendings, " \
|
48
48
|
"1 omissions, 0 notifications",
|
49
49
|
result.to_s)
|
@@ -51,7 +51,7 @@ class TestUnitOmission < Test::Unit::TestCase
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def test_omit_with_condition
|
54
|
-
result =
|
54
|
+
result = _run_test("test_omit_with_condition")
|
55
55
|
assert_equal("1 tests, 0 assertions, 0 failures, 0 errors, 0 pendings, " \
|
56
56
|
"1 omissions, 0 notifications",
|
57
57
|
result.to_s)
|
@@ -59,7 +59,7 @@ class TestUnitOmission < Test::Unit::TestCase
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def test_omit_with_block
|
62
|
-
result =
|
62
|
+
result = _run_test("test_omit_with_block")
|
63
63
|
assert_equal("1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, " \
|
64
64
|
"1 omissions, 0 notifications",
|
65
65
|
result.to_s)
|
@@ -67,7 +67,7 @@ class TestUnitOmission < Test::Unit::TestCase
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def test_omit_with_condition_and_block
|
70
|
-
result =
|
70
|
+
result = _run_test("test_omit_with_block_and_condition")
|
71
71
|
assert_equal("1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, " \
|
72
72
|
"1 omissions, 0 notifications",
|
73
73
|
result.to_s)
|
@@ -75,7 +75,7 @@ class TestUnitOmission < Test::Unit::TestCase
|
|
75
75
|
end
|
76
76
|
|
77
77
|
private
|
78
|
-
def
|
78
|
+
def _run_test(name)
|
79
79
|
super(TestCase, name)
|
80
80
|
end
|
81
81
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'test/unit'
|
2
|
-
require '
|
2
|
+
require 'testunit-test-util'
|
3
3
|
|
4
|
-
class
|
4
|
+
class TestUntiPending < Test::Unit::TestCase
|
5
5
|
include TestUnitTestUtil
|
6
6
|
|
7
7
|
class TestCase < Test::Unit::TestCase
|
@@ -34,7 +34,7 @@ class TestUnitPending < Test::Unit::TestCase
|
|
34
34
|
|
35
35
|
def test_pend
|
36
36
|
test = nil
|
37
|
-
result =
|
37
|
+
result = _run_test("test_pend") {|t| test = t}
|
38
38
|
assert_equal("1 tests, 0 assertions, 0 failures, 0 errors, 1 pendings, " \
|
39
39
|
"0 omissions, 0 notifications",
|
40
40
|
result.to_s)
|
@@ -44,7 +44,7 @@ class TestUnitPending < Test::Unit::TestCase
|
|
44
44
|
|
45
45
|
def test_pend_with_failure_in_block
|
46
46
|
test = nil
|
47
|
-
result =
|
47
|
+
result = _run_test("test_pend_with_failure_in_block") {|t| test = t}
|
48
48
|
assert_equal("1 tests, 1 assertions, 0 failures, 0 errors, 1 pendings, " \
|
49
49
|
"0 omissions, 0 notifications",
|
50
50
|
result.to_s)
|
@@ -54,7 +54,7 @@ class TestUnitPending < Test::Unit::TestCase
|
|
54
54
|
|
55
55
|
def test_pend_with_no_failure_in_block
|
56
56
|
test = nil
|
57
|
-
result =
|
57
|
+
result = _run_test("test_pend_with_no_failure_in_block") {|t| test = t}
|
58
58
|
assert_equal("1 tests, 1 assertions, 1 failures, 0 errors, 0 pendings, " \
|
59
59
|
"0 omissions, 0 notifications",
|
60
60
|
result.to_s)
|
@@ -64,7 +64,7 @@ class TestUnitPending < Test::Unit::TestCase
|
|
64
64
|
end
|
65
65
|
|
66
66
|
private
|
67
|
-
def
|
67
|
+
def _run_test(name, &block)
|
68
68
|
super(TestCase, name, &block)
|
69
69
|
end
|
70
70
|
end
|
File without changes
|
data/test/test_assertions.rb
CHANGED
@@ -7,6 +7,10 @@ require 'test/unit'
|
|
7
7
|
module Test
|
8
8
|
module Unit
|
9
9
|
class TC_Assertions < TestCase
|
10
|
+
backtrace_pre = "---Backtrace---"
|
11
|
+
backtrace_post = "---------------"
|
12
|
+
BACKTRACE_RE = /#{backtrace_pre}\n.+\n#{backtrace_post}/m
|
13
|
+
|
10
14
|
def check(value, message="")
|
11
15
|
add_assertion
|
12
16
|
raise AssertionFailedError.new(message) unless value
|
@@ -116,9 +120,6 @@ module Test
|
|
116
120
|
check_nothing_fails {
|
117
121
|
assert_equal("string1", "string1")
|
118
122
|
}
|
119
|
-
check_nothing_fails {
|
120
|
-
assert_equal( "string1", "string1", "successful assert_equal")
|
121
|
-
}
|
122
123
|
check_nothing_fails {
|
123
124
|
assert_equal("string1", "string1", "successful assert_equal")
|
124
125
|
}
|
@@ -166,6 +167,47 @@ EOM
|
|
166
167
|
end
|
167
168
|
end
|
168
169
|
|
170
|
+
def test_assert_equal_with_long_line
|
171
|
+
expected = ["0123456789",
|
172
|
+
"1123456789",
|
173
|
+
"2123456789",
|
174
|
+
"3123456789",
|
175
|
+
"4123456789",
|
176
|
+
"5123456789",
|
177
|
+
"6123456789",
|
178
|
+
"7123456789",
|
179
|
+
"8123456789"].join
|
180
|
+
actual = ["0000000000",
|
181
|
+
"1123456789",
|
182
|
+
"2123456789",
|
183
|
+
"3123456789",
|
184
|
+
"4123456789",
|
185
|
+
"5123456789",
|
186
|
+
"6123456789",
|
187
|
+
"7123456789",
|
188
|
+
"8123456789"].join
|
189
|
+
message = <<-EOM.chomp
|
190
|
+
<"#{expected}"> expected but was
|
191
|
+
<"#{actual}">.
|
192
|
+
|
193
|
+
diff:
|
194
|
+
- #{expected}
|
195
|
+
? ^^^^^^^^^
|
196
|
+
+ #{actual}
|
197
|
+
? ^^^^^^^^^
|
198
|
+
|
199
|
+
folded diff:
|
200
|
+
- 012345678911234567892123456789312345678941234567895123456789612345678971234567
|
201
|
+
? ^^^^^^^^^
|
202
|
+
+ 000000000011234567892123456789312345678941234567895123456789612345678971234567
|
203
|
+
? ^^^^^^^^^
|
204
|
+
898123456789
|
205
|
+
EOM
|
206
|
+
check_fails(message) do
|
207
|
+
assert_equal(expected, actual)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
169
211
|
def test_assert_equal_for_too_small_difference
|
170
212
|
message = <<-EOM.chomp
|
171
213
|
<1> expected but was
|
@@ -203,85 +245,191 @@ EOM
|
|
203
245
|
end
|
204
246
|
end
|
205
247
|
|
206
|
-
def
|
248
|
+
def test_assert_raise_success
|
207
249
|
return_value = nil
|
208
|
-
check_nothing_fails(true)
|
209
|
-
return_value = assert_raise(RuntimeError)
|
250
|
+
check_nothing_fails(true) do
|
251
|
+
return_value = assert_raise(RuntimeError) do
|
210
252
|
raise "Error"
|
211
|
-
|
212
|
-
|
213
|
-
check(return_value.kind_of?(Exception),
|
214
|
-
|
215
|
-
|
216
|
-
|
253
|
+
end
|
254
|
+
end
|
255
|
+
check(return_value.kind_of?(Exception),
|
256
|
+
"Should have returned the exception " +
|
257
|
+
"from a successful assert_raise")
|
258
|
+
check(return_value.message == "Error",
|
259
|
+
"Should have returned the correct exception " +
|
260
|
+
"from a successful assert_raise")
|
261
|
+
|
262
|
+
check_nothing_fails(true) do
|
263
|
+
assert_raise(ArgumentError, "successful assert_raise") do
|
217
264
|
raise ArgumentError.new("Error")
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
check_nothing_fails(true) do
|
269
|
+
assert_raise(RuntimeError) do
|
222
270
|
raise "Error"
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
check_nothing_fails(true) do
|
275
|
+
assert_raise(RuntimeError, "successful assert_raise") do
|
227
276
|
raise "Error"
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
check_nothing_fails(true) do
|
281
|
+
assert_raise do
|
282
|
+
raise Exception, "Any exception"
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
def test_assert_raise_fail
|
288
|
+
check_fails("<RuntimeError> exception expected but none was thrown.") do
|
289
|
+
assert_raise(RuntimeError) do
|
232
290
|
1 + 1
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
message = <<-EOM
|
295
|
+
failed assert_raise.
|
296
|
+
<ArgumentError> exception expected but was
|
297
|
+
Class: <RuntimeError>
|
298
|
+
Message: <"Error">
|
299
|
+
EOM
|
300
|
+
check_fails(/\A#{message}#{BACKTRACE_RE}\Z/m) do
|
301
|
+
assert_raise(ArgumentError, "failed assert_raise") do
|
237
302
|
raise "Error"
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
message = <<-EOM
|
307
|
+
Should expect a class of exception, Object.
|
308
|
+
<false> is not true.
|
309
|
+
EOM
|
310
|
+
check_fails(message.chomp) do
|
311
|
+
assert_nothing_raised(Object) do
|
242
312
|
1 + 1
|
243
|
-
|
244
|
-
|
313
|
+
end
|
314
|
+
end
|
315
|
+
end
|
245
316
|
|
317
|
+
def test_assert_raise_module
|
246
318
|
exceptions = [ArgumentError, TypeError]
|
247
319
|
modules = [Math, Comparable]
|
248
320
|
rescues = exceptions + modules
|
321
|
+
|
249
322
|
exceptions.each do |exc|
|
250
|
-
|
251
|
-
|
323
|
+
return_value = nil
|
324
|
+
check_nothing_fails(true) do
|
325
|
+
return_value = assert_raise(*rescues) do
|
252
326
|
raise exc, "Error"
|
253
|
-
|
254
|
-
|
255
|
-
check(return_value.instance_of?(exc),
|
256
|
-
|
327
|
+
end
|
328
|
+
end
|
329
|
+
check(return_value.instance_of?(exc),
|
330
|
+
"Should have returned #{exc} but was #{return_value.class}")
|
331
|
+
check(return_value.message == "Error",
|
332
|
+
"Should have returned the correct exception " +
|
333
|
+
"from a successful assert_raise")
|
257
334
|
end
|
335
|
+
|
258
336
|
modules.each do |mod|
|
259
|
-
|
260
|
-
|
337
|
+
return_value = nil
|
338
|
+
check_nothing_fails(true) do
|
339
|
+
return_value = assert_raise(*rescues) do
|
261
340
|
raise Exception.new("Error").extend(mod)
|
262
|
-
|
263
|
-
|
264
|
-
check(mod === return_value,
|
265
|
-
|
341
|
+
end
|
342
|
+
end
|
343
|
+
check(mod === return_value,
|
344
|
+
"Should have returned #{mod}")
|
345
|
+
check(return_value.message == "Error",
|
346
|
+
"Should have returned the correct exception " +
|
347
|
+
"from a successful assert_raise")
|
266
348
|
end
|
267
|
-
|
268
|
-
|
349
|
+
|
350
|
+
check_fails("<[ArgumentError, TypeError, Math, Comparable]> exception " +
|
351
|
+
"expected but none was thrown.") do
|
352
|
+
assert_raise(*rescues) do
|
269
353
|
1 + 1
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
message = <<-EOM
|
358
|
+
failed assert_raise.
|
359
|
+
<[ArgumentError, TypeError]> exception expected but was
|
274
360
|
Class: <RuntimeError>
|
275
361
|
Message: <"Error">
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
assert_raise(ArgumentError, TypeError, "failed assert_raise")
|
362
|
+
EOM
|
363
|
+
message = Regexp.escape(message)
|
364
|
+
check_fails(/\A#{message}#{BACKTRACE_RE}\z/m) do
|
365
|
+
assert_raise(ArgumentError, TypeError, "failed assert_raise") do
|
280
366
|
raise "Error"
|
281
|
-
|
282
|
-
|
367
|
+
end
|
368
|
+
end
|
283
369
|
end
|
284
|
-
|
370
|
+
|
371
|
+
def test_assert_raise_instance
|
372
|
+
return_value = nil
|
373
|
+
check_nothing_fails(true) do
|
374
|
+
return_value = assert_raise(RuntimeError.new("Error")) do
|
375
|
+
raise "Error"
|
376
|
+
end
|
377
|
+
end
|
378
|
+
check(return_value.kind_of?(Exception),
|
379
|
+
"Should have returned the exception " +
|
380
|
+
"from a successful assert_raise")
|
381
|
+
check(return_value.message == "Error",
|
382
|
+
"Should have returned the correct exception " +
|
383
|
+
"from a successful assert_raise")
|
384
|
+
|
385
|
+
message = <<-EOM
|
386
|
+
<RuntimeError("XXX")> exception expected but was
|
387
|
+
Class: <RuntimeError>
|
388
|
+
Message: <"Error">
|
389
|
+
EOM
|
390
|
+
message = Regexp.escape(message)
|
391
|
+
check_fails(/\A#{message}#{BACKTRACE_RE}\z/) do
|
392
|
+
return_value = assert_raise(RuntimeError.new("XXX")) do
|
393
|
+
raise "Error"
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
different_error_class = Class.new(StandardError)
|
398
|
+
message = <<-EOM
|
399
|
+
<\#<Class:0x[a-f\\d]+>\\("Error"\\)> exception expected but was
|
400
|
+
Class: <RuntimeError>
|
401
|
+
Message: <"Error">
|
402
|
+
EOM
|
403
|
+
check_fails(/\A#{message}#{BACKTRACE_RE}\z/) do
|
404
|
+
assert_raise(different_error_class.new("Error")) do
|
405
|
+
raise "Error"
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
different_error = different_error_class.new("Error")
|
410
|
+
def different_error.inspect
|
411
|
+
"DifferentError: \"Error\""
|
412
|
+
end
|
413
|
+
message = <<-EOM
|
414
|
+
<\DifferentError: \\"Error\\"> exception expected but was
|
415
|
+
Class: <RuntimeError>
|
416
|
+
Message: <"Error">
|
417
|
+
EOM
|
418
|
+
check_fails(/\A#{message}#{BACKTRACE_RE}\z/) do
|
419
|
+
assert_raise(different_error) do
|
420
|
+
raise "Error"
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
424
|
+
check_nothing_fails(true) do
|
425
|
+
assert_raise(different_error_class.new("Error"),
|
426
|
+
RuntimeError.new("Error"),
|
427
|
+
RuntimeError.new("XXX")) do
|
428
|
+
raise "Error"
|
429
|
+
end
|
430
|
+
end
|
431
|
+
end
|
432
|
+
|
285
433
|
def test_assert_instance_of
|
286
434
|
check_nothing_fails {
|
287
435
|
assert_instance_of(String, "string")
|
@@ -496,9 +644,9 @@ Message: <"Error">
|
|
496
644
|
end
|
497
645
|
end
|
498
646
|
|
499
|
-
def
|
647
|
+
def test_assert_throw
|
500
648
|
check_nothing_fails do
|
501
|
-
|
649
|
+
assert_throw(:thing, "message") do
|
502
650
|
throw :thing
|
503
651
|
end
|
504
652
|
end
|
@@ -507,13 +655,13 @@ Message: <"Error">
|
|
507
655
|
check_fails("message.\n" +
|
508
656
|
"<:thing> expected to be thrown but\n" +
|
509
657
|
"<#{inspect_tag(tag)}> was thrown.") do
|
510
|
-
|
658
|
+
assert_throw(:thing, "message") do
|
511
659
|
throw :thing2
|
512
660
|
end
|
513
661
|
end
|
514
662
|
check_fails("message.\n" +
|
515
663
|
"<:thing> should have been thrown.") do
|
516
|
-
|
664
|
+
assert_throw(:thing, "message") do
|
517
665
|
1 + 1
|
518
666
|
end
|
519
667
|
end
|
@@ -675,6 +823,160 @@ Message: <"Error">
|
|
675
823
|
end
|
676
824
|
end
|
677
825
|
|
826
|
+
def test_assert_compare
|
827
|
+
check_nothing_fails do
|
828
|
+
assert_compare(1.4, "<", 10.0)
|
829
|
+
end
|
830
|
+
|
831
|
+
check_nothing_fails do
|
832
|
+
assert_compare(2, "<=", 2)
|
833
|
+
end
|
834
|
+
|
835
|
+
check_nothing_fails do
|
836
|
+
assert_compare(14, ">=", 10.0)
|
837
|
+
end
|
838
|
+
|
839
|
+
check_nothing_fails do
|
840
|
+
assert_compare(14, ">", 13.9)
|
841
|
+
end
|
842
|
+
|
843
|
+
expected_message = <<-EOM
|
844
|
+
<15> < <10> should be true
|
845
|
+
<15> expected less than
|
846
|
+
<10>.
|
847
|
+
EOM
|
848
|
+
check_fails(expected_message.chomp) do
|
849
|
+
assert_compare(15, "<", 10)
|
850
|
+
end
|
851
|
+
|
852
|
+
expected_message = <<-EOM
|
853
|
+
<15> <= <10> should be true
|
854
|
+
<15> expected less than or equal to
|
855
|
+
<10>.
|
856
|
+
EOM
|
857
|
+
check_fails(expected_message.chomp) do
|
858
|
+
assert_compare(15, "<=", 10)
|
859
|
+
end
|
860
|
+
|
861
|
+
expected_message = <<-EOM
|
862
|
+
<10> > <15> should be true
|
863
|
+
<10> expected greater than
|
864
|
+
<15>.
|
865
|
+
EOM
|
866
|
+
check_fails(expected_message.chomp) do
|
867
|
+
assert_compare(10, ">", 15)
|
868
|
+
end
|
869
|
+
|
870
|
+
expected_message = <<-EOM
|
871
|
+
<10> >= <15> should be true
|
872
|
+
<10> expected greater than or equal to
|
873
|
+
<15>.
|
874
|
+
EOM
|
875
|
+
check_fails(expected_message.chomp) do
|
876
|
+
assert_compare(10, ">=", 15)
|
877
|
+
end
|
878
|
+
end
|
879
|
+
|
880
|
+
def test_assert_fail_assertion
|
881
|
+
check_nothing_fails do
|
882
|
+
assert_fail_assertion do
|
883
|
+
flunk
|
884
|
+
end
|
885
|
+
end
|
886
|
+
|
887
|
+
check_fails("Failed assertion was expected.") do
|
888
|
+
assert_fail_assertion do
|
889
|
+
end
|
890
|
+
end
|
891
|
+
end
|
892
|
+
|
893
|
+
def test_assert_raise_message
|
894
|
+
check_nothing_fails do
|
895
|
+
assert_raise_message("Raise!") do
|
896
|
+
raise "Raise!"
|
897
|
+
end
|
898
|
+
end
|
899
|
+
|
900
|
+
check_nothing_fails do
|
901
|
+
assert_raise_message("Raise!") do
|
902
|
+
raise Exception, "Raise!"
|
903
|
+
end
|
904
|
+
end
|
905
|
+
|
906
|
+
check_nothing_fails do
|
907
|
+
assert_raise_message(/raise/i) do
|
908
|
+
raise "Raise!"
|
909
|
+
end
|
910
|
+
end
|
911
|
+
|
912
|
+
expected_message = <<-EOM
|
913
|
+
<"Expected message"> exception message expected but was
|
914
|
+
<"Actual message">.
|
915
|
+
EOM
|
916
|
+
check_fails(expected_message.chomp) do
|
917
|
+
assert_raise_message("Expected message") do
|
918
|
+
raise "Actual message"
|
919
|
+
end
|
920
|
+
end
|
921
|
+
|
922
|
+
expected_message = <<-EOM
|
923
|
+
<"Expected message"> exception message expected but none was thrown.
|
924
|
+
EOM
|
925
|
+
check_fails(expected_message.chomp) do
|
926
|
+
assert_raise_message("Expected message") do
|
927
|
+
end
|
928
|
+
end
|
929
|
+
end
|
930
|
+
|
931
|
+
def test_assert_raise_kind_of
|
932
|
+
check_nothing_fails(true) do
|
933
|
+
assert_raise_kind_of(SystemCallError) do
|
934
|
+
raise Errno::EACCES
|
935
|
+
end
|
936
|
+
end
|
937
|
+
|
938
|
+
expected_message = <<-EOM
|
939
|
+
<SystemCallError> family exception expected but was
|
940
|
+
Class: <RuntimeError>
|
941
|
+
Message: <"XXX">
|
942
|
+
---Backtrace---
|
943
|
+
EOM
|
944
|
+
check_fails(/\A#{Regexp.escape(expected_message)}(?m).+\z/) do
|
945
|
+
assert_raise_kind_of(SystemCallError) do
|
946
|
+
raise RuntimeError, "XXX"
|
947
|
+
end
|
948
|
+
end
|
949
|
+
end
|
950
|
+
|
951
|
+
def test_assert_const_defined
|
952
|
+
check_nothing_fails do
|
953
|
+
assert_const_defined(Test, :Unit)
|
954
|
+
end
|
955
|
+
|
956
|
+
check_nothing_fails do
|
957
|
+
assert_const_defined(Test, "Unit")
|
958
|
+
end
|
959
|
+
|
960
|
+
check_fails("<Test>.const_defined?(<:Nonexistence>) expected.") do
|
961
|
+
assert_const_defined(Test, :Nonexistence)
|
962
|
+
end
|
963
|
+
end
|
964
|
+
|
965
|
+
def test_assert_not_const_defined
|
966
|
+
check_nothing_fails do
|
967
|
+
assert_not_const_defined(Test, :Nonexistence)
|
968
|
+
end
|
969
|
+
|
970
|
+
check_fails("!<Test>.const_defined?(<:Unit>) expected.") do
|
971
|
+
assert_not_const_defined(Test, :Unit)
|
972
|
+
end
|
973
|
+
|
974
|
+
check_fails("!<Test>.const_defined?(<\"Unit\">) expected.") do
|
975
|
+
assert_not_const_defined(Test, "Unit")
|
976
|
+
end
|
977
|
+
end
|
978
|
+
|
979
|
+
private
|
678
980
|
def add_failure(message, location=caller)
|
679
981
|
unless @catch_assertions
|
680
982
|
super
|
@@ -691,3 +993,4 @@ Message: <"Error">
|
|
691
993
|
end
|
692
994
|
end
|
693
995
|
end
|
996
|
+
p
|