activegroonga 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/README.textile +55 -0
  2. data/Rakefile +45 -165
  3. data/{license/LGPL → doc/text/lgpl.txt} +0 -0
  4. data/doc/text/news.textile +60 -0
  5. data/doc/text/tutorial.textile +3 -0
  6. data/lib/active_groonga/base.rb +50 -2
  7. data/lib/active_groonga/railtie.rb +6 -5
  8. data/lib/active_groonga/railties/groonga.rake +8 -4
  9. data/lib/active_groonga/result_set.rb +133 -8
  10. data/lib/active_groonga/version.rb +1 -1
  11. data/test/active-groonga-test-utils.rb +6 -0
  12. data/test/run-test.rb +11 -24
  13. data/test/test-base.rb +10 -4
  14. data/test/test-result-set.rb +121 -9
  15. metadata +90 -138
  16. data/AUTHORS +0 -1
  17. data/NEWS.ja.rdoc +0 -46
  18. data/NEWS.rdoc +0 -46
  19. data/README.ja.rdoc +0 -52
  20. data/README.rdoc +0 -52
  21. data/test-unit-notify/Rakefile +0 -47
  22. data/test-unit-notify/lib/test/unit/notify.rb +0 -104
  23. data/test-unit/COPYING +0 -56
  24. data/test-unit/GPL +0 -340
  25. data/test-unit/PSFL +0 -271
  26. data/test-unit/Rakefile +0 -53
  27. data/test-unit/TODO +0 -5
  28. data/test-unit/bin/testrb +0 -5
  29. data/test-unit/html/bar.svg +0 -153
  30. data/test-unit/html/developer.svg +0 -469
  31. data/test-unit/html/favicon.ico +0 -0
  32. data/test-unit/html/favicon.svg +0 -82
  33. data/test-unit/html/heading-mark.svg +0 -393
  34. data/test-unit/html/index.html +0 -247
  35. data/test-unit/html/index.html.ja +0 -270
  36. data/test-unit/html/install.svg +0 -636
  37. data/test-unit/html/logo.svg +0 -483
  38. data/test-unit/html/test-unit.css +0 -339
  39. data/test-unit/html/tutorial.svg +0 -559
  40. data/test-unit/lib/test/unit.rb +0 -328
  41. data/test-unit/lib/test/unit/assertionfailederror.rb +0 -25
  42. data/test-unit/lib/test/unit/assertions.rb +0 -1334
  43. data/test-unit/lib/test/unit/attribute.rb +0 -125
  44. data/test-unit/lib/test/unit/autorunner.rb +0 -363
  45. data/test-unit/lib/test/unit/collector.rb +0 -36
  46. data/test-unit/lib/test/unit/collector/descendant.rb +0 -23
  47. data/test-unit/lib/test/unit/collector/dir.rb +0 -108
  48. data/test-unit/lib/test/unit/collector/load.rb +0 -144
  49. data/test-unit/lib/test/unit/collector/objectspace.rb +0 -34
  50. data/test-unit/lib/test/unit/color-scheme.rb +0 -106
  51. data/test-unit/lib/test/unit/color.rb +0 -96
  52. data/test-unit/lib/test/unit/diff.rb +0 -740
  53. data/test-unit/lib/test/unit/error.rb +0 -130
  54. data/test-unit/lib/test/unit/exceptionhandler.rb +0 -39
  55. data/test-unit/lib/test/unit/failure.rb +0 -136
  56. data/test-unit/lib/test/unit/fixture.rb +0 -176
  57. data/test-unit/lib/test/unit/notification.rb +0 -129
  58. data/test-unit/lib/test/unit/omission.rb +0 -191
  59. data/test-unit/lib/test/unit/pending.rb +0 -150
  60. data/test-unit/lib/test/unit/priority.rb +0 -180
  61. data/test-unit/lib/test/unit/runner/console.rb +0 -52
  62. data/test-unit/lib/test/unit/runner/emacs.rb +0 -8
  63. data/test-unit/lib/test/unit/runner/tap.rb +0 -8
  64. data/test-unit/lib/test/unit/testcase.rb +0 -483
  65. data/test-unit/lib/test/unit/testresult.rb +0 -121
  66. data/test-unit/lib/test/unit/testsuite.rb +0 -110
  67. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +0 -14
  68. data/test-unit/lib/test/unit/ui/console/testrunner.rb +0 -430
  69. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +0 -63
  70. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +0 -82
  71. data/test-unit/lib/test/unit/ui/testrunner.rb +0 -53
  72. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +0 -77
  73. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +0 -41
  74. data/test-unit/lib/test/unit/util/backtracefilter.rb +0 -42
  75. data/test-unit/lib/test/unit/util/method-owner-finder.rb +0 -28
  76. data/test-unit/lib/test/unit/util/observable.rb +0 -90
  77. data/test-unit/lib/test/unit/util/output.rb +0 -31
  78. data/test-unit/lib/test/unit/util/procwrapper.rb +0 -48
  79. data/test-unit/lib/test/unit/version.rb +0 -7
  80. data/test-unit/sample/adder.rb +0 -13
  81. data/test-unit/sample/subtracter.rb +0 -12
  82. data/test-unit/sample/test_adder.rb +0 -20
  83. data/test-unit/sample/test_subtracter.rb +0 -20
  84. data/test-unit/sample/test_user.rb +0 -23
  85. data/test-unit/test/collector/test-descendant.rb +0 -133
  86. data/test-unit/test/collector/test-load.rb +0 -442
  87. data/test-unit/test/collector/test_dir.rb +0 -406
  88. data/test-unit/test/collector/test_objectspace.rb +0 -100
  89. data/test-unit/test/run-test.rb +0 -15
  90. data/test-unit/test/test-attribute.rb +0 -86
  91. data/test-unit/test/test-color-scheme.rb +0 -69
  92. data/test-unit/test/test-color.rb +0 -47
  93. data/test-unit/test/test-diff.rb +0 -518
  94. data/test-unit/test/test-emacs-runner.rb +0 -60
  95. data/test-unit/test/test-fixture.rb +0 -287
  96. data/test-unit/test/test-notification.rb +0 -33
  97. data/test-unit/test/test-omission.rb +0 -81
  98. data/test-unit/test/test-pending.rb +0 -70
  99. data/test-unit/test/test-priority.rb +0 -119
  100. data/test-unit/test/test-testcase.rb +0 -544
  101. data/test-unit/test/test_assertions.rb +0 -1197
  102. data/test-unit/test/test_error.rb +0 -26
  103. data/test-unit/test/test_failure.rb +0 -33
  104. data/test-unit/test/test_testresult.rb +0 -113
  105. data/test-unit/test/test_testsuite.rb +0 -129
  106. data/test-unit/test/testunit-test-util.rb +0 -14
  107. data/test-unit/test/ui/test_tap.rb +0 -33
  108. data/test-unit/test/ui/test_testrunmediator.rb +0 -20
  109. data/test-unit/test/util/test-method-owner-finder.rb +0 -38
  110. data/test-unit/test/util/test-output.rb +0 -11
  111. data/test-unit/test/util/test_backtracefilter.rb +0 -41
  112. data/test-unit/test/util/test_observable.rb +0 -102
  113. data/test-unit/test/util/test_procwrapper.rb +0 -36
