test-unit 3.2.5 → 3.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/BSDL +24 -0
- data/COPYING +41 -44
- data/README.md +8 -11
- data/Rakefile +0 -23
- data/doc/text/getting-started.md +1 -1
- data/doc/text/news.md +366 -0
- data/lib/test/unit/assertion-failed-error.rb +35 -0
- data/lib/test/unit/assertions.rb +312 -112
- data/lib/test/unit/attribute.rb +7 -2
- data/lib/test/unit/autorunner.rb +79 -31
- data/lib/test/unit/code-snippet-fetcher.rb +7 -7
- data/lib/test/unit/collector/descendant.rb +1 -0
- data/lib/test/unit/collector/dir.rb +4 -2
- data/lib/test/unit/collector/load.rb +10 -13
- data/lib/test/unit/collector/objectspace.rb +1 -0
- data/lib/test/unit/collector.rb +31 -0
- data/lib/test/unit/color-scheme.rb +20 -2
- data/lib/test/unit/data-sets.rb +116 -0
- data/lib/test/unit/data.rb +121 -12
- data/lib/test/unit/diff.rb +2 -3
- data/lib/test/unit/fixture.rb +6 -0
- data/lib/test/unit/notification.rb +9 -7
- data/lib/test/unit/omission.rb +34 -31
- data/lib/test/unit/pending.rb +12 -11
- data/lib/test/unit/priority.rb +7 -3
- data/lib/test/unit/runner/console.rb +8 -0
- data/lib/test/unit/test-suite-creator.rb +22 -8
- data/lib/test/unit/testcase.rb +216 -146
- data/lib/test/unit/testsuite.rb +1 -1
- data/lib/test/unit/ui/console/testrunner.rb +92 -32
- data/lib/test/unit/util/memory-usage.rb +47 -0
- data/lib/test/unit/util/observable.rb +2 -2
- data/lib/test/unit/util/output.rb +5 -4
- data/lib/test/unit/util/procwrapper.rb +4 -4
- data/lib/test/unit/version.rb +1 -1
- data/lib/test/unit/warning.rb +3 -0
- data/lib/test/unit.rb +177 -161
- data/lib/test-unit.rb +2 -17
- metadata +13 -88
- data/GPL +0 -339
- data/LGPL +0 -502
- data/test/collector/test-descendant.rb +0 -182
- data/test/collector/test-load.rb +0 -442
- data/test/collector/test_dir.rb +0 -407
- data/test/collector/test_objectspace.rb +0 -102
- data/test/fixtures/header-label.csv +0 -3
- data/test/fixtures/header-label.tsv +0 -3
- data/test/fixtures/header.csv +0 -3
- data/test/fixtures/header.tsv +0 -3
- data/test/fixtures/no-header.csv +0 -2
- data/test/fixtures/no-header.tsv +0 -2
- data/test/fixtures/plus.csv +0 -3
- data/test/run-test.rb +0 -22
- data/test/test-assertions.rb +0 -2180
- data/test/test-attribute-matcher.rb +0 -38
- data/test/test-attribute.rb +0 -123
- data/test/test-code-snippet.rb +0 -37
- data/test/test-color-scheme.rb +0 -82
- data/test/test-color.rb +0 -47
- data/test/test-data.rb +0 -303
- data/test/test-diff.rb +0 -518
- data/test/test-emacs-runner.rb +0 -60
- data/test/test-error.rb +0 -26
- data/test/test-failure.rb +0 -33
- data/test/test-fault-location-detector.rb +0 -163
- data/test/test-fixture.rb +0 -713
- data/test/test-notification.rb +0 -33
- data/test/test-omission.rb +0 -81
- data/test/test-pending.rb +0 -70
- data/test/test-priority.rb +0 -173
- data/test/test-test-case.rb +0 -1278
- data/test/test-test-result.rb +0 -113
- data/test/test-test-suite-creator.rb +0 -97
- data/test/test-test-suite.rb +0 -151
- data/test/testunit-test-util.rb +0 -31
- data/test/ui/test_testrunmediator.rb +0 -20
- data/test/util/test-method-owner-finder.rb +0 -38
- data/test/util/test-output.rb +0 -11
- data/test/util/test_backtracefilter.rb +0 -52
- data/test/util/test_observable.rb +0 -102
- data/test/util/test_procwrapper.rb +0 -36
data/test/test-assertions.rb
DELETED
@@ -1,2180 +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-2014 Kouhei Sutou. All rights reserved.
|
6
|
-
# License:: Ruby license.
|
7
|
-
|
8
|
-
require 'test/unit'
|
9
|
-
require "testunit-test-util"
|
10
|
-
|
11
|
-
module Test
|
12
|
-
module Unit
|
13
|
-
module AssertionCheckable
|
14
|
-
include TestUnitTestUtil
|
15
|
-
|
16
|
-
private
|
17
|
-
def check(value, message="")
|
18
|
-
add_assertion
|
19
|
-
raise AssertionFailedError.new(message) unless value
|
20
|
-
end
|
21
|
-
|
22
|
-
def check_assertions(expect_fail, options={})
|
23
|
-
expected_message = options[:expected_message]
|
24
|
-
actual_message_normalizer = options[:actual_message_normalizer]
|
25
|
-
return_value_expected = options[:return_value_expected]
|
26
|
-
@actual_assertion_count = 0
|
27
|
-
failed = true
|
28
|
-
actual_message = nil
|
29
|
-
@catch_assertions = true
|
30
|
-
return_value = nil
|
31
|
-
begin
|
32
|
-
return_value = yield
|
33
|
-
failed = false
|
34
|
-
rescue AssertionFailedError => error
|
35
|
-
actual_message = error.message
|
36
|
-
end
|
37
|
-
@catch_assertions = false
|
38
|
-
|
39
|
-
if expect_fail
|
40
|
-
message = "Should have failed, but didn't"
|
41
|
-
else
|
42
|
-
message = "Should not have failed, but did with message\n" +
|
43
|
-
"<#{actual_message}>"
|
44
|
-
end
|
45
|
-
check(expect_fail == failed, message)
|
46
|
-
|
47
|
-
message = "Should have made one assertion but made\n" +
|
48
|
-
"<#{@actual_assertion_count}>"
|
49
|
-
check(1 == @actual_assertion_count, message)
|
50
|
-
|
51
|
-
if expect_fail
|
52
|
-
if actual_message_normalizer
|
53
|
-
actual_message = actual_message_normalizer.call(actual_message)
|
54
|
-
end
|
55
|
-
case expected_message
|
56
|
-
when String
|
57
|
-
check(expected_message == actual_message,
|
58
|
-
"Should have the correct message.\n" +
|
59
|
-
"<#{expected_message.inspect}> expected but was\n" +
|
60
|
-
"<#{actual_message.inspect}>")
|
61
|
-
when Regexp
|
62
|
-
check(expected_message =~ actual_message,
|
63
|
-
"The message should match correctly.\n" +
|
64
|
-
"</#{expected_message.source}/> expected to match\n" +
|
65
|
-
"<#{actual_message.inspect}>")
|
66
|
-
else
|
67
|
-
check(false,
|
68
|
-
"Incorrect expected message type in assert_nothing_failed")
|
69
|
-
end
|
70
|
-
else
|
71
|
-
case return_value_expected
|
72
|
-
when :dont_care
|
73
|
-
# do nothing
|
74
|
-
when true
|
75
|
-
check(!return_value.nil?, "Should return a value")
|
76
|
-
else
|
77
|
-
check(return_value.nil?,
|
78
|
-
"Should not return a value but returned <#{return_value}>")
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
return_value
|
83
|
-
end
|
84
|
-
|
85
|
-
def check_nothing_fails(return_value_expected=false, &proc)
|
86
|
-
check_assertions(false,
|
87
|
-
{:expected_message => nil,
|
88
|
-
:return_value_expected => return_value_expected},
|
89
|
-
&proc)
|
90
|
-
end
|
91
|
-
|
92
|
-
def check_fail(expected_message, options={}, &proc)
|
93
|
-
check_assertions(true,
|
94
|
-
options.merge(:expected_message => expected_message),
|
95
|
-
&proc)
|
96
|
-
end
|
97
|
-
|
98
|
-
def check_fail_exception(expected_message, options={}, &proc)
|
99
|
-
normalizer = lambda do |actual_message|
|
100
|
-
actual_message.gsub(/(^[^:\n]+:\d+:.+\n?)+\z/, "")
|
101
|
-
end
|
102
|
-
check_assertions(true,
|
103
|
-
options.merge(:expected_message => expected_message,
|
104
|
-
:actual_message_normalizer => normalizer),
|
105
|
-
&proc)
|
106
|
-
end
|
107
|
-
|
108
|
-
def inspect_tag(tag)
|
109
|
-
tag.inspect
|
110
|
-
end
|
111
|
-
|
112
|
-
def add_failure(message, location=caller, options=nil)
|
113
|
-
unless @catch_assertions
|
114
|
-
super
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def add_assertion
|
119
|
-
if @catch_assertions
|
120
|
-
@actual_assertion_count += 1
|
121
|
-
else
|
122
|
-
super
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
class TestAssertions < TestCase
|
128
|
-
include AssertionCheckable
|
129
|
-
|
130
|
-
class TestAssertBlock < self
|
131
|
-
def test_pass_without_message
|
132
|
-
check_nothing_fails {
|
133
|
-
assert_block {true}
|
134
|
-
}
|
135
|
-
end
|
136
|
-
|
137
|
-
def test_pass_with_message
|
138
|
-
check_nothing_fails {
|
139
|
-
assert_block("successful assert_block") {true}
|
140
|
-
}
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_failure_without_message
|
144
|
-
check_fail("assert_block failed.") {
|
145
|
-
assert_block {false}
|
146
|
-
}
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_failure_with_message
|
150
|
-
check_fail("failed assert_block") {
|
151
|
-
assert_block("failed assert_block") {false}
|
152
|
-
}
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
class TestAssertEqual < self
|
157
|
-
class TestSuccess < self
|
158
|
-
def test_without_message
|
159
|
-
check_nothing_fails {
|
160
|
-
assert_equal("string1", "string1")
|
161
|
-
}
|
162
|
-
end
|
163
|
-
|
164
|
-
def test_with_message
|
165
|
-
check_nothing_fails {
|
166
|
-
assert_equal("string1", "string1", "successful assert_equal")
|
167
|
-
}
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
class TestFailure < self
|
172
|
-
def test_without_message
|
173
|
-
message = <<-EOM.chomp
|
174
|
-
<"string1"> expected but was
|
175
|
-
<"string2">.
|
176
|
-
|
177
|
-
diff:
|
178
|
-
- string1
|
179
|
-
? ^
|
180
|
-
+ string2
|
181
|
-
? ^
|
182
|
-
EOM
|
183
|
-
check_fail(message) {
|
184
|
-
assert_equal("string1", "string2")
|
185
|
-
}
|
186
|
-
end
|
187
|
-
|
188
|
-
def test_with_message
|
189
|
-
message = <<-EOM.chomp
|
190
|
-
failed assert_equal.
|
191
|
-
<"string1"> expected but was
|
192
|
-
<"string2">.
|
193
|
-
|
194
|
-
diff:
|
195
|
-
- string1
|
196
|
-
? ^
|
197
|
-
+ string2
|
198
|
-
? ^
|
199
|
-
EOM
|
200
|
-
check_fail(message) {
|
201
|
-
assert_equal("string1", "string2", "failed assert_equal")
|
202
|
-
}
|
203
|
-
end
|
204
|
-
|
205
|
-
def test_with_message_proc
|
206
|
-
message = <<-EOM.chomp
|
207
|
-
failed assert_equal.
|
208
|
-
<"string1"> expected but was
|
209
|
-
<"string2">.
|
210
|
-
|
211
|
-
diff:
|
212
|
-
- string1
|
213
|
-
? ^
|
214
|
-
+ string2
|
215
|
-
? ^
|
216
|
-
EOM
|
217
|
-
check_fail(message) do
|
218
|
-
assert_equal("string1", "string2", lambda {"failed assert_equal"})
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
class TestSystemMessage < self
|
224
|
-
def test_different_type
|
225
|
-
message = <<-EOM.chomp
|
226
|
-
<"111111"> expected but was
|
227
|
-
<111111>.
|
228
|
-
|
229
|
-
diff:
|
230
|
-
- "111111"
|
231
|
-
? - -
|
232
|
-
+ 111111
|
233
|
-
EOM
|
234
|
-
check_fail(message) do
|
235
|
-
assert_equal("111111", 111111)
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
def test_long_line
|
240
|
-
expected = ["0123456789",
|
241
|
-
"1123456789",
|
242
|
-
"2123456789",
|
243
|
-
"3123456789",
|
244
|
-
"4123456789",
|
245
|
-
"5123456789",
|
246
|
-
"6123456789",
|
247
|
-
"7123456789",
|
248
|
-
"8123456789"].join
|
249
|
-
actual = ["0000000000",
|
250
|
-
"1123456789",
|
251
|
-
"2123456789",
|
252
|
-
"3123456789",
|
253
|
-
"4123456789",
|
254
|
-
"5123456789",
|
255
|
-
"6123456789",
|
256
|
-
"7123456789",
|
257
|
-
"8123456789"].join
|
258
|
-
message = <<-EOM.chomp
|
259
|
-
<"#{expected}"> expected but was
|
260
|
-
<"#{actual}">.
|
261
|
-
|
262
|
-
diff:
|
263
|
-
- #{expected}
|
264
|
-
? ^^^^^^^^^
|
265
|
-
+ #{actual}
|
266
|
-
? ^^^^^^^^^
|
267
|
-
|
268
|
-
folded diff:
|
269
|
-
- 012345678911234567892123456789312345678941234567895123456789612345678971234567
|
270
|
-
? ^^^^^^^^^
|
271
|
-
+ 000000000011234567892123456789312345678941234567895123456789612345678971234567
|
272
|
-
? ^^^^^^^^^
|
273
|
-
898123456789
|
274
|
-
EOM
|
275
|
-
check_fail(message) do
|
276
|
-
assert_equal(expected, actual)
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
def test_too_small_difference
|
281
|
-
message = <<-EOM.chomp
|
282
|
-
<1> expected but was
|
283
|
-
<2>.
|
284
|
-
EOM
|
285
|
-
check_fail(message) do
|
286
|
-
assert_equal(1, 2)
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
def test_same_inspected_objects
|
291
|
-
now = Time.now
|
292
|
-
now_without_usec = Time.at(now.to_i)
|
293
|
-
message = <<-EOM.chomp
|
294
|
-
<#{now.inspect}> expected but was
|
295
|
-
<#{now.inspect}>.
|
296
|
-
EOM
|
297
|
-
check_fail(message) do
|
298
|
-
assert_equal(now, now_without_usec)
|
299
|
-
end
|
300
|
-
end
|
301
|
-
|
302
|
-
def test_multi_lines_result
|
303
|
-
message = <<-EOM.chomp
|
304
|
-
<#{AssertionMessage.convert("a\nb")}> expected but was
|
305
|
-
<#{AssertionMessage.convert("x")}>.
|
306
|
-
|
307
|
-
diff:
|
308
|
-
+ x
|
309
|
-
- a
|
310
|
-
- b
|
311
|
-
EOM
|
312
|
-
check_fail(message) do
|
313
|
-
assert_equal("a\nb", "x")
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
def test_large_string
|
318
|
-
message = <<-EOM.chomp
|
319
|
-
<#{AssertionMessage.convert("a\n" + "x" * 997)}> expected but was
|
320
|
-
<#{AssertionMessage.convert("x")}>.
|
321
|
-
|
322
|
-
diff:
|
323
|
-
+ x
|
324
|
-
- a
|
325
|
-
- #{"x" * 997}
|
326
|
-
|
327
|
-
folded diff:
|
328
|
-
+ x
|
329
|
-
- a
|
330
|
-
#{(["- " + ("x" * 78)] * 12).join("\n")}
|
331
|
-
- #{"x" * 61}
|
332
|
-
EOM
|
333
|
-
check_fail(message) do
|
334
|
-
assert_equal("a\n" + "x" * 997, "x")
|
335
|
-
end
|
336
|
-
|
337
|
-
message = <<-EOM.chomp
|
338
|
-
<#{AssertionMessage.convert("a\n" + "x" * 998)}> expected but was
|
339
|
-
<#{AssertionMessage.convert("x")}>.
|
340
|
-
EOM
|
341
|
-
check_fail(message) do
|
342
|
-
assert_equal("a\n" + "x" * 998, "x")
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
346
|
-
def test_max_diff_target_string_size
|
347
|
-
key = "TEST_UNIT_MAX_DIFF_TARGET_STRING_SIZE"
|
348
|
-
before_value = ENV[key]
|
349
|
-
ENV[key] = "100"
|
350
|
-
begin
|
351
|
-
message = <<-EOM.chomp
|
352
|
-
<#{AssertionMessage.convert("a\n" + "x" * 97)}> expected but was
|
353
|
-
<#{AssertionMessage.convert("x")}>.
|
354
|
-
|
355
|
-
diff:
|
356
|
-
+ x
|
357
|
-
- a
|
358
|
-
- #{"x" * 97}
|
359
|
-
|
360
|
-
folded diff:
|
361
|
-
+ x
|
362
|
-
- a
|
363
|
-
#{(["- " + ("x" * 78)]).join("\n")}
|
364
|
-
- #{"x" * 19}
|
365
|
-
EOM
|
366
|
-
check_fail(message) do
|
367
|
-
assert_equal("a\n" + "x" * 97, "x")
|
368
|
-
end
|
369
|
-
|
370
|
-
message = <<-EOM.chomp
|
371
|
-
<#{AssertionMessage.convert("a\n" + "x" * 98)}> expected but was
|
372
|
-
<#{AssertionMessage.convert("x")}>.
|
373
|
-
EOM
|
374
|
-
check_fail(message) do
|
375
|
-
assert_equal("a\n" + "x" * 98, "x")
|
376
|
-
end
|
377
|
-
ensure
|
378
|
-
ENV[key] = before_value
|
379
|
-
end
|
380
|
-
end
|
381
|
-
|
382
|
-
def test_different_encoding
|
383
|
-
utf8_string = "こんにちは"
|
384
|
-
unless utf8_string.respond_to?(:force_encoding)
|
385
|
-
omit("encoding test is for Ruby >= 1.9")
|
386
|
-
end
|
387
|
-
ascii_8bit_string = utf8_string.dup.force_encoding("ascii-8bit")
|
388
|
-
message = <<-EOM.chomp
|
389
|
-
<#{utf8_string.inspect}>("UTF-8") expected but was
|
390
|
-
<#{ascii_8bit_string.inspect}>("ASCII-8BIT").
|
391
|
-
EOM
|
392
|
-
check_fail(message) do
|
393
|
-
assert_equal(utf8_string, ascii_8bit_string)
|
394
|
-
end
|
395
|
-
end
|
396
|
-
|
397
|
-
def test_different_hash
|
398
|
-
designers = {
|
399
|
-
"Ruby" => "Matz",
|
400
|
-
"Lisp" => "John McCarthy",
|
401
|
-
}
|
402
|
-
categories = {
|
403
|
-
"LL" => ["Ruby", "Python"],
|
404
|
-
"Heavy" => ["C", "C++"],
|
405
|
-
}
|
406
|
-
message = <<-EOM.chomp
|
407
|
-
<{"Lisp"=>"John McCarthy", "Ruby"=>"Matz"}> expected but was
|
408
|
-
<{"Heavy"=>["C", "C++"], "LL"=>["Ruby", "Python"]}>.
|
409
|
-
EOM
|
410
|
-
check_fail(message) do
|
411
|
-
assert_equal(designers, categories)
|
412
|
-
end
|
413
|
-
end
|
414
|
-
|
415
|
-
def test_recursive_hash
|
416
|
-
alice = {"name" => "Alice"}
|
417
|
-
bob = {"name" => "Bob"}
|
418
|
-
alice["followers"] = [bob]
|
419
|
-
bob["followers"] = [alice]
|
420
|
-
message = <<-EOM.chomp
|
421
|
-
<{"followers"=>[{"followers"=>[{...}], "name"=>"Bob"}], "name"=>"Alice"}> expected but was
|
422
|
-
<{"followers"=>[{"followers"=>[{...}], "name"=>"Alice"}], "name"=>"Bob"}>.
|
423
|
-
|
424
|
-
diff:
|
425
|
-
- {"followers"=>[{"followers"=>[{...}], "name"=>"Bob"}], "name"=>"Alice"}
|
426
|
-
? -----------------
|
427
|
-
+ {"followers"=>[{"followers"=>[{...}], "name"=>"Alice"}], "name"=>"Bob"}
|
428
|
-
? +++++++++++++++++
|
429
|
-
EOM
|
430
|
-
check_fail(message) do
|
431
|
-
assert_equal(alice, bob)
|
432
|
-
end
|
433
|
-
end
|
434
|
-
|
435
|
-
def test_numeric
|
436
|
-
numeric_family_class = Class.new(Numeric) do
|
437
|
-
def inspect
|
438
|
-
"inspect is called"
|
439
|
-
end
|
440
|
-
|
441
|
-
def to_s
|
442
|
-
"to_s is called"
|
443
|
-
end
|
444
|
-
end
|
445
|
-
numeric = numeric_family_class.new
|
446
|
-
|
447
|
-
message = <<-MESSAGE.chomp
|
448
|
-
<to_s is called> expected but was
|
449
|
-
<"must be failed">.
|
450
|
-
MESSAGE
|
451
|
-
check_fail(message) do
|
452
|
-
assert_equal(numeric, "must be failed")
|
453
|
-
end
|
454
|
-
end
|
455
|
-
end
|
456
|
-
end
|
457
|
-
|
458
|
-
def test_assert_raise_success
|
459
|
-
return_value = nil
|
460
|
-
check_nothing_fails(true) do
|
461
|
-
return_value = assert_raise(RuntimeError) do
|
462
|
-
raise "Error"
|
463
|
-
end
|
464
|
-
end
|
465
|
-
check(return_value.kind_of?(Exception),
|
466
|
-
"Should have returned the exception " +
|
467
|
-
"from a successful assert_raise")
|
468
|
-
check(return_value.message == "Error",
|
469
|
-
"Should have returned the correct exception " +
|
470
|
-
"from a successful assert_raise")
|
471
|
-
|
472
|
-
check_nothing_fails(true) do
|
473
|
-
assert_raise(ArgumentError, "successful assert_raise") do
|
474
|
-
raise ArgumentError.new("Error")
|
475
|
-
end
|
476
|
-
end
|
477
|
-
|
478
|
-
check_nothing_fails(true) do
|
479
|
-
assert_raise(RuntimeError) do
|
480
|
-
raise "Error"
|
481
|
-
end
|
482
|
-
end
|
483
|
-
|
484
|
-
check_nothing_fails(true) do
|
485
|
-
assert_raise(RuntimeError, "successful assert_raise") do
|
486
|
-
raise "Error"
|
487
|
-
end
|
488
|
-
end
|
489
|
-
|
490
|
-
check_nothing_fails(true) do
|
491
|
-
assert_raise do
|
492
|
-
raise Exception, "Any exception"
|
493
|
-
end
|
494
|
-
end
|
495
|
-
end
|
496
|
-
|
497
|
-
def test_assert_raise_fail
|
498
|
-
check_fail("<RuntimeError> exception was expected but none was thrown.") do
|
499
|
-
assert_raise(RuntimeError) do
|
500
|
-
1 + 1
|
501
|
-
end
|
502
|
-
end
|
503
|
-
|
504
|
-
message = <<-EOM.chomp
|
505
|
-
failed assert_raise.
|
506
|
-
<ArgumentError> exception expected but was
|
507
|
-
<RuntimeError(<Error>)>.
|
508
|
-
EOM
|
509
|
-
check_fail_exception(message) do
|
510
|
-
assert_raise(ArgumentError, "failed assert_raise") do
|
511
|
-
raise "Error"
|
512
|
-
end
|
513
|
-
end
|
514
|
-
|
515
|
-
message = <<-EOM
|
516
|
-
<Object> must be a subclass of Exception, an object of Exception subclasses or a Module.
|
517
|
-
EOM
|
518
|
-
check_fail(message.chomp) do
|
519
|
-
assert_nothing_raised(Object) do
|
520
|
-
1 + 1
|
521
|
-
end
|
522
|
-
end
|
523
|
-
end
|
524
|
-
|
525
|
-
def test_assert_raise_module
|
526
|
-
exceptions = [ArgumentError, TypeError]
|
527
|
-
modules = [Math, Comparable]
|
528
|
-
rescues = exceptions + modules
|
529
|
-
|
530
|
-
exceptions.each do |exc|
|
531
|
-
return_value = nil
|
532
|
-
check_nothing_fails(true) do
|
533
|
-
return_value = assert_raise(*rescues) do
|
534
|
-
raise exc, "Error"
|
535
|
-
end
|
536
|
-
end
|
537
|
-
check(return_value.instance_of?(exc),
|
538
|
-
"Should have returned #{exc} but was #{return_value.class}")
|
539
|
-
check(return_value.message == "Error",
|
540
|
-
"Should have returned the correct exception " +
|
541
|
-
"from a successful assert_raise")
|
542
|
-
end
|
543
|
-
|
544
|
-
modules.each do |mod|
|
545
|
-
return_value = nil
|
546
|
-
check_nothing_fails(true) do
|
547
|
-
return_value = assert_raise(*rescues) do
|
548
|
-
raise Exception.new("Error").extend(mod)
|
549
|
-
end
|
550
|
-
end
|
551
|
-
check(mod === return_value,
|
552
|
-
"Should have returned #{mod}")
|
553
|
-
check(return_value.message == "Error",
|
554
|
-
"Should have returned the correct exception " +
|
555
|
-
"from a successful assert_raise")
|
556
|
-
end
|
557
|
-
|
558
|
-
check_fail("<[ArgumentError, TypeError, Math, Comparable]> exception " +
|
559
|
-
"was expected but none was thrown.") do
|
560
|
-
assert_raise(*rescues) do
|
561
|
-
1 + 1
|
562
|
-
end
|
563
|
-
end
|
564
|
-
|
565
|
-
message = <<-EOM.chomp
|
566
|
-
failed assert_raise.
|
567
|
-
<[ArgumentError, TypeError]> exception expected but was
|
568
|
-
<RuntimeError(<Error>)>.
|
569
|
-
EOM
|
570
|
-
check_fail_exception(message) do
|
571
|
-
assert_raise(ArgumentError, TypeError, "failed assert_raise") do
|
572
|
-
raise "Error"
|
573
|
-
end
|
574
|
-
end
|
575
|
-
end
|
576
|
-
|
577
|
-
def test_assert_raise_instance
|
578
|
-
return_value = nil
|
579
|
-
check_nothing_fails(true) do
|
580
|
-
return_value = assert_raise(RuntimeError.new("Error")) do
|
581
|
-
raise "Error"
|
582
|
-
end
|
583
|
-
end
|
584
|
-
check(return_value.kind_of?(Exception),
|
585
|
-
"Should have returned the exception " +
|
586
|
-
"from a successful assert_raise")
|
587
|
-
check(return_value.message == "Error",
|
588
|
-
"Should have returned the correct exception " +
|
589
|
-
"from a successful assert_raise")
|
590
|
-
|
591
|
-
message = <<-EOM.chomp
|
592
|
-
<RuntimeError(<XXX>)> exception expected but was
|
593
|
-
<RuntimeError(<Error>)>.
|
594
|
-
|
595
|
-
diff:
|
596
|
-
- RuntimeError(<XXX>)
|
597
|
-
? ^^^
|
598
|
-
+ RuntimeError(<Error>)
|
599
|
-
? ^^^^^
|
600
|
-
EOM
|
601
|
-
check_fail_exception(message) do
|
602
|
-
return_value = assert_raise(RuntimeError.new("XXX")) do
|
603
|
-
raise "Error"
|
604
|
-
end
|
605
|
-
end
|
606
|
-
|
607
|
-
different_error_class = Class.new(StandardError)
|
608
|
-
message = <<-EOM.chomp
|
609
|
-
<#{different_error_class.inspect}(<Error>)> exception expected but was
|
610
|
-
<RuntimeError(<Error>)>.
|
611
|
-
EOM
|
612
|
-
check_fail_exception(message) do
|
613
|
-
assert_raise(different_error_class.new("Error")) do
|
614
|
-
raise "Error"
|
615
|
-
end
|
616
|
-
end
|
617
|
-
|
618
|
-
different_error = different_error_class.new("Error")
|
619
|
-
def different_error.inspect
|
620
|
-
"DifferentError: \"Error\""
|
621
|
-
end
|
622
|
-
message = <<-EOM.chomp
|
623
|
-
<DifferentError: "Error"> exception expected but was
|
624
|
-
<RuntimeError(<Error>)>.
|
625
|
-
EOM
|
626
|
-
check_fail_exception(message) do
|
627
|
-
assert_raise(different_error) do
|
628
|
-
raise "Error"
|
629
|
-
end
|
630
|
-
end
|
631
|
-
|
632
|
-
check_nothing_fails(true) do
|
633
|
-
assert_raise(different_error_class.new("Error"),
|
634
|
-
RuntimeError.new("Error"),
|
635
|
-
RuntimeError.new("XXX")) do
|
636
|
-
raise "Error"
|
637
|
-
end
|
638
|
-
end
|
639
|
-
end
|
640
|
-
|
641
|
-
def test_assert_raise_jruby
|
642
|
-
omit("For JRuby") unless Object.const_defined?(:Java)
|
643
|
-
|
644
|
-
exception = Java::JavaLang::StringIndexOutOfBoundsException
|
645
|
-
|
646
|
-
return_value = nil
|
647
|
-
check_nothing_fails(true) do
|
648
|
-
return_value = assert_raise(exception) do
|
649
|
-
Java::JavaLang::String.new("abc").char_at(4)
|
650
|
-
end
|
651
|
-
end
|
652
|
-
check(return_value.instance_of?(exception),
|
653
|
-
"Should have returned #{exception} but was #{return_value.class}")
|
654
|
-
end
|
655
|
-
|
656
|
-
def test_assert_instance_of
|
657
|
-
check_nothing_fails {
|
658
|
-
assert_instance_of(String, "string")
|
659
|
-
}
|
660
|
-
check_nothing_fails {
|
661
|
-
assert_instance_of(String, "string", "successful assert_instance_of")
|
662
|
-
}
|
663
|
-
check_nothing_fails {
|
664
|
-
assert_instance_of(String, "string", "successful assert_instance_of")
|
665
|
-
}
|
666
|
-
check_fail(%Q{<"string"> was expected to be instance_of?\n<Hash> but was\n<String>.}) {
|
667
|
-
assert_instance_of(Hash, "string")
|
668
|
-
}
|
669
|
-
check_fail(%Q{failed assert_instance_of.\n<"string"> was expected to be instance_of?\n<Hash> but was\n<String>.}) {
|
670
|
-
assert_instance_of(Hash, "string", "failed assert_instance_of")
|
671
|
-
}
|
672
|
-
|
673
|
-
check_nothing_fails do
|
674
|
-
assert_instance_of([Class, NilClass], Array)
|
675
|
-
end
|
676
|
-
check_fail(%Q{<"string"> was expected to be instance_of?\n[<Class>, <NilClass>] but was\n<String>.}) do
|
677
|
-
assert_instance_of([Class, NilClass], "string")
|
678
|
-
end
|
679
|
-
check_fail(%Q{<Array> was expected to be instance_of?\n[<Module>, <NilClass>] but was\n<Class>.}) do
|
680
|
-
assert_instance_of([Module, NilClass], Array)
|
681
|
-
end
|
682
|
-
end
|
683
|
-
|
684
|
-
def test_assert_not_instance_of
|
685
|
-
check_nothing_fails {
|
686
|
-
assert_not_instance_of(NilClass, "string")
|
687
|
-
}
|
688
|
-
check_nothing_fails {
|
689
|
-
assert_not_instance_of(NilClass, "string", "successful assert_instance_of")
|
690
|
-
}
|
691
|
-
check_fail(%Q{<"string"> was expected to not be instance_of?\n<String> but was.}) {
|
692
|
-
assert_not_instance_of(String, "string")
|
693
|
-
}
|
694
|
-
check_fail(%Q{failed assert.\n<"string"> was expected to not be instance_of?\n<String> but was.}) {
|
695
|
-
assert_not_instance_of(String, "string", "failed assert")
|
696
|
-
}
|
697
|
-
|
698
|
-
check_nothing_fails do
|
699
|
-
assert_not_instance_of([Module, NilClass], Array)
|
700
|
-
end
|
701
|
-
check_fail(%Q{<Array> was expected to not be instance_of?\n[<Class>, <NilClass>] but was.}) do
|
702
|
-
assert_not_instance_of([Class, NilClass], Array)
|
703
|
-
end
|
704
|
-
check_fail(%Q{<"str"> was expected to not be instance_of?\n[<Numeric>, <String>] but was.}) do
|
705
|
-
assert_not_instance_of([Numeric, String], 'str')
|
706
|
-
end
|
707
|
-
end
|
708
|
-
|
709
|
-
def test_assert_nil
|
710
|
-
check_nothing_fails {
|
711
|
-
assert_nil(nil)
|
712
|
-
}
|
713
|
-
check_nothing_fails {
|
714
|
-
assert_nil(nil, "successful assert_nil")
|
715
|
-
}
|
716
|
-
check_nothing_fails {
|
717
|
-
assert_nil(nil, "successful assert_nil")
|
718
|
-
}
|
719
|
-
check_fail(%Q{<"string"> was expected to be nil.}) {
|
720
|
-
assert_nil("string")
|
721
|
-
}
|
722
|
-
check_fail(%Q{failed assert_nil.\n<"string"> was expected to be nil.}) {
|
723
|
-
assert_nil("string", "failed assert_nil")
|
724
|
-
}
|
725
|
-
end
|
726
|
-
|
727
|
-
def test_assert_not_nil
|
728
|
-
check_nothing_fails{assert_not_nil(false)}
|
729
|
-
check_nothing_fails{assert_not_nil(false, "message")}
|
730
|
-
check_fail("<nil> was expected to not be nil."){assert_not_nil(nil)}
|
731
|
-
check_fail("message.\n<nil> was expected to not be nil.") {assert_not_nil(nil, "message")}
|
732
|
-
end
|
733
|
-
|
734
|
-
def test_assert_kind_of
|
735
|
-
check_nothing_fails {
|
736
|
-
assert_kind_of(Module, Array)
|
737
|
-
}
|
738
|
-
check_nothing_fails {
|
739
|
-
assert_kind_of(Object, "string", "successful assert_kind_of")
|
740
|
-
}
|
741
|
-
check_nothing_fails {
|
742
|
-
assert_kind_of(String, "string", "successful assert_kind_of")
|
743
|
-
}
|
744
|
-
check_nothing_fails {
|
745
|
-
assert_kind_of(Comparable, 1)
|
746
|
-
}
|
747
|
-
check_fail(%Q{<"string"> was expected to be kind_of?\n<Class> but was\n<String>.}) {
|
748
|
-
assert_kind_of(Class, "string")
|
749
|
-
}
|
750
|
-
check_fail(%Q{failed assert_kind_of.\n<"string"> was expected to be kind_of?\n<Class> but was\n<String>.}) {
|
751
|
-
assert_kind_of(Class, "string", "failed assert_kind_of")
|
752
|
-
}
|
753
|
-
|
754
|
-
check_nothing_fails do
|
755
|
-
assert_kind_of([Class, NilClass], Array)
|
756
|
-
end
|
757
|
-
check_fail(%Q{<"string"> was expected to be kind_of?\n[<Class>, <NilClass>] but was\n<String>.}) do
|
758
|
-
assert_kind_of([Class, NilClass], "string")
|
759
|
-
end
|
760
|
-
end
|
761
|
-
|
762
|
-
def test_assert_not_kind_of
|
763
|
-
check_nothing_fails {
|
764
|
-
assert_not_kind_of(Class, 42)
|
765
|
-
}
|
766
|
-
check_nothing_fails {
|
767
|
-
assert_not_kind_of(Symbol, "string", "successful assert_not_kind_of")
|
768
|
-
}
|
769
|
-
check_nothing_fails {
|
770
|
-
assert_not_kind_of(Integer, 1.1)
|
771
|
-
}
|
772
|
-
check_fail(%Q{<1> was expected to not be kind_of?\n<Integer> but was.}) {
|
773
|
-
assert_not_kind_of(Integer, 1)
|
774
|
-
}
|
775
|
-
check_fail(%Q{failed assert_not_kind_of.\n<"string"> was expected to not be kind_of?\n<String> but was.}) {
|
776
|
-
assert_not_kind_of(String, "string", "failed assert_not_kind_of")
|
777
|
-
}
|
778
|
-
|
779
|
-
check_nothing_fails do
|
780
|
-
assert_not_kind_of([String, NilClass], 100)
|
781
|
-
end
|
782
|
-
check_fail(%Q{<Array> was expected to not be kind_of?\n[<Class>, <NilClass>] but was.}) do
|
783
|
-
assert_not_kind_of([Class, NilClass], Array)
|
784
|
-
end
|
785
|
-
end
|
786
|
-
|
787
|
-
def test_assert_match
|
788
|
-
check_nothing_fails {
|
789
|
-
assert_match(/strin./, "string")
|
790
|
-
}
|
791
|
-
check_nothing_fails {
|
792
|
-
assert_match("strin", "string")
|
793
|
-
}
|
794
|
-
check_nothing_fails {
|
795
|
-
assert_match(/strin./, "string", "successful assert_match")
|
796
|
-
}
|
797
|
-
check_nothing_fails {
|
798
|
-
assert_match(/strin./, "string", "successful assert_match")
|
799
|
-
}
|
800
|
-
check_fail(%Q{</slin./> was expected to be =~\n<"string">.}) {
|
801
|
-
assert_match(/slin./, "string")
|
802
|
-
}
|
803
|
-
check_fail(%Q{</strin\\./> was expected to be =~\n<"string">.}) {
|
804
|
-
assert_match("strin.", "string")
|
805
|
-
}
|
806
|
-
check_fail(%Q{failed assert_match.\n</slin./> was expected to be =~\n<"string">.}) {
|
807
|
-
assert_match(/slin./, "string", "failed assert_match")
|
808
|
-
}
|
809
|
-
end
|
810
|
-
|
811
|
-
def test_assert_same
|
812
|
-
thing = "thing"
|
813
|
-
check_nothing_fails {
|
814
|
-
assert_same(thing, thing)
|
815
|
-
}
|
816
|
-
check_nothing_fails {
|
817
|
-
assert_same(thing, thing, "successful assert_same")
|
818
|
-
}
|
819
|
-
check_nothing_fails {
|
820
|
-
assert_same(thing, thing, "successful assert_same")
|
821
|
-
}
|
822
|
-
thing2 = thing.dup
|
823
|
-
check_fail(%Q{<"thing">\nwith id <#{thing.__id__}> was expected to be equal? to\n<"thing">\nwith id <#{thing2.__id__}>.}) {
|
824
|
-
assert_same(thing, thing2)
|
825
|
-
}
|
826
|
-
check_fail(%Q{failed assert_same.\n<"thing">\nwith id <#{thing.__id__}> was expected to be equal? to\n<"thing">\nwith id <#{thing2.__id__}>.}) {
|
827
|
-
assert_same(thing, thing2, "failed assert_same")
|
828
|
-
}
|
829
|
-
end
|
830
|
-
|
831
|
-
def test_assert_nothing_raised
|
832
|
-
check_nothing_fails(:dont_care) {
|
833
|
-
assert_nothing_raised {
|
834
|
-
1 + 1
|
835
|
-
}
|
836
|
-
}
|
837
|
-
check_nothing_fails(:dont_care) {
|
838
|
-
assert_nothing_raised("successful assert_nothing_raised") {
|
839
|
-
1 + 1
|
840
|
-
}
|
841
|
-
}
|
842
|
-
check_nothing_fails(:dont_care) {
|
843
|
-
assert_nothing_raised("successful assert_nothing_raised") {
|
844
|
-
1 + 1
|
845
|
-
}
|
846
|
-
}
|
847
|
-
check_nothing_fails(:dont_care) {
|
848
|
-
begin
|
849
|
-
assert_nothing_raised(RuntimeError, StandardError, Comparable, "successful assert_nothing_raised") {
|
850
|
-
raise ZeroDivisionError.new("ArgumentError")
|
851
|
-
}
|
852
|
-
rescue ZeroDivisionError
|
853
|
-
end
|
854
|
-
}
|
855
|
-
expected_message =
|
856
|
-
"<Object> must be a subclass of Exception, " +
|
857
|
-
"an object of Exception subclasses or a Module."
|
858
|
-
check_fail(expected_message) {
|
859
|
-
assert_nothing_raised(Object) {
|
860
|
-
1 + 1
|
861
|
-
}
|
862
|
-
}
|
863
|
-
expected_message = <<-EOM.chomp
|
864
|
-
Exception raised:
|
865
|
-
RuntimeError(<Error>)
|
866
|
-
EOM
|
867
|
-
check_fail_exception(expected_message) {
|
868
|
-
assert_nothing_raised {
|
869
|
-
raise "Error"
|
870
|
-
}
|
871
|
-
}
|
872
|
-
expected_message = <<-EOM.chomp
|
873
|
-
failed assert_nothing_raised.
|
874
|
-
Exception raised:
|
875
|
-
RuntimeError(<Error>)
|
876
|
-
EOM
|
877
|
-
check_fail_exception(expected_message) {
|
878
|
-
assert_nothing_raised("failed assert_nothing_raised") {
|
879
|
-
raise "Error"
|
880
|
-
}
|
881
|
-
}
|
882
|
-
expected_message = <<-EOM.chomp
|
883
|
-
Exception raised:
|
884
|
-
RuntimeError(<Error>)
|
885
|
-
EOM
|
886
|
-
check_fail_exception(expected_message) {
|
887
|
-
assert_nothing_raised(StandardError, RuntimeError) {
|
888
|
-
raise "Error"
|
889
|
-
}
|
890
|
-
}
|
891
|
-
check_fail("Failure.") do
|
892
|
-
assert_nothing_raised do
|
893
|
-
flunk("Failure")
|
894
|
-
end
|
895
|
-
end
|
896
|
-
end
|
897
|
-
|
898
|
-
def test_flunk
|
899
|
-
check_fail("Flunked.") {
|
900
|
-
flunk
|
901
|
-
}
|
902
|
-
check_fail("flunk message.") {
|
903
|
-
flunk("flunk message")
|
904
|
-
}
|
905
|
-
end
|
906
|
-
|
907
|
-
def test_assert_not_same
|
908
|
-
thing = "thing"
|
909
|
-
thing2 = thing.dup
|
910
|
-
check_nothing_fails {
|
911
|
-
assert_not_same(thing, thing2)
|
912
|
-
}
|
913
|
-
check_nothing_fails {
|
914
|
-
assert_not_same(thing, thing2, "message")
|
915
|
-
}
|
916
|
-
check_fail(%Q{<"thing">\nwith id <#{thing.__id__}> was expected to not be equal? to\n<"thing">\nwith id <#{thing.__id__}>.}) {
|
917
|
-
assert_not_same(thing, thing)
|
918
|
-
}
|
919
|
-
check_fail(%Q{message.\n<"thing">\nwith id <#{thing.__id__}> was expected to not be equal? to\n<"thing">\nwith id <#{thing.__id__}>.}) {
|
920
|
-
assert_not_same(thing, thing, "message")
|
921
|
-
}
|
922
|
-
end
|
923
|
-
|
924
|
-
def test_assert_not_equal
|
925
|
-
check_nothing_fails {
|
926
|
-
assert_not_equal("string1", "string2")
|
927
|
-
}
|
928
|
-
check_nothing_fails {
|
929
|
-
assert_not_equal("string1", "string2", "message")
|
930
|
-
}
|
931
|
-
check_fail(%Q{<"string"> was expected to be != to\n<"string">.}) {
|
932
|
-
assert_not_equal("string", "string")
|
933
|
-
}
|
934
|
-
check_fail(%Q{message.\n<"string"> was expected to be != to\n<"string">.}) {
|
935
|
-
assert_not_equal("string", "string", "message")
|
936
|
-
}
|
937
|
-
end
|
938
|
-
|
939
|
-
def test_assert_not_match_pass
|
940
|
-
check_nothing_fails do
|
941
|
-
assert_not_match(/sling/, "string")
|
942
|
-
end
|
943
|
-
end
|
944
|
-
|
945
|
-
def test_assert_not_match_pass_with_message
|
946
|
-
check_nothing_fails do
|
947
|
-
assert_not_match(/sling/, "string", "message")
|
948
|
-
end
|
949
|
-
end
|
950
|
-
|
951
|
-
def test_assert_not_match_fail_not_regexp
|
952
|
-
check_fail("<REGEXP> in assert_not_match(<REGEXP>, ...) " +
|
953
|
-
"should be a Regexp.\n" +
|
954
|
-
"<\"asdf\"> was expected to be instance_of?\n" +
|
955
|
-
"<Regexp> but was\n" +
|
956
|
-
"<String>.") do
|
957
|
-
assert_not_match("asdf", "asdf")
|
958
|
-
end
|
959
|
-
end
|
960
|
-
|
961
|
-
def test_assert_not_match_fail_match
|
962
|
-
check_fail("</string/> was expected to not match\n" +
|
963
|
-
"<\"string\">.") do
|
964
|
-
assert_not_match(/string/, "string")
|
965
|
-
end
|
966
|
-
end
|
967
|
-
|
968
|
-
def test_assert_not_match_fail_match_with_message
|
969
|
-
check_fail("message.\n" +
|
970
|
-
"</string/> was expected to not match\n" +
|
971
|
-
"<\"string\">.") do
|
972
|
-
assert_not_match(/string/, "string", "message")
|
973
|
-
end
|
974
|
-
end
|
975
|
-
|
976
|
-
def test_assert_no_match
|
977
|
-
check_nothing_fails{assert_no_match(/sling/, "string")}
|
978
|
-
check_nothing_fails{assert_no_match(/sling/, "string", "message")}
|
979
|
-
check_fail(%Q{The first argument to assert_no_match should be a Regexp.\n<"asdf"> was expected to be instance_of?\n<Regexp> but was\n<String>.}) do
|
980
|
-
assert_no_match("asdf", "asdf")
|
981
|
-
end
|
982
|
-
check_fail(%Q{</string/> was expected to not match\n<"string">.}) do
|
983
|
-
assert_no_match(/string/, "string")
|
984
|
-
end
|
985
|
-
check_fail(%Q{message.\n</string/> was expected to not match\n<"string">.}) do
|
986
|
-
assert_no_match(/string/, "string", "message")
|
987
|
-
end
|
988
|
-
end
|
989
|
-
|
990
|
-
def test_assert_throw
|
991
|
-
check_nothing_fails do
|
992
|
-
assert_throw(:thing, "message") do
|
993
|
-
throw :thing
|
994
|
-
end
|
995
|
-
end
|
996
|
-
|
997
|
-
tag = :thing2
|
998
|
-
check_fail("message.\n" +
|
999
|
-
"<:thing> was expected to be thrown but\n" +
|
1000
|
-
"<#{inspect_tag(tag)}> was thrown.") do
|
1001
|
-
assert_throw(:thing, "message") do
|
1002
|
-
throw :thing2
|
1003
|
-
end
|
1004
|
-
end
|
1005
|
-
check_fail("message.\n" +
|
1006
|
-
"<:thing> should have been thrown.") do
|
1007
|
-
assert_throw(:thing, "message") do
|
1008
|
-
1 + 1
|
1009
|
-
end
|
1010
|
-
end
|
1011
|
-
end
|
1012
|
-
|
1013
|
-
def test_assert_nothing_thrown
|
1014
|
-
check_nothing_fails do
|
1015
|
-
assert_nothing_thrown("message") do
|
1016
|
-
1 + 1
|
1017
|
-
end
|
1018
|
-
end
|
1019
|
-
|
1020
|
-
tag = :thing
|
1021
|
-
inspected = inspect_tag(tag)
|
1022
|
-
check_fail("message.\n" +
|
1023
|
-
"<#{inspected}> was thrown when nothing was expected.") do
|
1024
|
-
assert_nothing_thrown("message") do
|
1025
|
-
throw tag
|
1026
|
-
end
|
1027
|
-
end
|
1028
|
-
end
|
1029
|
-
|
1030
|
-
def test_assert_operator
|
1031
|
-
check_nothing_fails {
|
1032
|
-
assert_operator("thing", :==, "thing", "message")
|
1033
|
-
}
|
1034
|
-
check_fail(%Q{<0.15>\ngiven as the operator for #assert_operator must be a Symbol or #respond_to?(:to_str).}) do
|
1035
|
-
assert_operator("thing", 0.15, "thing")
|
1036
|
-
end
|
1037
|
-
check_fail(%Q{message.\n<"thing1"> was expected to be\n==\n<"thing2">.}) {
|
1038
|
-
assert_operator("thing1", :==, "thing2", "message")
|
1039
|
-
}
|
1040
|
-
end
|
1041
|
-
|
1042
|
-
def test_assert_not_operator
|
1043
|
-
check_nothing_fails {
|
1044
|
-
assert_not_operator("thing", :==, "Thing", "message")
|
1045
|
-
}
|
1046
|
-
check_fail(%Q{<42>\ngiven as the operator for #assert_not_operator must be a Symbol or #respond_to?(:to_str).}) do
|
1047
|
-
assert_not_operator("thing", 42, "message")
|
1048
|
-
end
|
1049
|
-
check_fail(%Q{message.\n<0> was expected to not be\n==\n<0.0>.}) {
|
1050
|
-
assert_not_operator(0, :==, 0.0, "message")
|
1051
|
-
}
|
1052
|
-
end
|
1053
|
-
|
1054
|
-
def test_assert_respond_to
|
1055
|
-
check_nothing_fails {
|
1056
|
-
assert_respond_to("thing", :to_s, "message")
|
1057
|
-
}
|
1058
|
-
check_nothing_fails {
|
1059
|
-
assert_respond_to("thing", "to_s", "message")
|
1060
|
-
}
|
1061
|
-
check_fail("<0.15>.kind_of?(Symbol) or\n" +
|
1062
|
-
"<0.15>.respond_to?(:to_str) expected") {
|
1063
|
-
assert_respond_to("thing", 0.15)
|
1064
|
-
}
|
1065
|
-
check_fail("message.\n" +
|
1066
|
-
"<:symbol>.respond_to?(:nonexistence) expected\n" +
|
1067
|
-
"(Class: <Symbol>)") {
|
1068
|
-
assert_respond_to(:symbol, :nonexistence, "message")
|
1069
|
-
}
|
1070
|
-
end
|
1071
|
-
|
1072
|
-
def test_assert_not_respond_to_pass_symbol
|
1073
|
-
check_nothing_fails do
|
1074
|
-
assert_not_respond_to("thing", :nonexistent, "message")
|
1075
|
-
end
|
1076
|
-
end
|
1077
|
-
|
1078
|
-
def test_assert_not_respond_to_pass_string
|
1079
|
-
check_nothing_fails do
|
1080
|
-
assert_not_respond_to("thing", :nonexistent, "message")
|
1081
|
-
end
|
1082
|
-
end
|
1083
|
-
|
1084
|
-
def test_assert_not_respond_to_fail_number
|
1085
|
-
check_fail("<0.15>.kind_of?(Symbol) or\n" +
|
1086
|
-
"<0.15>.respond_to?(:to_str) expected") do
|
1087
|
-
assert_respond_to("thing", 0.15)
|
1088
|
-
end
|
1089
|
-
end
|
1090
|
-
|
1091
|
-
def tset_assert_not_respond_to_fail_existence
|
1092
|
-
check_fail("message.\n" +
|
1093
|
-
"!<:symbol>.respond_to?(:to_s) expected\n" +
|
1094
|
-
"(Class: <Symbol>)") do
|
1095
|
-
assert_respond_to(:symbol, :to_s, "message")
|
1096
|
-
end
|
1097
|
-
end
|
1098
|
-
|
1099
|
-
def test_assert_send
|
1100
|
-
object = Object.new
|
1101
|
-
class << object
|
1102
|
-
private
|
1103
|
-
def return_argument(argument, bogus)
|
1104
|
-
return argument
|
1105
|
-
end
|
1106
|
-
end
|
1107
|
-
check_nothing_fails do
|
1108
|
-
assert_send([object, :return_argument, true, "bogus"], "message")
|
1109
|
-
end
|
1110
|
-
|
1111
|
-
inspected_object = AssertionMessage.convert(object)
|
1112
|
-
expected_message = <<-EOM
|
1113
|
-
message.
|
1114
|
-
<#{inspected_object}> was expected to respond to
|
1115
|
-
<return_argument(*[false, "bogus"])> with a true value but was
|
1116
|
-
<false>.
|
1117
|
-
EOM
|
1118
|
-
check_fail(expected_message.chomp) do
|
1119
|
-
assert_send([object, :return_argument, false, "bogus"], "message")
|
1120
|
-
end
|
1121
|
-
end
|
1122
|
-
|
1123
|
-
def test_condition_invariant
|
1124
|
-
object = Object.new
|
1125
|
-
def object.inspect
|
1126
|
-
@changed = true
|
1127
|
-
end
|
1128
|
-
def object.==(other)
|
1129
|
-
@changed ||= false
|
1130
|
-
return (!@changed)
|
1131
|
-
end
|
1132
|
-
check_nothing_fails do
|
1133
|
-
assert_equal(object, object, "message")
|
1134
|
-
end
|
1135
|
-
end
|
1136
|
-
|
1137
|
-
def test_assert_boolean
|
1138
|
-
check_nothing_fails do
|
1139
|
-
assert_boolean(true)
|
1140
|
-
end
|
1141
|
-
check_nothing_fails do
|
1142
|
-
assert_boolean(false)
|
1143
|
-
end
|
1144
|
-
|
1145
|
-
check_fail("<true> or <false> expected but was\n<1>") do
|
1146
|
-
assert_boolean(1)
|
1147
|
-
end
|
1148
|
-
|
1149
|
-
check_fail("<true> or <false> expected but was\n<nil>") do
|
1150
|
-
assert_boolean(nil)
|
1151
|
-
end
|
1152
|
-
|
1153
|
-
check_fail("message.\n<true> or <false> expected but was\n<\"XXX\">") do
|
1154
|
-
assert_boolean("XXX", "message")
|
1155
|
-
end
|
1156
|
-
end
|
1157
|
-
|
1158
|
-
def test_assert_true
|
1159
|
-
check_nothing_fails do
|
1160
|
-
assert_true(true)
|
1161
|
-
end
|
1162
|
-
|
1163
|
-
check_fail("<true> expected but was\n<false>") do
|
1164
|
-
assert_true(false)
|
1165
|
-
end
|
1166
|
-
|
1167
|
-
check_fail("<true> expected but was\n<1>") do
|
1168
|
-
assert_true(1)
|
1169
|
-
end
|
1170
|
-
|
1171
|
-
check_fail("message.\n<true> expected but was\n<nil>") do
|
1172
|
-
assert_true(nil, "message")
|
1173
|
-
end
|
1174
|
-
end
|
1175
|
-
|
1176
|
-
def test_assert_false
|
1177
|
-
check_nothing_fails do
|
1178
|
-
assert_false(false)
|
1179
|
-
end
|
1180
|
-
|
1181
|
-
check_fail("<false> expected but was\n<true>") do
|
1182
|
-
assert_false(true)
|
1183
|
-
end
|
1184
|
-
|
1185
|
-
check_fail("<false> expected but was\n<nil>") do
|
1186
|
-
assert_false(nil)
|
1187
|
-
end
|
1188
|
-
|
1189
|
-
check_fail("message.\n<false> expected but was\n<:false>") do
|
1190
|
-
assert_false(:false, "message")
|
1191
|
-
end
|
1192
|
-
end
|
1193
|
-
|
1194
|
-
def test_assert_compare
|
1195
|
-
check_nothing_fails do
|
1196
|
-
assert_compare(1.4, "<", 10.0)
|
1197
|
-
end
|
1198
|
-
|
1199
|
-
check_nothing_fails do
|
1200
|
-
assert_compare(2, "<=", 2)
|
1201
|
-
end
|
1202
|
-
|
1203
|
-
check_nothing_fails do
|
1204
|
-
assert_compare(14, ">=", 10.0)
|
1205
|
-
end
|
1206
|
-
|
1207
|
-
check_nothing_fails do
|
1208
|
-
assert_compare(14, ">", 13.9)
|
1209
|
-
end
|
1210
|
-
|
1211
|
-
expected_message = <<-EOM
|
1212
|
-
<15> < <10> should be true
|
1213
|
-
<15> was expected to be less than
|
1214
|
-
<10>.
|
1215
|
-
EOM
|
1216
|
-
check_fail(expected_message.chomp) do
|
1217
|
-
assert_compare(15, "<", 10)
|
1218
|
-
end
|
1219
|
-
|
1220
|
-
expected_message = <<-EOM
|
1221
|
-
<15> <= <10> should be true
|
1222
|
-
<15> was expected to be less than or equal to
|
1223
|
-
<10>.
|
1224
|
-
EOM
|
1225
|
-
check_fail(expected_message.chomp) do
|
1226
|
-
assert_compare(15, "<=", 10)
|
1227
|
-
end
|
1228
|
-
|
1229
|
-
expected_message = <<-EOM
|
1230
|
-
<10> > <15> should be true
|
1231
|
-
<10> was expected to be greater than
|
1232
|
-
<15>.
|
1233
|
-
EOM
|
1234
|
-
check_fail(expected_message.chomp) do
|
1235
|
-
assert_compare(10, ">", 15)
|
1236
|
-
end
|
1237
|
-
|
1238
|
-
expected_message = <<-EOM
|
1239
|
-
<10> >= <15> should be true
|
1240
|
-
<10> was expected to be greater than or equal to
|
1241
|
-
<15>.
|
1242
|
-
EOM
|
1243
|
-
check_fail(expected_message.chomp) do
|
1244
|
-
assert_compare(10, ">=", 15)
|
1245
|
-
end
|
1246
|
-
end
|
1247
|
-
|
1248
|
-
def test_assert_fail_assertion
|
1249
|
-
check_nothing_fails do
|
1250
|
-
assert_fail_assertion do
|
1251
|
-
flunk
|
1252
|
-
end
|
1253
|
-
end
|
1254
|
-
|
1255
|
-
check_fail("Failed assertion was expected.") do
|
1256
|
-
assert_fail_assertion do
|
1257
|
-
end
|
1258
|
-
end
|
1259
|
-
end
|
1260
|
-
|
1261
|
-
def test_assert_raise_message
|
1262
|
-
check_nothing_fails do
|
1263
|
-
assert_raise_message("Raise!") do
|
1264
|
-
raise "Raise!"
|
1265
|
-
end
|
1266
|
-
end
|
1267
|
-
|
1268
|
-
check_nothing_fails do
|
1269
|
-
assert_raise_message("Raise!") do
|
1270
|
-
raise Exception, "Raise!"
|
1271
|
-
end
|
1272
|
-
end
|
1273
|
-
|
1274
|
-
check_nothing_fails do
|
1275
|
-
assert_raise_message(/raise/i) do
|
1276
|
-
raise "Raise!"
|
1277
|
-
end
|
1278
|
-
end
|
1279
|
-
|
1280
|
-
expected_message = <<-EOM
|
1281
|
-
<"Expected message"> exception message expected but was
|
1282
|
-
<"Actual message">.
|
1283
|
-
EOM
|
1284
|
-
check_fail(expected_message.chomp) do
|
1285
|
-
assert_raise_message("Expected message") do
|
1286
|
-
raise "Actual message"
|
1287
|
-
end
|
1288
|
-
end
|
1289
|
-
|
1290
|
-
expected_message = <<-EOM
|
1291
|
-
<"Expected message"> exception message was expected but none was thrown.
|
1292
|
-
EOM
|
1293
|
-
check_fail(expected_message.chomp) do
|
1294
|
-
assert_raise_message("Expected message") do
|
1295
|
-
end
|
1296
|
-
end
|
1297
|
-
end
|
1298
|
-
|
1299
|
-
def test_assert_raise_kind_of
|
1300
|
-
check_nothing_fails(true) do
|
1301
|
-
assert_raise_kind_of(SystemCallError) do
|
1302
|
-
raise Errno::EACCES
|
1303
|
-
end
|
1304
|
-
end
|
1305
|
-
|
1306
|
-
expected_message = <<-EOM.chomp
|
1307
|
-
<SystemCallError> family exception expected but was
|
1308
|
-
<RuntimeError(<XXX>)>.
|
1309
|
-
EOM
|
1310
|
-
check_fail_exception(expected_message) do
|
1311
|
-
assert_raise_kind_of(SystemCallError) do
|
1312
|
-
raise RuntimeError, "XXX"
|
1313
|
-
end
|
1314
|
-
end
|
1315
|
-
end
|
1316
|
-
|
1317
|
-
def test_assert_const_defined
|
1318
|
-
check_nothing_fails do
|
1319
|
-
assert_const_defined(Test, :Unit)
|
1320
|
-
end
|
1321
|
-
|
1322
|
-
check_nothing_fails do
|
1323
|
-
assert_const_defined(Test, "Unit")
|
1324
|
-
end
|
1325
|
-
|
1326
|
-
check_fail("<Test>.const_defined?(<:Nonexistence>) expected.") do
|
1327
|
-
assert_const_defined(Test, :Nonexistence)
|
1328
|
-
end
|
1329
|
-
end
|
1330
|
-
|
1331
|
-
def test_assert_not_const_defined
|
1332
|
-
check_nothing_fails do
|
1333
|
-
assert_not_const_defined(Test, :Nonexistence)
|
1334
|
-
end
|
1335
|
-
|
1336
|
-
check_fail("!<Test>.const_defined?(<:Unit>) expected.") do
|
1337
|
-
assert_not_const_defined(Test, :Unit)
|
1338
|
-
end
|
1339
|
-
|
1340
|
-
check_fail("!<Test>.const_defined?(<\"Unit\">) expected.") do
|
1341
|
-
assert_not_const_defined(Test, "Unit")
|
1342
|
-
end
|
1343
|
-
end
|
1344
|
-
|
1345
|
-
def test_assert_predicate
|
1346
|
-
check_nothing_fails do
|
1347
|
-
assert_predicate([], :empty?)
|
1348
|
-
end
|
1349
|
-
|
1350
|
-
check_fail("<[1]>.empty? is true value expected but was\n<false>") do
|
1351
|
-
assert_predicate([1], :empty?)
|
1352
|
-
end
|
1353
|
-
|
1354
|
-
check_fail("<[1]>.respond_to?(:nonexistent?) expected\n" +
|
1355
|
-
"(Class: <Array>)") do
|
1356
|
-
assert_predicate([1], :nonexistent?)
|
1357
|
-
end
|
1358
|
-
end
|
1359
|
-
|
1360
|
-
def test_assert_not_predicate
|
1361
|
-
check_nothing_fails do
|
1362
|
-
assert_not_predicate([1], :empty?)
|
1363
|
-
end
|
1364
|
-
|
1365
|
-
check_fail("<[]>.empty? is false value expected but was\n<true>") do
|
1366
|
-
assert_not_predicate([], :empty?)
|
1367
|
-
end
|
1368
|
-
|
1369
|
-
check_fail("<[]>.respond_to?(:nonexistent?) expected\n" +
|
1370
|
-
"(Class: <Array>)") do
|
1371
|
-
assert_not_predicate([], :nonexistent?)
|
1372
|
-
end
|
1373
|
-
end
|
1374
|
-
|
1375
|
-
def test_assert_alias_method
|
1376
|
-
object = Object.new
|
1377
|
-
class << object
|
1378
|
-
def original_method
|
1379
|
-
end
|
1380
|
-
alias_method :alias_method, :original_method
|
1381
|
-
|
1382
|
-
def other
|
1383
|
-
end
|
1384
|
-
end
|
1385
|
-
|
1386
|
-
check_nothing_fails do
|
1387
|
-
assert_alias_method(object, :alias_method, :original_method)
|
1388
|
-
end
|
1389
|
-
|
1390
|
-
check_nothing_fails do
|
1391
|
-
assert_alias_method(object, :original_method, :alias_method)
|
1392
|
-
end
|
1393
|
-
|
1394
|
-
check_fail("<#{object.method(:other).inspect}> is alias of\n" +
|
1395
|
-
"<#{object.method(:original_method).inspect}> expected") do
|
1396
|
-
assert_alias_method(object, :other, :original_method)
|
1397
|
-
end
|
1398
|
-
|
1399
|
-
inspected_object = AssertionMessage.convert(object)
|
1400
|
-
check_fail("<#{inspected_object}>.nonexistent doesn't exist\n" +
|
1401
|
-
"(Class: <Object>)") do
|
1402
|
-
assert_alias_method(object, :nonexistent, :original_method)
|
1403
|
-
end
|
1404
|
-
|
1405
|
-
check_fail("<#{inspected_object}>.nonexistent doesn't exist\n" +
|
1406
|
-
"(Class: <Object>)") do
|
1407
|
-
assert_alias_method(object, :alias_method, :nonexistent)
|
1408
|
-
end
|
1409
|
-
end
|
1410
|
-
|
1411
|
-
def test_assert_path_exist
|
1412
|
-
check_nothing_fails do
|
1413
|
-
assert_path_exist(__FILE__)
|
1414
|
-
end
|
1415
|
-
|
1416
|
-
nonexistent_file = __FILE__ + ".nonexistent"
|
1417
|
-
check_fail("<#{nonexistent_file.inspect}> was expected to exist") do
|
1418
|
-
assert_path_exist(nonexistent_file)
|
1419
|
-
end
|
1420
|
-
end
|
1421
|
-
|
1422
|
-
def test_assert_path_not_exist
|
1423
|
-
nonexistent_file = __FILE__ + ".nonexistent"
|
1424
|
-
check_nothing_fails do
|
1425
|
-
assert_path_not_exist(nonexistent_file)
|
1426
|
-
end
|
1427
|
-
|
1428
|
-
check_fail("<#{__FILE__.inspect}> was expected to not exist") do
|
1429
|
-
assert_path_not_exist(__FILE__)
|
1430
|
-
end
|
1431
|
-
end
|
1432
|
-
end
|
1433
|
-
|
1434
|
-
class TestAssert < TestCase
|
1435
|
-
include AssertionCheckable
|
1436
|
-
|
1437
|
-
def test_pass
|
1438
|
-
check_nothing_fails do
|
1439
|
-
assert(true)
|
1440
|
-
end
|
1441
|
-
end
|
1442
|
-
|
1443
|
-
def test_pass_neither_false_or_nil
|
1444
|
-
check_nothing_fails do
|
1445
|
-
assert("a")
|
1446
|
-
end
|
1447
|
-
end
|
1448
|
-
|
1449
|
-
def test_pass_with_message
|
1450
|
-
check_nothing_fails do
|
1451
|
-
assert(true, "successful assert")
|
1452
|
-
end
|
1453
|
-
end
|
1454
|
-
|
1455
|
-
def test_pass_block
|
1456
|
-
check_nothing_fails do
|
1457
|
-
assert do
|
1458
|
-
true
|
1459
|
-
end
|
1460
|
-
end
|
1461
|
-
end
|
1462
|
-
|
1463
|
-
def test_fail_nil
|
1464
|
-
check_fail("<nil> is not true.") do
|
1465
|
-
assert(nil)
|
1466
|
-
end
|
1467
|
-
end
|
1468
|
-
|
1469
|
-
def test_fail_false
|
1470
|
-
check_fail("<false> is not true.") do
|
1471
|
-
assert(false)
|
1472
|
-
end
|
1473
|
-
end
|
1474
|
-
|
1475
|
-
def test_fail_false_with_message
|
1476
|
-
check_fail("failed assert.\n" +
|
1477
|
-
"<false> is not true.") do
|
1478
|
-
assert(false, "failed assert")
|
1479
|
-
end
|
1480
|
-
end
|
1481
|
-
|
1482
|
-
def test_fail_with_assertion_message
|
1483
|
-
check_fail("user message.\n" +
|
1484
|
-
"placeholder <:in> message") do
|
1485
|
-
assert(false, build_message("user message",
|
1486
|
-
"placeholder <?> message",
|
1487
|
-
:in))
|
1488
|
-
end
|
1489
|
-
end
|
1490
|
-
|
1491
|
-
def test_fail_block
|
1492
|
-
check_fail(//) do
|
1493
|
-
assert do
|
1494
|
-
0.odd?
|
1495
|
-
end
|
1496
|
-
end
|
1497
|
-
end
|
1498
|
-
|
1499
|
-
def test_error_invalid_message_true
|
1500
|
-
check_fail("assertion message must be String, Proc or " +
|
1501
|
-
"Test::Unit::Assertions::AssertionMessage: " +
|
1502
|
-
"<true>(<TrueClass>)") do
|
1503
|
-
begin
|
1504
|
-
assert(true, true)
|
1505
|
-
rescue ArgumentError
|
1506
|
-
raise AssertionFailedError, $!.message
|
1507
|
-
end
|
1508
|
-
end
|
1509
|
-
end
|
1510
|
-
|
1511
|
-
def test_error_wrong_number_of_arguments
|
1512
|
-
check_fail("wrong number of arguments (0 for 1..2)") do
|
1513
|
-
begin
|
1514
|
-
assert
|
1515
|
-
rescue ArgumentError
|
1516
|
-
raise AssertionFailedError, $!.message
|
1517
|
-
end
|
1518
|
-
end
|
1519
|
-
end
|
1520
|
-
|
1521
|
-
class TestBlock < self
|
1522
|
-
def test_with_message
|
1523
|
-
if defined?(PowerAssert)
|
1524
|
-
system_message = <<-MESSAGE.chomp
|
1525
|
-
1.to_s == "2"
|
1526
|
-
| |
|
1527
|
-
| false
|
1528
|
-
"1"
|
1529
|
-
MESSAGE
|
1530
|
-
else
|
1531
|
-
system_message = "<false> is not true."
|
1532
|
-
end
|
1533
|
-
check_fail("user message.\n#{system_message}") do
|
1534
|
-
assert("user message") do
|
1535
|
-
1.to_s == "2"
|
1536
|
-
end
|
1537
|
-
end
|
1538
|
-
end
|
1539
|
-
end
|
1540
|
-
end
|
1541
|
-
|
1542
|
-
class TestRefute < TestCase
|
1543
|
-
include AssertionCheckable
|
1544
|
-
|
1545
|
-
class TestPass < self
|
1546
|
-
def test_nil
|
1547
|
-
check_nothing_fails do
|
1548
|
-
refute(nil)
|
1549
|
-
end
|
1550
|
-
end
|
1551
|
-
|
1552
|
-
def test_false
|
1553
|
-
check_nothing_fails do
|
1554
|
-
refute(false)
|
1555
|
-
end
|
1556
|
-
end
|
1557
|
-
|
1558
|
-
def test_with_message
|
1559
|
-
check_nothing_fails do
|
1560
|
-
refute(nil, "successful refute")
|
1561
|
-
end
|
1562
|
-
end
|
1563
|
-
end
|
1564
|
-
|
1565
|
-
class TestFailure < self
|
1566
|
-
def test_true
|
1567
|
-
check_fail("<true> is neither nil or false.") do
|
1568
|
-
refute(true)
|
1569
|
-
end
|
1570
|
-
end
|
1571
|
-
|
1572
|
-
def test_with_message
|
1573
|
-
check_fail("failed refute.\n" +
|
1574
|
-
"<true> is neither nil or false.") do
|
1575
|
-
refute(true, "failed refute")
|
1576
|
-
end
|
1577
|
-
end
|
1578
|
-
|
1579
|
-
def test_fail_with_assertion_message
|
1580
|
-
check_fail("user message.\n" +
|
1581
|
-
"placeholder <:in> message") do
|
1582
|
-
refute(true, build_message("user message",
|
1583
|
-
"placeholder <?> message",
|
1584
|
-
:in))
|
1585
|
-
end
|
1586
|
-
end
|
1587
|
-
|
1588
|
-
def test_error_invalid_message_true
|
1589
|
-
check_fail("assertion message must be String, Proc or " +
|
1590
|
-
"Test::Unit::Assertions::AssertionMessage: " +
|
1591
|
-
"<false>(<FalseClass>)") do
|
1592
|
-
begin
|
1593
|
-
refute(true, false)
|
1594
|
-
rescue ArgumentError
|
1595
|
-
raise AssertionFailedError, $!.message
|
1596
|
-
end
|
1597
|
-
end
|
1598
|
-
end
|
1599
|
-
end
|
1600
|
-
end
|
1601
|
-
|
1602
|
-
class TestAssertInDelta < TestCase
|
1603
|
-
include AssertionCheckable
|
1604
|
-
|
1605
|
-
def test_pass
|
1606
|
-
check_nothing_fails do
|
1607
|
-
assert_in_delta(1.4, 1.4, 0)
|
1608
|
-
end
|
1609
|
-
end
|
1610
|
-
|
1611
|
-
def test_pass_without_delta
|
1612
|
-
check_nothing_fails do
|
1613
|
-
assert_in_delta(1.401, 1.402)
|
1614
|
-
end
|
1615
|
-
end
|
1616
|
-
|
1617
|
-
def test_pass_with_message
|
1618
|
-
check_nothing_fails do
|
1619
|
-
assert_in_delta(0.5, 0.4, 0.1, "message")
|
1620
|
-
end
|
1621
|
-
end
|
1622
|
-
|
1623
|
-
def test_pass_float_like_object
|
1624
|
-
check_nothing_fails do
|
1625
|
-
float_thing = Object.new
|
1626
|
-
def float_thing.to_f
|
1627
|
-
0.2
|
1628
|
-
end
|
1629
|
-
assert_in_delta(0.1, float_thing, 0.1)
|
1630
|
-
end
|
1631
|
-
end
|
1632
|
-
|
1633
|
-
def test_pass_string_expected
|
1634
|
-
check_nothing_fails do
|
1635
|
-
assert_in_delta("0.5", 0.4, 0.1)
|
1636
|
-
end
|
1637
|
-
end
|
1638
|
-
|
1639
|
-
def test_fail_with_message
|
1640
|
-
check_fail("message.\n" +
|
1641
|
-
"<0.5> -/+ <0.05> was expected to include\n" +
|
1642
|
-
"<0.4>.\n" +
|
1643
|
-
"\n" +
|
1644
|
-
"Relation:\n" +
|
1645
|
-
"<<0.4> < <0.5>-<0.05>[0.45] <= <0.5>+<0.05>[0.55]>") do
|
1646
|
-
assert_in_delta(0.5, 0.4, 0.05, "message")
|
1647
|
-
end
|
1648
|
-
end
|
1649
|
-
|
1650
|
-
def test_fail_because_not_float_like_object
|
1651
|
-
object = Object.new
|
1652
|
-
inspected_object = AssertionMessage.convert(object)
|
1653
|
-
check_fail("The arguments must respond to to_f; " +
|
1654
|
-
"the first float did not.\n" +
|
1655
|
-
"<#{inspected_object}>.respond_to?(:to_f) expected\n" +
|
1656
|
-
"(Class: <Object>)") do
|
1657
|
-
assert_in_delta(object, 0.4, 0.1)
|
1658
|
-
end
|
1659
|
-
end
|
1660
|
-
|
1661
|
-
def test_fail_because_negaitve_delta
|
1662
|
-
check_fail("The delta should not be negative.\n" +
|
1663
|
-
"<-0.1> was expected to be\n>=\n<0.0>.") do
|
1664
|
-
assert_in_delta(0.5, 0.4, -0.1, "message")
|
1665
|
-
end
|
1666
|
-
end
|
1667
|
-
|
1668
|
-
def test_fail_without_delta
|
1669
|
-
check_fail("<1.402> -/+ <0.001> was expected to include\n" +
|
1670
|
-
"<1.404>.\n" +
|
1671
|
-
"\n" +
|
1672
|
-
"Relation:\n" +
|
1673
|
-
"<" +
|
1674
|
-
"<1.402>-<0.001>[#{1.402 - 0.001}] <= " +
|
1675
|
-
"<1.402>+<0.001>[#{1.402 + 0.001}] < " +
|
1676
|
-
"<1.404>" +
|
1677
|
-
">") do
|
1678
|
-
assert_in_delta(1.402, 1.404)
|
1679
|
-
end
|
1680
|
-
end
|
1681
|
-
end
|
1682
|
-
|
1683
|
-
class TestAssertNotInDelta < Test::Unit::TestCase
|
1684
|
-
include AssertionCheckable
|
1685
|
-
|
1686
|
-
def test_pass
|
1687
|
-
check_nothing_fails do
|
1688
|
-
assert_not_in_delta(1.42, 1.44, 0.01)
|
1689
|
-
end
|
1690
|
-
end
|
1691
|
-
|
1692
|
-
def test_pass_without_delta
|
1693
|
-
check_nothing_fails do
|
1694
|
-
assert_not_in_delta(1.402, 1.404)
|
1695
|
-
end
|
1696
|
-
end
|
1697
|
-
|
1698
|
-
def test_pass_with_message
|
1699
|
-
check_nothing_fails do
|
1700
|
-
assert_not_in_delta(0.5, 0.4, 0.09, "message")
|
1701
|
-
end
|
1702
|
-
end
|
1703
|
-
|
1704
|
-
def test_pass_float_like_object
|
1705
|
-
check_nothing_fails do
|
1706
|
-
float_thing = Object.new
|
1707
|
-
def float_thing.to_f
|
1708
|
-
0.2
|
1709
|
-
end
|
1710
|
-
assert_not_in_delta(0.1, float_thing, 0.09)
|
1711
|
-
end
|
1712
|
-
end
|
1713
|
-
|
1714
|
-
def test_pass_string_epxected
|
1715
|
-
check_nothing_fails do
|
1716
|
-
assert_not_in_delta("0.5", 0.4, 0.09)
|
1717
|
-
end
|
1718
|
-
end
|
1719
|
-
|
1720
|
-
def test_fail
|
1721
|
-
check_fail("<1.4> -/+ <0.11> was expected to not include\n" +
|
1722
|
-
"<1.5>.\n" +
|
1723
|
-
"\n" +
|
1724
|
-
"Relation:\n" +
|
1725
|
-
"<" +
|
1726
|
-
"<1.4>-<0.11>[#{1.4 - 0.11}] <= " +
|
1727
|
-
"<1.5> <= " +
|
1728
|
-
"<1.4>+<0.11>[#{1.4 + 0.11}]" +
|
1729
|
-
">") do
|
1730
|
-
assert_not_in_delta(1.4, 1.5, 0.11)
|
1731
|
-
end
|
1732
|
-
end
|
1733
|
-
|
1734
|
-
def test_fail_without_delta
|
1735
|
-
check_fail("<1.402> -/+ <0.001> was expected to not include\n" +
|
1736
|
-
"<1.4021>.\n" +
|
1737
|
-
"\n" +
|
1738
|
-
"Relation:\n" +
|
1739
|
-
"<" +
|
1740
|
-
"<1.402>-<0.001>[#{1.402 - 0.001}] <= " +
|
1741
|
-
"<1.4021> <= " +
|
1742
|
-
"<1.402>+<0.001>[#{1.402 + 0.001}]" +
|
1743
|
-
">") do
|
1744
|
-
assert_not_in_delta(1.402, 1.4021)
|
1745
|
-
end
|
1746
|
-
end
|
1747
|
-
|
1748
|
-
def test_fail_with_message
|
1749
|
-
check_fail("message.\n" +
|
1750
|
-
"<0.5> -/+ <0.11> was expected to not include\n" +
|
1751
|
-
"<0.4>.\n" +
|
1752
|
-
"\n" +
|
1753
|
-
"Relation:\n" +
|
1754
|
-
"<" +
|
1755
|
-
"<0.5>-<0.11>[0.39] <= " +
|
1756
|
-
"<0.4> <= " +
|
1757
|
-
"<0.5>+<0.11>[0.61]" +
|
1758
|
-
">") do
|
1759
|
-
assert_not_in_delta(0.5, 0.4, 0.11, "message")
|
1760
|
-
end
|
1761
|
-
end
|
1762
|
-
|
1763
|
-
def test_fail_because_not_float_like_object
|
1764
|
-
object = Object.new
|
1765
|
-
inspected_object = AssertionMessage.convert(object)
|
1766
|
-
check_fail("The arguments must respond to to_f; " +
|
1767
|
-
"the first float did not.\n" +
|
1768
|
-
"<#{inspected_object}>.respond_to?(:to_f) expected\n" +
|
1769
|
-
"(Class: <Object>)") do
|
1770
|
-
assert_not_in_delta(object, 0.4, 0.1)
|
1771
|
-
end
|
1772
|
-
end
|
1773
|
-
|
1774
|
-
def test_fail_because_negaitve_delta
|
1775
|
-
check_fail("The delta should not be negative.\n" +
|
1776
|
-
"<-0.11> was expected to be\n>=\n<0.0>.") do
|
1777
|
-
assert_not_in_delta(0.5, 0.4, -0.11, "message")
|
1778
|
-
end
|
1779
|
-
end
|
1780
|
-
end
|
1781
|
-
|
1782
|
-
class TestAssertInEpsilon < TestCase
|
1783
|
-
include AssertionCheckable
|
1784
|
-
|
1785
|
-
def test_pass
|
1786
|
-
check_nothing_fails do
|
1787
|
-
assert_in_epsilon(10000, 9000, 0.1)
|
1788
|
-
end
|
1789
|
-
end
|
1790
|
-
|
1791
|
-
def test_pass_without_epsilon
|
1792
|
-
check_nothing_fails do
|
1793
|
-
assert_in_epsilon(10000, 9991)
|
1794
|
-
end
|
1795
|
-
end
|
1796
|
-
|
1797
|
-
def test_pass_with_message
|
1798
|
-
check_nothing_fails do
|
1799
|
-
assert_in_epsilon(10000, 9000, 0.1, "message")
|
1800
|
-
end
|
1801
|
-
end
|
1802
|
-
|
1803
|
-
def test_pass_float_like_object
|
1804
|
-
check_nothing_fails do
|
1805
|
-
float_thing = Object.new
|
1806
|
-
def float_thing.to_f
|
1807
|
-
9000.0
|
1808
|
-
end
|
1809
|
-
assert_in_epsilon(10000, float_thing, 0.1)
|
1810
|
-
end
|
1811
|
-
end
|
1812
|
-
|
1813
|
-
def test_pass_string_expected
|
1814
|
-
check_nothing_fails do
|
1815
|
-
assert_in_epsilon("10000", 9000, 0.1)
|
1816
|
-
end
|
1817
|
-
end
|
1818
|
-
|
1819
|
-
def test_pass_zero_expected
|
1820
|
-
check_nothing_fails do
|
1821
|
-
assert_in_epsilon(0, 0.00000001)
|
1822
|
-
end
|
1823
|
-
end
|
1824
|
-
|
1825
|
-
def test_pass_minus_expected
|
1826
|
-
check_nothing_fails do
|
1827
|
-
assert_in_epsilon(-1, -1)
|
1828
|
-
end
|
1829
|
-
end
|
1830
|
-
|
1831
|
-
def test_fail_with_message
|
1832
|
-
check_fail("message.\n" +
|
1833
|
-
"<10000> -/+ (<10000> * <0.1>)[1000.0] " +
|
1834
|
-
"was expected to include\n" +
|
1835
|
-
"<8999>.\n" +
|
1836
|
-
"\n" +
|
1837
|
-
"Relation:\n" +
|
1838
|
-
"<" +
|
1839
|
-
"<8999> < " +
|
1840
|
-
"<10000>-(<10000>*<0.1>)[9000.0] <= " +
|
1841
|
-
"<10000>+(<10000>*<0.1>)[11000.0]" +
|
1842
|
-
">") do
|
1843
|
-
assert_in_epsilon(10000, 8999, 0.1, "message")
|
1844
|
-
end
|
1845
|
-
end
|
1846
|
-
|
1847
|
-
def test_fail_because_not_float_like_object
|
1848
|
-
object = Object.new
|
1849
|
-
inspected_object = AssertionMessage.convert(object)
|
1850
|
-
check_fail("The arguments must respond to to_f; " +
|
1851
|
-
"the first float did not.\n" +
|
1852
|
-
"<#{inspected_object}>.respond_to?(:to_f) expected\n" +
|
1853
|
-
"(Class: <Object>)") do
|
1854
|
-
assert_in_epsilon(object, 9000, 0.1)
|
1855
|
-
end
|
1856
|
-
end
|
1857
|
-
|
1858
|
-
def test_fail_because_negaitve_epsilon
|
1859
|
-
check_fail("The epsilon should not be negative.\n" +
|
1860
|
-
"<-0.1> was expected to be\n>=\n<0.0>.") do
|
1861
|
-
assert_in_epsilon(10000, 9000, -0.1, "message")
|
1862
|
-
end
|
1863
|
-
end
|
1864
|
-
|
1865
|
-
def test_fail_without_epsilon
|
1866
|
-
check_fail("<10000> -/+ (<10000> * <0.001>)[10.0] " +
|
1867
|
-
"was expected to include\n" +
|
1868
|
-
"<10011>.\n" +
|
1869
|
-
"\n" +
|
1870
|
-
"Relation:\n" +
|
1871
|
-
"<" +
|
1872
|
-
"<10000>-(<10000>*<0.001>)[9990.0] <= " +
|
1873
|
-
"<10000>+(<10000>*<0.001>)[10010.0] < " +
|
1874
|
-
"<10011>" +
|
1875
|
-
">") do
|
1876
|
-
assert_in_epsilon(10000, 10011)
|
1877
|
-
end
|
1878
|
-
end
|
1879
|
-
end
|
1880
|
-
|
1881
|
-
class TestAssertNotInEpsilon < Test::Unit::TestCase
|
1882
|
-
include AssertionCheckable
|
1883
|
-
|
1884
|
-
def test_pass
|
1885
|
-
check_nothing_fails do
|
1886
|
-
assert_not_in_epsilon(10000, 8999, 0.1)
|
1887
|
-
end
|
1888
|
-
end
|
1889
|
-
|
1890
|
-
def test_pass_without_epsilon
|
1891
|
-
check_nothing_fails do
|
1892
|
-
assert_not_in_epsilon(10000, 9989)
|
1893
|
-
end
|
1894
|
-
end
|
1895
|
-
|
1896
|
-
def test_pass_with_message
|
1897
|
-
check_nothing_fails do
|
1898
|
-
assert_not_in_epsilon(10000, 8999, 0.1, "message")
|
1899
|
-
end
|
1900
|
-
end
|
1901
|
-
|
1902
|
-
def test_pass_float_like_object
|
1903
|
-
check_nothing_fails do
|
1904
|
-
float_thing = Object.new
|
1905
|
-
def float_thing.to_f
|
1906
|
-
8999.0
|
1907
|
-
end
|
1908
|
-
assert_not_in_epsilon(10000, float_thing, 0.1)
|
1909
|
-
end
|
1910
|
-
end
|
1911
|
-
|
1912
|
-
def test_pass_string_epxected
|
1913
|
-
check_nothing_fails do
|
1914
|
-
assert_not_in_epsilon("10000", 8999, 0.1)
|
1915
|
-
end
|
1916
|
-
end
|
1917
|
-
|
1918
|
-
def test_fail
|
1919
|
-
check_fail("<10000> -/+ (<10000> * <0.1>)[1000.0] " +
|
1920
|
-
"was expected to not include\n" +
|
1921
|
-
"<9000>.\n" +
|
1922
|
-
"\n" +
|
1923
|
-
"Relation:\n" +
|
1924
|
-
"<" +
|
1925
|
-
"<10000>-(<10000>*<0.1>)[9000.0] <= " +
|
1926
|
-
"<9000> <= " +
|
1927
|
-
"<10000>+(<10000>*<0.1>)[11000.0]" +
|
1928
|
-
">") do
|
1929
|
-
assert_not_in_epsilon(10000, 9000, 0.1)
|
1930
|
-
end
|
1931
|
-
end
|
1932
|
-
|
1933
|
-
def test_fail_without_epsilon
|
1934
|
-
check_fail("<10000> -/+ (<10000> * <0.001>)[10.0] " +
|
1935
|
-
"was expected to not include\n" +
|
1936
|
-
"<9990>.\n" +
|
1937
|
-
"\n" +
|
1938
|
-
"Relation:\n" +
|
1939
|
-
"<" +
|
1940
|
-
"<10000>-(<10000>*<0.001>)[9990.0] <= " +
|
1941
|
-
"<9990> <= " +
|
1942
|
-
"<10000>+(<10000>*<0.001>)[10010.0]" +
|
1943
|
-
">") do
|
1944
|
-
assert_not_in_epsilon(10000, 9990)
|
1945
|
-
end
|
1946
|
-
end
|
1947
|
-
|
1948
|
-
def test_fail_with_message
|
1949
|
-
check_fail("message.\n" +
|
1950
|
-
"<10000> -/+ (<10000> * <0.1>)[1000.0] " +
|
1951
|
-
"was expected to not include\n" +
|
1952
|
-
"<9000>.\n" +
|
1953
|
-
"\n" +
|
1954
|
-
"Relation:\n" +
|
1955
|
-
"<" +
|
1956
|
-
"<10000>-(<10000>*<0.1>)[9000.0] <= " +
|
1957
|
-
"<9000> <= " +
|
1958
|
-
"<10000>+(<10000>*<0.1>)[11000.0]" +
|
1959
|
-
">") do
|
1960
|
-
assert_not_in_epsilon(10000, 9000, 0.1, "message")
|
1961
|
-
end
|
1962
|
-
end
|
1963
|
-
|
1964
|
-
def test_fail_because_not_float_like_object
|
1965
|
-
object = Object.new
|
1966
|
-
inspected_object = AssertionMessage.convert(object)
|
1967
|
-
check_fail("The arguments must respond to to_f; " +
|
1968
|
-
"the first float did not.\n" +
|
1969
|
-
"<#{inspected_object}>.respond_to?(:to_f) expected\n" +
|
1970
|
-
"(Class: <Object>)") do
|
1971
|
-
assert_not_in_epsilon(object, 9000, 0.1)
|
1972
|
-
end
|
1973
|
-
end
|
1974
|
-
|
1975
|
-
def test_fail_because_negaitve_epsilon
|
1976
|
-
check_fail("The epsilon should not be negative.\n" +
|
1977
|
-
"<-0.1> was expected to be\n>=\n<0.0>.") do
|
1978
|
-
assert_not_in_epsilon(10000, 9000, -0.1, "message")
|
1979
|
-
end
|
1980
|
-
end
|
1981
|
-
end
|
1982
|
-
|
1983
|
-
class TestAssertInclude < Test::Unit::TestCase
|
1984
|
-
include AssertionCheckable
|
1985
|
-
|
1986
|
-
def test_pass
|
1987
|
-
check_nothing_fails do
|
1988
|
-
assert_include([1, 2, 3], 1)
|
1989
|
-
end
|
1990
|
-
end
|
1991
|
-
|
1992
|
-
def test_pass_with_message
|
1993
|
-
check_nothing_fails do
|
1994
|
-
assert_include([1, 2, 3], 1, "message")
|
1995
|
-
end
|
1996
|
-
end
|
1997
|
-
|
1998
|
-
def test_fail
|
1999
|
-
check_fail("<[1, 2, 3]> was expected to include\n" +
|
2000
|
-
"<4>.") do
|
2001
|
-
assert_include([1, 2, 3], 4)
|
2002
|
-
end
|
2003
|
-
end
|
2004
|
-
|
2005
|
-
def test_fail_with_message
|
2006
|
-
check_fail("message.\n" +
|
2007
|
-
"<[1, 2, 3]> was expected to include\n" +
|
2008
|
-
"<4>.") do
|
2009
|
-
assert_include([1, 2, 3], 4, "message")
|
2010
|
-
end
|
2011
|
-
end
|
2012
|
-
|
2013
|
-
def test_fail_because_not_collection_like_object
|
2014
|
-
object = Object.new
|
2015
|
-
inspected_object = AssertionMessage.convert(object)
|
2016
|
-
check_fail("The collection must respond to :include?.\n" +
|
2017
|
-
"<#{inspected_object}>.respond_to?(:include?) expected\n" +
|
2018
|
-
"(Class: <Object>)") do
|
2019
|
-
assert_include(object, 1)
|
2020
|
-
end
|
2021
|
-
end
|
2022
|
-
end
|
2023
|
-
|
2024
|
-
class TestAssertNotInclude < Test::Unit::TestCase
|
2025
|
-
include AssertionCheckable
|
2026
|
-
|
2027
|
-
def test_pass
|
2028
|
-
check_nothing_fails do
|
2029
|
-
assert_not_include([1, 2, 3], 5)
|
2030
|
-
end
|
2031
|
-
end
|
2032
|
-
|
2033
|
-
def test_pass_with_message
|
2034
|
-
check_nothing_fails do
|
2035
|
-
assert_not_include([1, 2, 3], 5, "message")
|
2036
|
-
end
|
2037
|
-
end
|
2038
|
-
|
2039
|
-
def test_fail
|
2040
|
-
check_fail("<[1, 2, 3]> was expected to not include\n" +
|
2041
|
-
"<2>.") do
|
2042
|
-
assert_not_include([1, 2, 3], 2)
|
2043
|
-
end
|
2044
|
-
end
|
2045
|
-
|
2046
|
-
def test_fail_with_message
|
2047
|
-
check_fail("message.\n" +
|
2048
|
-
"<[1, 2, 3]> was expected to not include\n" +
|
2049
|
-
"<2>.") do
|
2050
|
-
assert_not_include([1, 2, 3], 2, "message")
|
2051
|
-
end
|
2052
|
-
end
|
2053
|
-
|
2054
|
-
def test_fail_because_not_collection_like_object
|
2055
|
-
object = Object.new
|
2056
|
-
inspected_object = AssertionMessage.convert(object)
|
2057
|
-
check_fail("The collection must respond to :include?.\n" +
|
2058
|
-
"<#{inspected_object}>.respond_to?(:include?) expected\n" +
|
2059
|
-
"(Class: <Object>)") do
|
2060
|
-
assert_not_include(object, 1)
|
2061
|
-
end
|
2062
|
-
end
|
2063
|
-
end
|
2064
|
-
|
2065
|
-
class TestAssertEmpty < Test::Unit::TestCase
|
2066
|
-
include AssertionCheckable
|
2067
|
-
|
2068
|
-
def test_pass
|
2069
|
-
check_nothing_fails do
|
2070
|
-
assert_empty([])
|
2071
|
-
end
|
2072
|
-
end
|
2073
|
-
|
2074
|
-
def test_pass_with_message
|
2075
|
-
check_nothing_fails do
|
2076
|
-
assert_empty([], "message")
|
2077
|
-
end
|
2078
|
-
end
|
2079
|
-
|
2080
|
-
def test_fail
|
2081
|
-
check_fail("<[1]> was expected to be empty.") do
|
2082
|
-
assert_empty([1])
|
2083
|
-
end
|
2084
|
-
end
|
2085
|
-
|
2086
|
-
def test_fail_with_message
|
2087
|
-
check_fail("message.\n" +
|
2088
|
-
"<[1]> was expected to be empty.") do
|
2089
|
-
assert_empty([1], "message")
|
2090
|
-
end
|
2091
|
-
end
|
2092
|
-
|
2093
|
-
def test_fail_because_no_empty_method
|
2094
|
-
object = Object.new
|
2095
|
-
inspected_object = AssertionMessage.convert(object)
|
2096
|
-
check_fail("The object must respond to :empty?.\n" +
|
2097
|
-
"<#{inspected_object}>.respond_to?(:empty?) expected\n" +
|
2098
|
-
"(Class: <Object>)") do
|
2099
|
-
assert_empty(object)
|
2100
|
-
end
|
2101
|
-
end
|
2102
|
-
end
|
2103
|
-
|
2104
|
-
class TestAssertNotEmpty < Test::Unit::TestCase
|
2105
|
-
include AssertionCheckable
|
2106
|
-
|
2107
|
-
def test_pass
|
2108
|
-
check_nothing_fails do
|
2109
|
-
assert_not_empty([1])
|
2110
|
-
end
|
2111
|
-
end
|
2112
|
-
|
2113
|
-
def test_pass_with_message
|
2114
|
-
check_nothing_fails do
|
2115
|
-
assert_not_empty([1], "message")
|
2116
|
-
end
|
2117
|
-
end
|
2118
|
-
|
2119
|
-
def test_fail
|
2120
|
-
check_fail("<[]> was expected to not be empty.") do
|
2121
|
-
assert_not_empty([])
|
2122
|
-
end
|
2123
|
-
end
|
2124
|
-
|
2125
|
-
def test_fail_with_message
|
2126
|
-
check_fail("message.\n" +
|
2127
|
-
"<[]> was expected to not be empty.") do
|
2128
|
-
assert_not_empty([], "message")
|
2129
|
-
end
|
2130
|
-
end
|
2131
|
-
|
2132
|
-
def test_fail_because_no_empty_method
|
2133
|
-
object = Object.new
|
2134
|
-
inspected_object = AssertionMessage.convert(object)
|
2135
|
-
check_fail("The object must respond to :empty?.\n" +
|
2136
|
-
"<#{inspected_object}>.respond_to?(:empty?) expected\n" +
|
2137
|
-
"(Class: <Object>)") do
|
2138
|
-
assert_not_empty(object)
|
2139
|
-
end
|
2140
|
-
end
|
2141
|
-
end
|
2142
|
-
|
2143
|
-
class TestAssertNotSend < Test::Unit::TestCase
|
2144
|
-
include AssertionCheckable
|
2145
|
-
|
2146
|
-
def test_pass
|
2147
|
-
check_nothing_fails do
|
2148
|
-
assert_not_send([[1, 2], :member?, 4], "message")
|
2149
|
-
end
|
2150
|
-
end
|
2151
|
-
|
2152
|
-
def test_fail
|
2153
|
-
expected_message = <<-EOM
|
2154
|
-
message.
|
2155
|
-
<[1, 2]> was expected to respond to
|
2156
|
-
<member?(*[2])> with not a true value but was
|
2157
|
-
<true>.
|
2158
|
-
EOM
|
2159
|
-
check_fail(expected_message.chomp) do
|
2160
|
-
assert_not_send([[1, 2], :member?, 2], "message")
|
2161
|
-
end
|
2162
|
-
end
|
2163
|
-
end
|
2164
|
-
|
2165
|
-
class TestTemplate < Test::Unit::TestCase
|
2166
|
-
def test_incompatible_encoding_by_diff
|
2167
|
-
need_encoding
|
2168
|
-
assert_raise(AssertionFailedError) do
|
2169
|
-
assert_equal("UTF-8の日本語\n" * 3,
|
2170
|
-
("Shift_JISの日本語\n" * 3).force_encoding("ASCII-8BIT"))
|
2171
|
-
end
|
2172
|
-
end
|
2173
|
-
|
2174
|
-
private
|
2175
|
-
def need_encoding
|
2176
|
-
omit("need Encoding") unless Object.const_defined?(:Encoding)
|
2177
|
-
end
|
2178
|
-
end
|
2179
|
-
end
|
2180
|
-
end
|