activegroonga 0.0.1

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