@@ -1,1197 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Author:: Nathaniel Talbott.
4
- # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
5
- # Copyright (c) 2009-2010 Kouhei Sutou. All rights reserved.
6
- # License:: Ruby license.
7
-
8
- require 'test/unit'
9
-
10
- module Test
11
- module Unit
12
- class TC_Assertions < TestCase
13
- backtrace_pre = "---Backtrace---"
14
- backtrace_post = "---------------"
15
- BACKTRACE_RE = /#{backtrace_pre}\n.+\n#{backtrace_post}/m
16
-
17
- def check(value, message="")
18
- add_assertion
19
- raise AssertionFailedError.new(message) unless value
20
- end
21
-
22
- def check_assertions(expect_fail, expected_message="",
23
- return_value_expected=false)
24
- @actual_assertion_count = 0
25
- failed = true
26
- actual_message = nil
27
- @catch_assertions = true
28
- return_value = nil
29
- begin
30
- return_value = yield
31
- failed = false
32
- rescue AssertionFailedError => error
33
- actual_message = error.message
34
- end
35
- @catch_assertions = false
36
-
37
- if expect_fail
38
- message = "Should have failed, but didn't"
39
- else
40
- message = "Should not have failed, but did with message\n" +
41
- "<#{actual_message}>"
42
- end
43
- check(expect_fail == failed, message)
44
-
45
- message = "Should have made one assertion but made\n" +
46
- "<#{@actual_assertion_count}>"
47
- check(1 == @actual_assertion_count, message)
48
-
49
- if expect_fail
50
- case expected_message
51
- when String
52
- check(actual_message == expected_message,
53
- "Should have the correct message.\n" +
54
- "<#{expected_message.inspect}> expected but was\n" +
55
- "<#{actual_message.inspect}>")
56
- when Regexp
57
- check(actual_message =~ expected_message,
58
- "The message should match correctly.\n" +
59
- "</#{expected_message.source}/> expected to match\n" +
60
- "<#{actual_message.inspect}>")
61
- else
62
- check(false,
63
- "Incorrect expected message type in assert_nothing_failed")
64
- end
65
- else
66
- if return_value_expected
67
- check(!return_value.nil?, "Should return a value")
68
- else
69
- check(return_value.nil?,
70
- "Should not return a value but returned <#{return_value}>")
71
- end
72
- end
73
-
74
- return_value
75
- end
76
-
77
- def check_nothing_fails(return_value_expected=false, &proc)
78
- check_assertions(false, "", return_value_expected, &proc)
79
- end
80
-
81
- def check_fails(expected_message="", &proc)
82
- check_assertions(true, expected_message, &proc)
83
- end
84
-
85
- def inspect_tag(tag)
86
- begin
87
- throw tag
88
- rescue NameError
89
- tag.to_s.inspect
90
- rescue ArgumentError
91
- tag.inspect
92
- end
93
- end
94
-
95
- def test_assert_block
96
- check_nothing_fails {
97
- assert_block {true}
98
- }
99
- check_nothing_fails {
100
- assert_block("successful assert_block") {true}
101
- }
102
- check_nothing_fails {
103
- assert_block("successful assert_block") {true}
104
- }
105
- check_fails("assert_block failed.") {
106
- assert_block {false}
107
- }
108
- check_fails("failed assert_block") {
109
- assert_block("failed assert_block") {false}
110
- }
111
- end
112
-
113
- def test_assert
114
- check_nothing_fails{assert("a")}
115
- check_nothing_fails{assert(true)}
116
- check_nothing_fails{assert(true, "successful assert")}
117
- check_fails("<nil> is not true."){assert(nil)}
118
- check_fails("<false> is not true."){assert(false)}
119
- check_fails("failed assert.\n<false> is not true."){assert(false, "failed assert")}
120
- end
121
-
122
- def test_assert_equal
123
- check_nothing_fails {
124
- assert_equal("string1", "string1")
125
- }
126
- check_nothing_fails {
127
- assert_equal("string1", "string1", "successful assert_equal")
128
- }
129
-
130
- message = <<-EOM.chomp
131
- <"string1"> expected but was
132
- <"string2">.
133
-
134
- diff:
135
- - string1
136
- ? ^
137
- + string2
138
- ? ^
139
- EOM
140
- check_fails(message) {
141
- assert_equal("string1", "string2")
142
- }
143
-
144
- message = <<-EOM.chomp
145
- failed assert_equal.
146
- <"string1"> expected but was
147
- <"string2">.
148
-
149
- diff:
150
- - string1
151
- ? ^
152
- + string2
153
- ? ^
154
- EOM
155
- check_fails(message) {
156
- assert_equal("string1", "string2", "failed assert_equal")
157
- }
158
-
159
- message = <<-EOM.chomp
160
- <"111111"> expected but was
161
- <111111>.
162
-
163
- diff:
164
- - "111111"
165
- ? - -
166
- + 111111
167
- EOM
168
- check_fails(message) do
169
- assert_equal("111111", 111111)
170
- end
171
- end
172
-
173
- def test_assert_equal_with_long_line
174
- expected = ["0123456789",
175
- "1123456789",
176
- "2123456789",
177
- "3123456789",
178
- "4123456789",
179
- "5123456789",
180
- "6123456789",
181
- "7123456789",
182
- "8123456789"].join
183
- actual = ["0000000000",
184
- "1123456789",
185
- "2123456789",
186
- "3123456789",
187
- "4123456789",
188
- "5123456789",
189
- "6123456789",
190
- "7123456789",
191
- "8123456789"].join
192
- message = <<-EOM.chomp
193
- <"#{expected}"> expected but was
194
- <"#{actual}">.
195
-
196
- diff:
197
- - #{expected}
198
- ? ^^^^^^^^^
199
- + #{actual}
200
- ? ^^^^^^^^^
201
-
202
- folded diff:
203
- - 012345678911234567892123456789312345678941234567895123456789612345678971234567
204
- ? ^^^^^^^^^
205
- + 000000000011234567892123456789312345678941234567895123456789612345678971234567
206
- ? ^^^^^^^^^
207
- 898123456789
208
- EOM
209
- check_fails(message) do
210
- assert_equal(expected, actual)
211
- end
212
- end
213
-
214
- def test_assert_equal_for_too_small_difference
215
- message = <<-EOM.chomp
216
- <1> expected but was
217
- <2>.
218
- EOM
219
- check_fails(message) do
220
- assert_equal(1, 2)
221
- end
222
- end
223
-
224
- def test_assert_equal_for_same_inspected_objects
225
- now = Time.now
226
- now_without_usec = Time.at(now.to_i)
227
- message = <<-EOM.chomp
228
- <#{now.inspect}> expected but was
229
- <#{now.inspect}>.
230
- EOM
231
- check_fails(message) do
232
- assert_equal(now, now_without_usec)
233
- end
234
- end
235
-
236
- def test_assert_equal_with_multi_lines_result
237
- message = <<-EOM.chomp
238
- <#{"a\nb".inspect}> expected but was
239
- <#{"x".inspect}>.
240
-
241
- diff:
242
- + x
243
- - a
244
- - b
245
- EOM
246
- check_fails(message) do
247
- assert_equal("a\nb", "x")
248
- end
249
- end
250
-
251
- def test_assert_equal_with_large_string
252
- message = <<-EOM.chomp
253
- <#{("a\n" + "x" * 997).inspect}> expected but was
254
- <#{"x".inspect}>.
255
-
256
- diff:
257
- + x
258
- - a
259
- - #{"x" * 997}
260
-
261
- folded diff:
262
- + x
263
- - a
264
- #{(["- " + ("x" * 78)] * 12).join("\n")}
265
- - #{"x" * 61}
266
- EOM
267
- check_fails(message) do
268
- assert_equal("a\n" + "x" * 997, "x")
269
- end
270
-
271
- message = <<-EOM.chomp
272
- <#{("a\n" + "x" * 998).inspect}> expected but was
273
- <#{"x".inspect}>.
274
- EOM
275
- check_fails(message) do
276
- assert_equal("a\n" + "x" * 998, "x")
277
- end
278
- end
279
-
280
- def test_assert_equal_with_max_diff_target_string_size
281
- key = "TEST_UNIT_MAX_DIFF_TARGET_STRING_SIZE"
282
- before_value = ENV[key]
283
- ENV[key] = "100"
284
- begin
285
- message = <<-EOM.chomp
286
- <#{("a\n" + "x" * 97).inspect}> expected but was
287
- <#{"x".inspect}>.
288
-
289
- diff:
290
- + x
291
- - a
292
- - #{"x" * 97}
293
-
294
- folded diff:
295
- + x
296
- - a
297
- #{(["- " + ("x" * 78)]).join("\n")}
298
- - #{"x" * 19}
299
- EOM
300
- check_fails(message) do
301
- assert_equal("a\n" + "x" * 97, "x")
302
- end
303
-
304
- message = <<-EOM.chomp
305
- <#{("a\n" + "x" * 98).inspect}> expected but was
306
- <#{"x".inspect}>.
307
- EOM
308
- check_fails(message) do
309
- assert_equal("a\n" + "x" * 98, "x")
310
- end
311
- ensure
312
- ENV[key] = before_value
313
- end
314
- end
315
-
316
- def test_assert_equal_with_different_encoding
317
- utf8_string = "こんにちは"
318
- unless utf8_string.respond_to?(:force_encoding)
319
- omit("encoding test is for Ruby >= 1.9")
320
- end
321
- ascii_8bit_string = utf8_string.dup.force_encoding("ascii-8bit")
322
- message = <<-EOM.chomp
323
- <"こんにちは">("UTF-8") expected but was
324
- <#{ascii_8bit_string.inspect}>("ASCII-8BIT").
325
- EOM
326
- check_fails(message) do
327
- assert_equal(utf8_string, ascii_8bit_string)
328
- end
329
- end
330
-
331
- def test_assert_raise_success
332
- return_value = nil
333
- check_nothing_fails(true) do
334
- return_value = assert_raise(RuntimeError) do
335
- raise "Error"
336
- end
337
- end
338
- check(return_value.kind_of?(Exception),
339
- "Should have returned the exception " +
340
- "from a successful assert_raise")
341
- check(return_value.message == "Error",
342
- "Should have returned the correct exception " +
343
- "from a successful assert_raise")
344
-
345
- check_nothing_fails(true) do
346
- assert_raise(ArgumentError, "successful assert_raise") do
347
- raise ArgumentError.new("Error")
348
- end
349
- end
350
-
351
- check_nothing_fails(true) do
352
- assert_raise(RuntimeError) do
353
- raise "Error"
354
- end
355
- end
356
-
357
- check_nothing_fails(true) do
358
- assert_raise(RuntimeError, "successful assert_raise") do
359
- raise "Error"
360
- end
361
- end
362
-
363
- check_nothing_fails(true) do
364
- assert_raise do
365
- raise Exception, "Any exception"
366
- end
367
- end
368
- end
369
-
370
- def test_assert_raise_fail
371
- check_fails("<RuntimeError> exception expected but none was thrown.") do
372
- assert_raise(RuntimeError) do
373
- 1 + 1
374
- end
375
- end
376
-
377
- message = <<-EOM
378
- failed assert_raise.
379
- <ArgumentError> exception expected but was
380
- Class: <RuntimeError>
381
- Message: <"Error">
382
- EOM
383
- check_fails(/\A#{message}#{BACKTRACE_RE}\Z/m) do
384
- assert_raise(ArgumentError, "failed assert_raise") do
385
- raise "Error"
386
- end
387
- end
388
-
389
- message = <<-EOM
390
- Should expect a class of exception, Object.
391
- <false> is not true.
392
- EOM
393
- check_fails(message.chomp) do
394
- assert_nothing_raised(Object) do
395
- 1 + 1
396
- end
397
- end
398
- end
399
-
400
- def test_assert_raise_module
401
- exceptions = [ArgumentError, TypeError]
402
- modules = [Math, Comparable]
403
- rescues = exceptions + modules
404
-
405
- exceptions.each do |exc|
406
- return_value = nil
407
- check_nothing_fails(true) do
408
- return_value = assert_raise(*rescues) do
409
- raise exc, "Error"
410
- end
411
- end
412
- check(return_value.instance_of?(exc),
413
- "Should have returned #{exc} but was #{return_value.class}")
414
- check(return_value.message == "Error",
415
- "Should have returned the correct exception " +
416
- "from a successful assert_raise")
417
- end
418
-
419
- modules.each do |mod|
420
- return_value = nil
421
- check_nothing_fails(true) do
422
- return_value = assert_raise(*rescues) do
423
- raise Exception.new("Error").extend(mod)
424
- end
425
- end
426
- check(mod === return_value,
427
- "Should have returned #{mod}")
428
- check(return_value.message == "Error",
429
- "Should have returned the correct exception " +
430
- "from a successful assert_raise")
431
- end
432
-
433
- check_fails("<[ArgumentError, TypeError, Math, Comparable]> exception " +
434
- "expected but none was thrown.") do
435
- assert_raise(*rescues) do
436
- 1 + 1
437
- end
438
- end
439
-
440
- message = <<-EOM
441
- failed assert_raise.
442
- <[ArgumentError, TypeError]> exception expected but was
443
- Class: <RuntimeError>
444
- Message: <"Error">
445
- EOM
446
- message = Regexp.escape(message)
447
- check_fails(/\A#{message}#{BACKTRACE_RE}\z/m) do
448
- assert_raise(ArgumentError, TypeError, "failed assert_raise") do
449
- raise "Error"
450
- end
451
- end
452
- end
453
-
454
- def test_assert_raise_instance
455
- return_value = nil
456
- check_nothing_fails(true) do
457
- return_value = assert_raise(RuntimeError.new("Error")) do
458
- raise "Error"
459
- end
460
- end
461
- check(return_value.kind_of?(Exception),
462
- "Should have returned the exception " +
463
- "from a successful assert_raise")
464
- check(return_value.message == "Error",
465
- "Should have returned the correct exception " +
466
- "from a successful assert_raise")
467
-
468
- message = <<-EOM
469
- <RuntimeError("XXX")> exception expected but was
470
- Class: <RuntimeError>
471
- Message: <"Error">
472
- EOM
473
- message = Regexp.escape(message)
474
- check_fails(/\A#{message}#{BACKTRACE_RE}\z/) do
475
- return_value = assert_raise(RuntimeError.new("XXX")) do
476
- raise "Error"
477
- end
478
- end
479
-
480
- different_error_class = Class.new(StandardError)
481
- message = <<-EOM
482
- <\#<Class:[xa-f\\d]+>\\("Error"\\)> exception expected but was
483
- Class: <RuntimeError>
484
- Message: <"Error">
485
- EOM
486
- check_fails(/\A#{message}#{BACKTRACE_RE}\z/) do
487
- assert_raise(different_error_class.new("Error")) do
488
- raise "Error"
489
- end
490
- end
491
-
492
- different_error = different_error_class.new("Error")
493
- def different_error.inspect
494
- "DifferentError: \"Error\""
495
- end
496
- message = <<-EOM
497
- <\DifferentError: \\"Error\\"> exception expected but was
498
- Class: <RuntimeError>
499
- Message: <"Error">
500
- EOM
501
- check_fails(/\A#{message}#{BACKTRACE_RE}\z/) do
502
- assert_raise(different_error) do
503
- raise "Error"
504
- end
505
- end
506
-
507
- check_nothing_fails(true) do
508
- assert_raise(different_error_class.new("Error"),
509
- RuntimeError.new("Error"),
510
- RuntimeError.new("XXX")) do
511
- raise "Error"
512
- end
513
- end
514
- end
515
-
516
- def test_assert_instance_of
517
- check_nothing_fails {
518
- assert_instance_of(String, "string")
519
- }
520
- check_nothing_fails {
521
- assert_instance_of(String, "string", "successful assert_instance_of")
522
- }
523
- check_nothing_fails {
524
- assert_instance_of(String, "string", "successful assert_instance_of")
525
- }
526
- check_fails(%Q{<"string"> expected to be an instance of\n<Hash> but was\n<String>.}) {
527
- assert_instance_of(Hash, "string")
528
- }
529
- check_fails(%Q{failed assert_instance_of.\n<"string"> expected to be an instance of\n<Hash> but was\n<String>.}) {
530
- assert_instance_of(Hash, "string", "failed assert_instance_of")
531
- }
532
-
533
- check_nothing_fails do
534
- assert_instance_of([Fixnum, NilClass], 100)
535
- end
536
- check_fails(%Q{<"string"> expected to be an instance of\n[<Fixnum>, <NilClass>] but was\n<String>.}) do
537
- assert_instance_of([Fixnum, NilClass], "string")
538
- end
539
- check_fails(%Q{<100> expected to be an instance of\n[<Numeric>, <NilClass>] but was\n<Fixnum>.}) do
540
- assert_instance_of([Numeric, NilClass], 100)
541
- end
542
- end
543
-
544
- def test_assert_nil
545
- check_nothing_fails {
546
- assert_nil(nil)
547
- }
548
- check_nothing_fails {
549
- assert_nil(nil, "successful assert_nil")
550
- }
551
- check_nothing_fails {
552
- assert_nil(nil, "successful assert_nil")
553
- }
554
- check_fails(%Q{<"string"> expected to be nil.}) {
555
- assert_nil("string")
556
- }
557
- check_fails(%Q{failed assert_nil.\n<"string"> expected to be nil.}) {
558
- assert_nil("string", "failed assert_nil")
559
- }
560
- end
561
-
562
- def test_assert_not_nil
563
- check_nothing_fails{assert_not_nil(false)}
564
- check_nothing_fails{assert_not_nil(false, "message")}
565
- check_fails("<nil> expected to not be nil."){assert_not_nil(nil)}
566
- check_fails("message.\n<nil> expected to not be nil.") {assert_not_nil(nil, "message")}
567
- end
568
-
569
- def test_assert_kind_of
570
- check_nothing_fails {
571
- assert_kind_of(Module, Array)
572
- }
573
- check_nothing_fails {
574
- assert_kind_of(Object, "string", "successful assert_kind_of")
575
- }
576
- check_nothing_fails {
577
- assert_kind_of(Object, "string", "successful assert_kind_of")
578
- }
579
- check_nothing_fails {
580
- assert_kind_of(Comparable, 1)
581
- }
582
- check_fails(%Q{<"string"> expected to be kind_of?\n<Class> but was\n<String>.}) {
583
- assert_kind_of(Class, "string")
584
- }
585
- check_fails(%Q{failed assert_kind_of.\n<"string"> expected to be kind_of?\n<Class> but was\n<String>.}) {
586
- assert_kind_of(Class, "string", "failed assert_kind_of")
587
- }
588
-
589
- check_nothing_fails do
590
- assert_kind_of([Fixnum, NilClass], 100)
591
- end
592
- check_fails(%Q{<"string"> expected to be kind_of?\n[<Fixnum>, <NilClass>] but was\n<String>.}) do
593
- assert_kind_of([Fixnum, NilClass], "string")
594
- end
595
- end
596
-
597
- def test_assert_match
598
- check_nothing_fails {
599
- assert_match(/strin./, "string")
600
- }
601
- check_nothing_fails {
602
- assert_match("strin", "string")
603
- }
604
- check_nothing_fails {
605
- assert_match(/strin./, "string", "successful assert_match")
606
- }
607
- check_nothing_fails {
608
- assert_match(/strin./, "string", "successful assert_match")
609
- }
610
- check_fails(%Q{<"string"> expected to be =~\n</slin./>.}) {
611
- assert_match(/slin./, "string")
612
- }
613
- check_fails(%Q{<"string"> expected to be =~\n</strin\\./>.}) {
614
- assert_match("strin.", "string")
615
- }
616
- check_fails(%Q{failed assert_match.\n<"string"> expected to be =~\n</slin./>.}) {
617
- assert_match(/slin./, "string", "failed assert_match")
618
- }
619
- end
620
-
621
- def test_assert_same
622
- thing = "thing"
623
- check_nothing_fails {
624
- assert_same(thing, thing)
625
- }
626
- check_nothing_fails {
627
- assert_same(thing, thing, "successful assert_same")
628
- }
629
- check_nothing_fails {
630
- assert_same(thing, thing, "successful assert_same")
631
- }
632
- thing2 = "thing"
633
- check_fails(%Q{<"thing">\nwith id <#{thing.__id__}> expected to be equal? to\n<"thing">\nwith id <#{thing2.__id__}>.}) {
634
- assert_same(thing, thing2)
635
- }
636
- check_fails(%Q{failed assert_same.\n<"thing">\nwith id <#{thing.__id__}> expected to be equal? to\n<"thing">\nwith id <#{thing2.__id__}>.}) {
637
- assert_same(thing, thing2, "failed assert_same")
638
- }
639
- end
640
-
641
- def test_assert_nothing_raised
642
- check_nothing_fails {
643
- assert_nothing_raised {
644
- 1 + 1
645
- }
646
- }
647
- check_nothing_fails {
648
- assert_nothing_raised("successful assert_nothing_raised") {
649
- 1 + 1
650
- }
651
- }
652
- check_nothing_fails {
653
- assert_nothing_raised("successful assert_nothing_raised") {
654
- 1 + 1
655
- }
656
- }
657
- check_nothing_fails {
658
- begin
659
- assert_nothing_raised(RuntimeError, StandardError, Comparable, "successful assert_nothing_raised") {
660
- raise ZeroDivisionError.new("ArgumentError")
661
- }
662
- rescue ZeroDivisionError
663
- end
664
- }
665
- check_fails("Should expect a class of exception, Object.\n<false> is not true.") {
666
- assert_nothing_raised(Object) {
667
- 1 + 1
668
- }
669
- }
670
- check_fails(%r{\AException raised:\nClass: <RuntimeError>\nMessage: <"Error">\n---Backtrace---\n.+\n---------------\Z}m) {
671
- assert_nothing_raised {
672
- raise "Error"
673
- }
674
- }
675
- check_fails(%r{\Afailed assert_nothing_raised\.\nException raised:\nClass: <RuntimeError>\nMessage: <"Error">\n---Backtrace---\n.+\n---------------\Z}m) {
676
- assert_nothing_raised("failed assert_nothing_raised") {
677
- raise "Error"
678
- }
679
- }
680
- check_fails(%r{\AException raised:\nClass: <RuntimeError>\nMessage: <"Error">\n---Backtrace---\n.+\n---------------\Z}m) {
681
- assert_nothing_raised(StandardError, RuntimeError) {
682
- raise "Error"
683
- }
684
- }
685
- check_fails("Failure.") do
686
- assert_nothing_raised do
687
- flunk("Failure")
688
- end
689
- end
690
- end
691
-
692
- def test_flunk
693
- check_fails("Flunked.") {
694
- flunk
695
- }
696
- check_fails("flunk message.") {
697
- flunk("flunk message")
698
- }
699
- end
700
-
701
- def test_assert_not_same
702
- thing = "thing"
703
- thing2 = "thing"
704
- check_nothing_fails {
705
- assert_not_same(thing, thing2)
706
- }
707
- check_nothing_fails {
708
- assert_not_same(thing, thing2, "message")
709
- }
710
- check_fails(%Q{<"thing">\nwith id <#{thing.__id__}> expected to not be equal? to\n<"thing">\nwith id <#{thing.__id__}>.}) {
711
- assert_not_same(thing, thing)
712
- }
713
- check_fails(%Q{message.\n<"thing">\nwith id <#{thing.__id__}> expected to not be equal? to\n<"thing">\nwith id <#{thing.__id__}>.}) {
714
- assert_not_same(thing, thing, "message")
715
- }
716
- end
717
-
718
- def test_assert_not_equal
719
- check_nothing_fails {
720
- assert_not_equal("string1", "string2")
721
- }
722
- check_nothing_fails {
723
- assert_not_equal("string1", "string2", "message")
724
- }
725
- check_fails(%Q{<"string"> expected to be != to\n<"string">.}) {
726
- assert_not_equal("string", "string")
727
- }
728
- check_fails(%Q{message.\n<"string"> expected to be != to\n<"string">.}) {
729
- assert_not_equal("string", "string", "message")
730
- }
731
- end
732
-
733
- def test_assert_no_match
734
- check_nothing_fails{assert_no_match(/sling/, "string")}
735
- check_nothing_fails{assert_no_match(/sling/, "string", "message")}
736
- check_fails(%Q{The first argument to assert_no_match should be a Regexp.\n<"asdf"> expected to be an instance of\n<Regexp> but was\n<String>.}) do
737
- assert_no_match("asdf", "asdf")
738
- end
739
- check_fails(%Q{</string/> expected to not match\n<"string">.}) do
740
- assert_no_match(/string/, "string")
741
- end
742
- check_fails(%Q{message.\n</string/> expected to not match\n<"string">.}) do
743
- assert_no_match(/string/, "string", "message")
744
- end
745
- end
746
-
747
- def test_assert_throw
748
- check_nothing_fails do
749
- assert_throw(:thing, "message") do
750
- throw :thing
751
- end
752
- end
753
-
754
- tag = :thing2
755
- check_fails("message.\n" +
756
- "<:thing> expected to be thrown but\n" +
757
- "<#{inspect_tag(tag)}> was thrown.") do
758
- assert_throw(:thing, "message") do
759
- throw :thing2
760
- end
761
- end
762
- check_fails("message.\n" +
763
- "<:thing> should have been thrown.") do
764
- assert_throw(:thing, "message") do
765
- 1 + 1
766
- end
767
- end
768
- end
769
-
770
- def test_assert_nothing_thrown
771
- check_nothing_fails do
772
- assert_nothing_thrown("message") do
773
- 1 + 1
774
- end
775
- end
776
-
777
- tag = :thing
778
- inspected = inspect_tag(tag)
779
- check_fails("message.\n" +
780
- "<#{inspected}> was thrown when nothing was expected.") do
781
- assert_nothing_thrown("message") do
782
- throw tag
783
- end
784
- end
785
- end
786
-
787
- def test_assert_operator
788
- check_nothing_fails {
789
- assert_operator("thing", :==, "thing", "message")
790
- }
791
- check_fails(%Q{<0.15>\ngiven as the operator for #assert_operator must be a Symbol or #respond_to?(:to_str).}) do
792
- assert_operator("thing", 0.15, "thing")
793
- end
794
- check_fails(%Q{message.\n<"thing1"> expected to be\n==\n<"thing2">.}) {
795
- assert_operator("thing1", :==, "thing2", "message")
796
- }
797
- end
798
-
799
- def test_assert_respond_to
800
- check_nothing_fails {
801
- assert_respond_to("thing", :to_s, "message")
802
- }
803
- check_nothing_fails {
804
- assert_respond_to("thing", "to_s", "message")
805
- }
806
- check_fails("<0.15>.kind_of?(Symbol) or\n" +
807
- "<0.15>.respond_to?(:to_str) expected") {
808
- assert_respond_to("thing", 0.15)
809
- }
810
- check_fails("message.\n" +
811
- "<:symbol>.respond_to?(:non_existent) expected\n" +
812
- "(Class: <Symbol>)") {
813
- assert_respond_to(:symbol, :non_existent, "message")
814
- }
815
- end
816
-
817
- def test_assert_in_delta
818
- check_nothing_fails {
819
- assert_in_delta(1.4, 1.4, 0)
820
- }
821
- check_nothing_fails {
822
- assert_in_delta(0.5, 0.4, 0.1, "message")
823
- }
824
- check_nothing_fails {
825
- float_thing = Object.new
826
- def float_thing.to_f
827
- 0.2
828
- end
829
- assert_in_delta(0.1, float_thing, 0.1)
830
- }
831
- check_fails("message.\n" +
832
- "<0.5> expected but was\n" +
833
- "<0.4> (tolerance <0.05>).\n" +
834
- "\n" +
835
- "Relation:\n" +
836
- "<<0.4> < <0.5>-<0.05>(0.45) <= <0.5>+<0.05>(0.55)>") {
837
- assert_in_delta(0.5, 0.4, 0.05, "message")
838
- }
839
- object = Object.new
840
- inspected_object = AssertionMessage.convert(object)
841
- check_fails("The arguments must respond to to_f; " +
842
- "the first float did not.\n" +
843
- "<#{inspected_object}>.respond_to?(:to_f) expected\n" +
844
- "(Class: <Object>)") {
845
- assert_in_delta(object, 0.4, 0.1)
846
- }
847
- check_fails("The delta should not be negative.\n" +
848
- "<-0.1> expected to be\n>=\n<0.0>.") {
849
- assert_in_delta(0.5, 0.4, -0.1, "message")
850
- }
851
- end
852
-
853
- def test_assert_send
854
- object = Object.new
855
- class << object
856
- private
857
- def return_argument(argument, bogus)
858
- return argument
859
- end
860
- end
861
- check_nothing_fails {
862
- assert_send([object, :return_argument, true, "bogus"], "message")
863
- }
864
- check_fails(%r{\Amessage\.\n<.+> expected to respond to\n<return_argument\(\[false, "bogus"\]\)> with a true value.\Z}) {
865
- assert_send([object, :return_argument, false, "bogus"], "message")
866
- }
867
- end
868
-
869
- def test_condition_invariant
870
- object = Object.new
871
- def object.inspect
872
- @changed = true
873
- end
874
- def object.==(other)
875
- @changed ||= false
876
- return (!@changed)
877
- end
878
- check_nothing_fails do
879
- assert_equal(object, object, "message")
880
- end
881
- end
882
-
883
- def test_assert_boolean
884
- check_nothing_fails do
885
- assert_boolean(true)
886
- end
887
- check_nothing_fails do
888
- assert_boolean(false)
889
- end
890
-
891
- check_fails("<true> or <false> expected but was\n<1>") do
892
- assert_boolean(1)
893
- end
894
-
895
- check_fails("<true> or <false> expected but was\n<nil>") do
896
- assert_boolean(nil)
897
- end
898
-
899
- check_fails("message.\n<true> or <false> expected but was\n<\"XXX\">") do
900
- assert_boolean("XXX", "message")
901
- end
902
- end
903
-
904
- def test_assert_true
905
- check_nothing_fails do
906
- assert_true(true)
907
- end
908
-
909
- check_fails("<true> expected but was\n<false>") do
910
- assert_true(false)
911
- end
912
-
913
- check_fails("<true> expected but was\n<1>") do
914
- assert_true(1)
915
- end
916
-
917
- check_fails("message.\n<true> expected but was\n<nil>") do
918
- assert_true(nil, "message")
919
- end
920
- end
921
-
922
- def test_assert_false
923
- check_nothing_fails do
924
- assert_false(false)
925
- end
926
-
927
- check_fails("<false> expected but was\n<true>") do
928
- assert_false(true)
929
- end
930
-
931
- check_fails("<false> expected but was\n<nil>") do
932
- assert_false(nil)
933
- end
934
-
935
- check_fails("message.\n<false> expected but was\n<:false>") do
936
- assert_false(:false, "message")
937
- end
938
- end
939
-
940
- def test_assert_compare
941
- check_nothing_fails do
942
- assert_compare(1.4, "<", 10.0)
943
- end
944
-
945
- check_nothing_fails do
946
- assert_compare(2, "<=", 2)
947
- end
948
-
949
- check_nothing_fails do
950
- assert_compare(14, ">=", 10.0)
951
- end
952
-
953
- check_nothing_fails do
954
- assert_compare(14, ">", 13.9)
955
- end
956
-
957
- expected_message = <<-EOM
958
- <15> < <10> should be true
959
- <15> expected less than
960
- <10>.
961
- EOM
962
- check_fails(expected_message.chomp) do
963
- assert_compare(15, "<", 10)
964
- end
965
-
966
- expected_message = <<-EOM
967
- <15> <= <10> should be true
968
- <15> expected less than or equal to
969
- <10>.
970
- EOM
971
- check_fails(expected_message.chomp) do
972
- assert_compare(15, "<=", 10)
973
- end
974
-
975
- expected_message = <<-EOM
976
- <10> > <15> should be true
977
- <10> expected greater than
978
- <15>.
979
- EOM
980
- check_fails(expected_message.chomp) do
981
- assert_compare(10, ">", 15)
982
- end
983
-
984
- expected_message = <<-EOM
985
- <10> >= <15> should be true
986
- <10> expected greater than or equal to
987
- <15>.
988
- EOM
989
- check_fails(expected_message.chomp) do
990
- assert_compare(10, ">=", 15)
991
- end
992
- end
993
-
994
- def test_assert_fail_assertion
995
- check_nothing_fails do
996
- assert_fail_assertion do
997
- flunk
998
- end
999
- end
1000
-
1001
- check_fails("Failed assertion was expected.") do
1002
- assert_fail_assertion do
1003
- end
1004
- end
1005
- end
1006
-
1007
- def test_assert_raise_message
1008
- check_nothing_fails do
1009
- assert_raise_message("Raise!") do
1010
- raise "Raise!"
1011
- end
1012
- end
1013
-
1014
- check_nothing_fails do
1015
- assert_raise_message("Raise!") do
1016
- raise Exception, "Raise!"
1017
- end
1018
- end
1019
-
1020
- check_nothing_fails do
1021
- assert_raise_message(/raise/i) do
1022
- raise "Raise!"
1023
- end
1024
- end
1025
-
1026
- expected_message = <<-EOM
1027
- <"Expected message"> exception message expected but was
1028
- <"Actual message">.
1029
- EOM
1030
- check_fails(expected_message.chomp) do
1031
- assert_raise_message("Expected message") do
1032
- raise "Actual message"
1033
- end
1034
- end
1035
-
1036
- expected_message = <<-EOM
1037
- <"Expected message"> exception message expected but none was thrown.
1038
- EOM
1039
- check_fails(expected_message.chomp) do
1040
- assert_raise_message("Expected message") do
1041
- end
1042
- end
1043
- end
1044
-
1045
- def test_assert_raise_kind_of
1046
- check_nothing_fails(true) do
1047
- assert_raise_kind_of(SystemCallError) do
1048
- raise Errno::EACCES
1049
- end
1050
- end
1051
-
1052
- expected_message = <<-EOM
1053
- <SystemCallError> family exception expected but was
1054
- Class: <RuntimeError>
1055
- Message: <"XXX">
1056
- ---Backtrace---
1057
- EOM
1058
- check_fails(/\A#{Regexp.escape(expected_message)}(?m).+\z/) do
1059
- assert_raise_kind_of(SystemCallError) do
1060
- raise RuntimeError, "XXX"
1061
- end
1062
- end
1063
- end
1064
-
1065
- def test_assert_const_defined
1066
- check_nothing_fails do
1067
- assert_const_defined(Test, :Unit)
1068
- end
1069
-
1070
- check_nothing_fails do
1071
- assert_const_defined(Test, "Unit")
1072
- end
1073
-
1074
- check_fails("<Test>.const_defined?(<:Nonexistence>) expected.") do
1075
- assert_const_defined(Test, :Nonexistence)
1076
- end
1077
- end
1078
-
1079
- def test_assert_not_const_defined
1080
- check_nothing_fails do
1081
- assert_not_const_defined(Test, :Nonexistence)
1082
- end
1083
-
1084
- check_fails("!<Test>.const_defined?(<:Unit>) expected.") do
1085
- assert_not_const_defined(Test, :Unit)
1086
- end
1087
-
1088
- check_fails("!<Test>.const_defined?(<\"Unit\">) expected.") do
1089
- assert_not_const_defined(Test, "Unit")
1090
- end
1091
- end
1092
-
1093
- def test_assert_predicate
1094
- check_nothing_fails do
1095
- assert_predicate([], :empty?)
1096
- end
1097
-
1098
- check_fails("<[1]>.empty? is true value expected but was\n<false>") do
1099
- assert_predicate([1], :empty?)
1100
- end
1101
-
1102
- check_fails("<[1]>.respond_to?(:nonexistent?) expected\n" +
1103
- "(Class: <Array>)") do
1104
- assert_predicate([1], :nonexistent?)
1105
- end
1106
- end
1107
-
1108
- def test_assert_not_predicate
1109
- check_nothing_fails do
1110
- assert_not_predicate([1], :empty?)
1111
- end
1112
-
1113
- check_fails("<[]>.empty? is false value expected but was\n<true>") do
1114
- assert_not_predicate([], :empty?)
1115
- end
1116
-
1117
- check_fails("<[]>.respond_to?(:nonexistent?) expected\n" +
1118
- "(Class: <Array>)") do
1119
- assert_not_predicate([], :nonexistent?)
1120
- end
1121
- end
1122
-
1123
- def test_assert_alias_method
1124
- object = Object.new
1125
- class << object
1126
- def original_method
1127
- end
1128
- alias_method :alias_method, :original_method
1129
-
1130
- def other
1131
- end
1132
- end
1133
-
1134
- check_nothing_fails do
1135
- assert_alias_method(object, :alias_method, :original_method)
1136
- end
1137
-
1138
- check_nothing_fails do
1139
- assert_alias_method(object, :original_method, :alias_method)
1140
- end
1141
-
1142
- check_fails("<#{object.method(:other).inspect}> is alias of\n" +
1143
- "<#{object.method(:original_method).inspect}> expected") do
1144
- assert_alias_method(object, :other, :original_method)
1145
- end
1146
-
1147
- inspected_object = AssertionMessage.convert(object)
1148
- check_fails("<#{inspected_object}>.nonexistent doesn't exist\n" +
1149
- "(Class: <Object>)") do
1150
- assert_alias_method(object, :nonexistent, :original_method)
1151
- end
1152
-
1153
- check_fails("<#{inspected_object}>.nonexistent doesn't exist\n" +
1154
- "(Class: <Object>)") do
1155
- assert_alias_method(object, :alias_method, :nonexistent)
1156
- end
1157
- end
1158
-
1159
- def test_assert_path_exist
1160
- check_nothing_fails do
1161
- assert_path_exist(__FILE__)
1162
- end
1163
-
1164
- nonexistent_file = __FILE__ + ".nonexistent"
1165
- check_fails("<#{nonexistent_file.inspect}> expected to exist") do
1166
- assert_path_exist(nonexistent_file)
1167
- end
1168
- end
1169
-
1170
- def test_assert_path_not_exist
1171
- nonexistent_file = __FILE__ + ".nonexistent"
1172
- check_nothing_fails do
1173
- assert_path_not_exist(nonexistent_file)
1174
- end
1175
-
1176
- check_fails("<#{__FILE__.inspect}> expected to not exist") do
1177
- assert_path_not_exist(__FILE__)
1178
- end
1179
- end
1180
-
1181
- private
1182
- def add_failure(message, location=caller, options=nil)
1183
- unless @catch_assertions
1184
- super
1185
- end
1186
- end
1187
-
1188
- def add_assertion
1189
- if @catch_assertions
1190
- @actual_assertion_count += 1
1191
- else
1192
- super
1193
- end
1194
- end
1195
- end
1196
- end
1197
- end