test-unit 2.5.5 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/{README.textile → README.md} +15 -12
- data/Rakefile +3 -11
- data/doc/text/how-to.md +88 -0
- data/doc/text/news.md +731 -0
- data/lib/test/unit/{assertionfailederror.rb → assertion-failed-error.rb} +0 -0
- data/lib/test/unit/assertions.rb +354 -167
- data/lib/test/unit/attribute.rb +2 -1
- data/lib/test/unit/autorunner.rb +12 -10
- data/lib/test/unit/collector/dir.rb +8 -8
- data/lib/test/unit/collector/load.rb +10 -4
- data/lib/test/unit/collector/objectspace.rb +3 -3
- data/lib/test/unit/{exceptionhandler.rb → exception-handler.rb} +1 -1
- data/lib/test/unit/{testsuitecreator.rb → test-suite-creator.rb} +4 -3
- data/lib/test/unit/testcase.rb +14 -7
- data/lib/test/unit/util/backtracefilter.rb +8 -2
- data/lib/test/unit/version.rb +1 -1
- data/test/test-assertions.rb +284 -150
- data/test/test-attribute.rb +11 -0
- data/test/{test_error.rb → test-error.rb} +0 -0
- data/test/{test_failure.rb → test-failure.rb} +0 -0
- data/test/{test-testcase.rb → test-test-case.rb} +438 -201
- data/test/{test_testresult.rb → test-test-result.rb} +0 -0
- data/test/test-test-suite-creator.rb +97 -0
- data/test/{test_testsuite.rb → test-test-suite.rb} +0 -0
- metadata +140 -136
data/lib/test/unit/attribute.rb
CHANGED
@@ -92,7 +92,8 @@ module Test
|
|
92
92
|
|
93
93
|
def attributes(method_name)
|
94
94
|
attributes = attributes_table[method_name]
|
95
|
-
ancestors
|
95
|
+
ancestors.each do |ancestor|
|
96
|
+
next if ancestor == self
|
96
97
|
if ancestor.is_a?(Class) and ancestor < Test::Unit::Attribute
|
97
98
|
parent_attributes = ancestor.attributes(method_name)
|
98
99
|
if attributes
|
data/lib/test/unit/autorunner.rb
CHANGED
@@ -240,11 +240,8 @@ module Test
|
|
240
240
|
"Runs tests in TestCases matching TESTCASE.",
|
241
241
|
"(patterns may be used).") do |n|
|
242
242
|
n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n)
|
243
|
-
|
244
|
-
|
245
|
-
@filters << proc{|t| n =~ t.class.name ? true : false}
|
246
|
-
else
|
247
|
-
@filters << proc{|t| n == t.class.name}
|
243
|
+
@filters << lambda do |test|
|
244
|
+
match_test_case_name(test, n)
|
248
245
|
end
|
249
246
|
end
|
250
247
|
|
@@ -252,11 +249,8 @@ module Test
|
|
252
249
|
"Ignores tests in TestCases matching TESTCASE.",
|
253
250
|
"(patterns may be used).") do |n|
|
254
251
|
n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n)
|
255
|
-
|
256
|
-
|
257
|
-
@filters << proc {|t| n =~ t.class.name ? false : true}
|
258
|
-
else
|
259
|
-
@filters << proc {|t| n != t.class.name}
|
252
|
+
@filters << lambda do |test|
|
253
|
+
not match_test_case_name(test, n)
|
260
254
|
end
|
261
255
|
end
|
262
256
|
|
@@ -465,6 +459,14 @@ module Test
|
|
465
459
|
yield
|
466
460
|
end
|
467
461
|
end
|
462
|
+
|
463
|
+
def match_test_case_name(test, pattern)
|
464
|
+
test.class.ancestors.each do |test_class|
|
465
|
+
break if test_class == TestCase
|
466
|
+
return true if pattern === test_class.name
|
467
|
+
end
|
468
|
+
false
|
469
|
+
end
|
468
470
|
end
|
469
471
|
end
|
470
472
|
end
|
@@ -55,7 +55,7 @@ module Test
|
|
55
55
|
sub_suites = []
|
56
56
|
path = realdir(name)
|
57
57
|
if @file.directory?(path)
|
58
|
-
|
58
|
+
dir_name = name unless name == '.'
|
59
59
|
@dir.entries(path).each do |e|
|
60
60
|
next if(e == '.' || e == '..')
|
61
61
|
e_name = dir_name ? @file.join(dir_name, e) : e
|
@@ -95,13 +95,13 @@ module Test
|
|
95
95
|
$:.delete_at($:.rindex(dir)) if(dir)
|
96
96
|
end
|
97
97
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
98
|
+
def realdir(path)
|
99
|
+
if @base
|
100
|
+
@file.join(@base, path)
|
101
|
+
else
|
102
|
+
path
|
103
|
+
end
|
104
|
+
end
|
105
105
|
end
|
106
106
|
end
|
107
107
|
end
|
@@ -119,10 +119,16 @@ module Test
|
|
119
119
|
end
|
120
120
|
|
121
121
|
def add_load_path(path)
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
122
|
+
return yield if path.nil?
|
123
|
+
|
124
|
+
path = path.to_s
|
125
|
+
begin
|
126
|
+
$LOAD_PATH.unshift(path)
|
127
|
+
yield
|
128
|
+
ensure
|
129
|
+
index = $LOAD_PATH.index(path)
|
130
|
+
$LOAD_PATH.delete_at(index) if index
|
131
|
+
end
|
126
132
|
end
|
127
133
|
|
128
134
|
def excluded_directory?(base)
|
@@ -9,14 +9,14 @@ module Test
|
|
9
9
|
module Collector
|
10
10
|
class ObjectSpace
|
11
11
|
include Collector
|
12
|
-
|
12
|
+
|
13
13
|
NAME = 'collected from the ObjectSpace'
|
14
|
-
|
14
|
+
|
15
15
|
def initialize(source=::ObjectSpace)
|
16
16
|
super()
|
17
17
|
@source = source
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def collect(name=NAME)
|
21
21
|
suite = TestSuite.new(name)
|
22
22
|
sub_suites = []
|
@@ -41,9 +41,10 @@ module Test
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def collect_test_names
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
methods = @test_case.public_instance_methods(true)
|
45
|
+
super_test_case = @test_case.superclass
|
46
|
+
methods -= super_test_case.public_instance_methods(true)
|
47
|
+
method_names = methods.collect(&:to_s)
|
47
48
|
test_names = method_names.find_all do |method_name|
|
48
49
|
method_name =~ /^test./ or @test_case.attributes(method_name)[:test]
|
49
50
|
end
|
data/lib/test/unit/testcase.rb
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
require 'test/unit/attribute'
|
10
10
|
require 'test/unit/fixture'
|
11
|
-
require 'test/unit/
|
11
|
+
require 'test/unit/exception-handler'
|
12
12
|
require 'test/unit/assertions'
|
13
13
|
require 'test/unit/failure'
|
14
14
|
require 'test/unit/error'
|
@@ -18,8 +18,8 @@ require 'test/unit/notification'
|
|
18
18
|
require 'test/unit/priority'
|
19
19
|
require 'test/unit/data'
|
20
20
|
require 'test/unit/testsuite'
|
21
|
-
require 'test/unit/
|
22
|
-
require 'test/unit/
|
21
|
+
require 'test/unit/test-suite-creator'
|
22
|
+
require 'test/unit/assertion-failed-error'
|
23
23
|
require 'test/unit/util/backtracefilter'
|
24
24
|
require 'test/unit/util/output'
|
25
25
|
require 'test/unit/util/method-owner-finder'
|
@@ -117,8 +117,14 @@ module Test
|
|
117
117
|
if _added_methods.include?(stringified_name)
|
118
118
|
attribute(:redefined, {:backtrace => caller}, {}, stringified_name)
|
119
119
|
end
|
120
|
-
|
121
|
-
|
120
|
+
_attributes = attributes_table[stringified_name] || {}
|
121
|
+
source_location = _attributes[:source_location]
|
122
|
+
if source_location
|
123
|
+
path, line = source_location
|
124
|
+
else
|
125
|
+
path, line, = caller[0].split(/:(\d+)/,2)
|
126
|
+
line = line.to_i if line
|
127
|
+
end
|
122
128
|
method_locations << {
|
123
129
|
:method_name => stringified_name,
|
124
130
|
:path => path,
|
@@ -267,12 +273,12 @@ module Test
|
|
267
273
|
raise ArgumentError, message
|
268
274
|
end
|
269
275
|
method_name = "test: #{test_description}"
|
270
|
-
define_method(method_name, &block)
|
271
276
|
description(test_description, method_name)
|
272
277
|
attribute(:test, true, {}, method_name)
|
273
278
|
if block.respond_to?(:source_location)
|
274
279
|
attribute(:source_location, block.source_location, {}, method_name)
|
275
280
|
end
|
281
|
+
define_method(method_name, &block)
|
276
282
|
else
|
277
283
|
targets = test_description_or_targets
|
278
284
|
attribute(:test, true, {}, *targets)
|
@@ -330,10 +336,11 @@ module Test
|
|
330
336
|
# case class context.
|
331
337
|
# @return [Test::Unit::TestCase] Created sub test case class.
|
332
338
|
def sub_test_case(name, &block)
|
339
|
+
parent_test_case = self
|
333
340
|
sub_test_case = Class.new(self) do
|
334
341
|
singleton_class = class << self; self; end
|
335
342
|
singleton_class.send(:define_method, :name) do
|
336
|
-
name
|
343
|
+
[parent_test_case.name, name].compact.join("::")
|
337
344
|
end
|
338
345
|
end
|
339
346
|
sub_test_case.class_eval(&block)
|
@@ -27,13 +27,17 @@ module Test
|
|
27
27
|
entry.start_with?("org/jruby/")
|
28
28
|
end
|
29
29
|
|
30
|
+
rubinius_internal_p = lambda do |entry|
|
31
|
+
entry.start_with?("kernel/")
|
32
|
+
end
|
33
|
+
|
30
34
|
found_prefix = false
|
31
35
|
new_backtrace = backtrace.reverse.reject do |entry|
|
32
36
|
if test_unit_internal_p.call(entry)
|
33
37
|
found_prefix = true
|
34
38
|
true
|
35
39
|
elsif found_prefix
|
36
|
-
jruby_internal_p.call(entry)
|
40
|
+
jruby_internal_p.call(entry) or rubinius_internal_p.call(entry)
|
37
41
|
else
|
38
42
|
true
|
39
43
|
end
|
@@ -41,7 +45,9 @@ module Test
|
|
41
45
|
|
42
46
|
if new_backtrace.empty?
|
43
47
|
new_backtrace = backtrace.reject do |entry|
|
44
|
-
test_unit_internal_p.call(entry) or
|
48
|
+
test_unit_internal_p.call(entry) or
|
49
|
+
jruby_internal_p.call(entry) or
|
50
|
+
rubinius_internal_p.call(entry)
|
45
51
|
end
|
46
52
|
new_backtrace = backtrace if new_backtrace.empty?
|
47
53
|
end
|
data/lib/test/unit/version.rb
CHANGED
data/test/test-assertions.rb
CHANGED
@@ -2,10 +2,11 @@
|
|
2
2
|
#
|
3
3
|
# Author:: Nathaniel Talbott.
|
4
4
|
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
5
|
-
# Copyright (c) 2009-
|
5
|
+
# Copyright (c) 2009-2014 Kouhei Sutou. All rights reserved.
|
6
6
|
# License:: Ruby license.
|
7
7
|
|
8
8
|
require 'test/unit'
|
9
|
+
require "testunit-test-util"
|
9
10
|
|
10
11
|
module Test
|
11
12
|
module Unit
|
@@ -102,17 +103,7 @@ module Test
|
|
102
103
|
end
|
103
104
|
|
104
105
|
def inspect_tag(tag)
|
105
|
-
|
106
|
-
"`#{tag}'".inspect
|
107
|
-
else
|
108
|
-
begin
|
109
|
-
throw tag
|
110
|
-
rescue NameError
|
111
|
-
tag.to_s.inspect
|
112
|
-
rescue ArgumentError
|
113
|
-
tag.inspect
|
114
|
-
end
|
115
|
-
end
|
106
|
+
tag.inspect
|
116
107
|
end
|
117
108
|
|
118
109
|
def add_failure(message, location=caller, options=nil)
|
@@ -151,15 +142,24 @@ module Test
|
|
151
142
|
}
|
152
143
|
end
|
153
144
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
145
|
+
class TestAssertEqual < self
|
146
|
+
class TestSuccess < self
|
147
|
+
def test_without_message
|
148
|
+
check_nothing_fails {
|
149
|
+
assert_equal("string1", "string1")
|
150
|
+
}
|
151
|
+
end
|
161
152
|
|
162
|
-
|
153
|
+
def test_with_message
|
154
|
+
check_nothing_fails {
|
155
|
+
assert_equal("string1", "string1", "successful assert_equal")
|
156
|
+
}
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
class TestFailure < self
|
161
|
+
def test_without_message
|
162
|
+
message = <<-EOM.chomp
|
163
163
|
<"string1"> expected but was
|
164
164
|
<"string2">.
|
165
165
|
|
@@ -169,11 +169,13 @@ diff:
|
|
169
169
|
+ string2
|
170
170
|
? ^
|
171
171
|
EOM
|
172
|
-
|
173
|
-
|
174
|
-
|
172
|
+
check_fail(message) {
|
173
|
+
assert_equal("string1", "string2")
|
174
|
+
}
|
175
|
+
end
|
175
176
|
|
176
|
-
|
177
|
+
def test_with_message
|
178
|
+
message = <<-EOM.chomp
|
177
179
|
failed assert_equal.
|
178
180
|
<"string1"> expected but was
|
179
181
|
<"string2">.
|
@@ -184,11 +186,15 @@ diff:
|
|
184
186
|
+ string2
|
185
187
|
? ^
|
186
188
|
EOM
|
187
|
-
|
188
|
-
|
189
|
-
|
189
|
+
check_fail(message) {
|
190
|
+
assert_equal("string1", "string2", "failed assert_equal")
|
191
|
+
}
|
192
|
+
end
|
193
|
+
end
|
190
194
|
|
191
|
-
|
195
|
+
class TestSystemMessage < self
|
196
|
+
def test_different_type
|
197
|
+
message = <<-EOM.chomp
|
192
198
|
<"111111"> expected but was
|
193
199
|
<111111>.
|
194
200
|
|
@@ -197,31 +203,31 @@ diff:
|
|
197
203
|
? - -
|
198
204
|
+ 111111
|
199
205
|
EOM
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
206
|
+
check_fail(message) do
|
207
|
+
assert_equal("111111", 111111)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
def test_long_line
|
212
|
+
expected = ["0123456789",
|
213
|
+
"1123456789",
|
214
|
+
"2123456789",
|
215
|
+
"3123456789",
|
216
|
+
"4123456789",
|
217
|
+
"5123456789",
|
218
|
+
"6123456789",
|
219
|
+
"7123456789",
|
220
|
+
"8123456789"].join
|
221
|
+
actual = ["0000000000",
|
222
|
+
"1123456789",
|
223
|
+
"2123456789",
|
224
|
+
"3123456789",
|
225
|
+
"4123456789",
|
226
|
+
"5123456789",
|
227
|
+
"6123456789",
|
228
|
+
"7123456789",
|
229
|
+
"8123456789"].join
|
230
|
+
message = <<-EOM.chomp
|
225
231
|
<"#{expected}"> expected but was
|
226
232
|
<"#{actual}">.
|
227
233
|
|
@@ -238,35 +244,35 @@ folded diff:
|
|
238
244
|
? ^^^^^^^^^
|
239
245
|
898123456789
|
240
246
|
EOM
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
247
|
+
check_fail(message) do
|
248
|
+
assert_equal(expected, actual)
|
249
|
+
end
|
250
|
+
end
|
245
251
|
|
246
|
-
|
247
|
-
|
252
|
+
def test_too_small_difference
|
253
|
+
message = <<-EOM.chomp
|
248
254
|
<1> expected but was
|
249
255
|
<2>.
|
250
256
|
EOM
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
257
|
+
check_fail(message) do
|
258
|
+
assert_equal(1, 2)
|
259
|
+
end
|
260
|
+
end
|
255
261
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
262
|
+
def test_same_inspected_objects
|
263
|
+
now = Time.now
|
264
|
+
now_without_usec = Time.at(now.to_i)
|
265
|
+
message = <<-EOM.chomp
|
260
266
|
<#{now.inspect}> expected but was
|
261
267
|
<#{now.inspect}>.
|
262
268
|
EOM
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
269
|
+
check_fail(message) do
|
270
|
+
assert_equal(now, now_without_usec)
|
271
|
+
end
|
272
|
+
end
|
267
273
|
|
268
|
-
|
269
|
-
|
274
|
+
def test_multi_lines_result
|
275
|
+
message = <<-EOM.chomp
|
270
276
|
<#{"a\nb".inspect}> expected but was
|
271
277
|
<#{"x".inspect}>.
|
272
278
|
|
@@ -275,13 +281,13 @@ diff:
|
|
275
281
|
- a
|
276
282
|
- b
|
277
283
|
EOM
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
284
|
+
check_fail(message) do
|
285
|
+
assert_equal("a\nb", "x")
|
286
|
+
end
|
287
|
+
end
|
282
288
|
|
283
|
-
|
284
|
-
|
289
|
+
def test_large_string
|
290
|
+
message = <<-EOM.chomp
|
285
291
|
<#{("a\n" + "x" * 997).inspect}> expected but was
|
286
292
|
<#{"x".inspect}>.
|
287
293
|
|
@@ -296,25 +302,25 @@ folded diff:
|
|
296
302
|
#{(["- " + ("x" * 78)] * 12).join("\n")}
|
297
303
|
- #{"x" * 61}
|
298
304
|
EOM
|
299
|
-
|
300
|
-
|
301
|
-
|
305
|
+
check_fail(message) do
|
306
|
+
assert_equal("a\n" + "x" * 997, "x")
|
307
|
+
end
|
302
308
|
|
303
|
-
|
309
|
+
message = <<-EOM.chomp
|
304
310
|
<#{("a\n" + "x" * 998).inspect}> expected but was
|
305
311
|
<#{"x".inspect}>.
|
306
312
|
EOM
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
313
|
+
check_fail(message) do
|
314
|
+
assert_equal("a\n" + "x" * 998, "x")
|
315
|
+
end
|
316
|
+
end
|
311
317
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
+
def test_max_diff_target_string_size
|
319
|
+
key = "TEST_UNIT_MAX_DIFF_TARGET_STRING_SIZE"
|
320
|
+
before_value = ENV[key]
|
321
|
+
ENV[key] = "100"
|
322
|
+
begin
|
323
|
+
message = <<-EOM.chomp
|
318
324
|
<#{("a\n" + "x" * 97).inspect}> expected but was
|
319
325
|
<#{"x".inspect}>.
|
320
326
|
|
@@ -329,61 +335,61 @@ folded diff:
|
|
329
335
|
#{(["- " + ("x" * 78)]).join("\n")}
|
330
336
|
- #{"x" * 19}
|
331
337
|
EOM
|
332
|
-
|
333
|
-
|
334
|
-
|
338
|
+
check_fail(message) do
|
339
|
+
assert_equal("a\n" + "x" * 97, "x")
|
340
|
+
end
|
335
341
|
|
336
|
-
|
342
|
+
message = <<-EOM.chomp
|
337
343
|
<#{("a\n" + "x" * 98).inspect}> expected but was
|
338
344
|
<#{"x".inspect}>.
|
339
345
|
EOM
|
340
|
-
|
341
|
-
|
346
|
+
check_fail(message) do
|
347
|
+
assert_equal("a\n" + "x" * 98, "x")
|
348
|
+
end
|
349
|
+
ensure
|
350
|
+
ENV[key] = before_value
|
351
|
+
end
|
342
352
|
end
|
343
|
-
ensure
|
344
|
-
ENV[key] = before_value
|
345
|
-
end
|
346
|
-
end
|
347
353
|
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
354
|
+
def test_different_encoding
|
355
|
+
utf8_string = "こんにちは"
|
356
|
+
unless utf8_string.respond_to?(:force_encoding)
|
357
|
+
omit("encoding test is for Ruby >= 1.9")
|
358
|
+
end
|
359
|
+
ascii_8bit_string = utf8_string.dup.force_encoding("ascii-8bit")
|
360
|
+
message = <<-EOM.chomp
|
355
361
|
<#{utf8_string.inspect}>("UTF-8") expected but was
|
356
362
|
<#{ascii_8bit_string.inspect}>("ASCII-8BIT").
|
357
363
|
EOM
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
364
|
+
check_fail(message) do
|
365
|
+
assert_equal(utf8_string, ascii_8bit_string)
|
366
|
+
end
|
367
|
+
end
|
362
368
|
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
369
|
+
def test_different_hash
|
370
|
+
designers = {
|
371
|
+
"Ruby" => "Matz",
|
372
|
+
"Lisp" => "John McCarthy",
|
373
|
+
}
|
374
|
+
categories = {
|
375
|
+
"LL" => ["Ruby", "Python"],
|
376
|
+
"Heavy" => ["C", "C++"],
|
377
|
+
}
|
378
|
+
message = <<-EOM.chomp
|
373
379
|
<{"Lisp"=>"John McCarthy", "Ruby"=>"Matz"}> expected but was
|
374
380
|
<{"Heavy"=>["C", "C++"], "LL"=>["Ruby", "Python"]}>.
|
375
381
|
EOM
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
382
|
+
check_fail(message) do
|
383
|
+
assert_equal(designers, categories)
|
384
|
+
end
|
385
|
+
end
|
380
386
|
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
+
def test_recursive_hash
|
388
|
+
alice = {"name" => "Alice"}
|
389
|
+
bob = {"name" => "Bob"}
|
390
|
+
alice["followers"] = [bob]
|
391
|
+
bob["followers"] = [alice]
|
392
|
+
message = <<-EOM.chomp
|
387
393
|
<{"followers"=>[{"followers"=>[{...}], "name"=>"Bob"}], "name"=>"Alice"}> expected but was
|
388
394
|
<{"followers"=>[{"followers"=>[{...}], "name"=>"Alice"}], "name"=>"Bob"}>.
|
389
395
|
|
@@ -393,8 +399,31 @@ diff:
|
|
393
399
|
+ {"followers"=>[{"followers"=>[{...}], "name"=>"Alice"}], "name"=>"Bob"}
|
394
400
|
? +++++++++++++++++
|
395
401
|
EOM
|
396
|
-
|
397
|
-
|
402
|
+
check_fail(message) do
|
403
|
+
assert_equal(alice, bob)
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
def test_numeric
|
408
|
+
numeric_family_class = Class.new(Numeric) do
|
409
|
+
def inspect
|
410
|
+
"inspect is called"
|
411
|
+
end
|
412
|
+
|
413
|
+
def to_s
|
414
|
+
"to_s is called"
|
415
|
+
end
|
416
|
+
end
|
417
|
+
numeric = numeric_family_class.new
|
418
|
+
|
419
|
+
message = <<-MESSAGE.chomp
|
420
|
+
<to_s is called> expected but was
|
421
|
+
<"must be failed">.
|
422
|
+
MESSAGE
|
423
|
+
check_fail(message) do
|
424
|
+
assert_equal(numeric, "must be failed")
|
425
|
+
end
|
426
|
+
end
|
398
427
|
end
|
399
428
|
end
|
400
429
|
|
@@ -592,24 +621,49 @@ EOM
|
|
592
621
|
check_nothing_fails {
|
593
622
|
assert_instance_of(String, "string", "successful assert_instance_of")
|
594
623
|
}
|
595
|
-
check_fail(%Q{<"string"> expected to be
|
624
|
+
check_fail(%Q{<"string"> expected to be instance_of?\n<Hash> but was\n<String>.}) {
|
596
625
|
assert_instance_of(Hash, "string")
|
597
626
|
}
|
598
|
-
check_fail(%Q{failed assert_instance_of.\n<"string"> expected to be
|
627
|
+
check_fail(%Q{failed assert_instance_of.\n<"string"> expected to be instance_of?\n<Hash> but was\n<String>.}) {
|
599
628
|
assert_instance_of(Hash, "string", "failed assert_instance_of")
|
600
629
|
}
|
601
630
|
|
602
631
|
check_nothing_fails do
|
603
632
|
assert_instance_of([Fixnum, NilClass], 100)
|
604
633
|
end
|
605
|
-
check_fail(%Q{<"string"> expected to be
|
634
|
+
check_fail(%Q{<"string"> expected to be instance_of?\n[<Fixnum>, <NilClass>] but was\n<String>.}) do
|
606
635
|
assert_instance_of([Fixnum, NilClass], "string")
|
607
636
|
end
|
608
|
-
check_fail(%Q{<100> expected to be
|
637
|
+
check_fail(%Q{<100> expected to be instance_of?\n[<Numeric>, <NilClass>] but was\n<Fixnum>.}) do
|
609
638
|
assert_instance_of([Numeric, NilClass], 100)
|
610
639
|
end
|
611
640
|
end
|
612
641
|
|
642
|
+
def test_assert_not_instance_of
|
643
|
+
check_nothing_fails {
|
644
|
+
assert_not_instance_of(NilClass, "string")
|
645
|
+
}
|
646
|
+
check_nothing_fails {
|
647
|
+
assert_not_instance_of(NilClass, "string", "successful assert_instance_of")
|
648
|
+
}
|
649
|
+
check_fail(%Q{<"string"> expected to not be instance_of?\n<String> but was.}) {
|
650
|
+
assert_not_instance_of(String, "string")
|
651
|
+
}
|
652
|
+
check_fail(%Q{failed assert.\n<"string"> expected to not be instance_of?\n<String> but was.}) {
|
653
|
+
assert_not_instance_of(String, "string", "failed assert")
|
654
|
+
}
|
655
|
+
|
656
|
+
check_nothing_fails do
|
657
|
+
assert_not_instance_of([Numeric, NilClass], 100)
|
658
|
+
end
|
659
|
+
check_fail(%Q{<100> expected to not be instance_of?\n[<Fixnum>, <NilClass>] but was.}) do
|
660
|
+
assert_not_instance_of([Fixnum, NilClass], 100)
|
661
|
+
end
|
662
|
+
check_fail(%Q{<"str"> expected to not be instance_of?\n[<Numeric>, <String>] but was.}) do
|
663
|
+
assert_not_instance_of([Numeric, String], 'str')
|
664
|
+
end
|
665
|
+
end
|
666
|
+
|
613
667
|
def test_assert_nil
|
614
668
|
check_nothing_fails {
|
615
669
|
assert_nil(nil)
|
@@ -627,14 +681,14 @@ EOM
|
|
627
681
|
assert_nil("string", "failed assert_nil")
|
628
682
|
}
|
629
683
|
end
|
630
|
-
|
684
|
+
|
631
685
|
def test_assert_not_nil
|
632
686
|
check_nothing_fails{assert_not_nil(false)}
|
633
687
|
check_nothing_fails{assert_not_nil(false, "message")}
|
634
688
|
check_fail("<nil> expected to not be nil."){assert_not_nil(nil)}
|
635
689
|
check_fail("message.\n<nil> expected to not be nil.") {assert_not_nil(nil, "message")}
|
636
690
|
end
|
637
|
-
|
691
|
+
|
638
692
|
def test_assert_kind_of
|
639
693
|
check_nothing_fails {
|
640
694
|
assert_kind_of(Module, Array)
|
@@ -643,7 +697,7 @@ EOM
|
|
643
697
|
assert_kind_of(Object, "string", "successful assert_kind_of")
|
644
698
|
}
|
645
699
|
check_nothing_fails {
|
646
|
-
assert_kind_of(
|
700
|
+
assert_kind_of(String, "string", "successful assert_kind_of")
|
647
701
|
}
|
648
702
|
check_nothing_fails {
|
649
703
|
assert_kind_of(Comparable, 1)
|
@@ -663,6 +717,31 @@ EOM
|
|
663
717
|
end
|
664
718
|
end
|
665
719
|
|
720
|
+
def test_assert_not_kind_of
|
721
|
+
check_nothing_fails {
|
722
|
+
assert_not_kind_of(Class, 42)
|
723
|
+
}
|
724
|
+
check_nothing_fails {
|
725
|
+
assert_not_kind_of(Symbol, "string", "successful assert_not_kind_of")
|
726
|
+
}
|
727
|
+
check_nothing_fails {
|
728
|
+
assert_not_kind_of(Integer, 1.1)
|
729
|
+
}
|
730
|
+
check_fail(%Q{<1> expected to not be kind_of?\n<Integer> but was.}) {
|
731
|
+
assert_not_kind_of(Integer, 1)
|
732
|
+
}
|
733
|
+
check_fail(%Q{failed assert_not_kind_of.\n<"string"> expected to not be kind_of?\n<String> but was.}) {
|
734
|
+
assert_not_kind_of(String, "string", "failed assert_not_kind_of")
|
735
|
+
}
|
736
|
+
|
737
|
+
check_nothing_fails do
|
738
|
+
assert_not_kind_of([String, NilClass], 100)
|
739
|
+
end
|
740
|
+
check_fail(%Q{<100> expected to not be kind_of?\n[<Fixnum>, <NilClass>] but was.}) do
|
741
|
+
assert_not_kind_of([Fixnum, NilClass], 100)
|
742
|
+
end
|
743
|
+
end
|
744
|
+
|
666
745
|
def test_assert_match
|
667
746
|
check_nothing_fails {
|
668
747
|
assert_match(/strin./, "string")
|
@@ -686,7 +765,7 @@ EOM
|
|
686
765
|
assert_match(/slin./, "string", "failed assert_match")
|
687
766
|
}
|
688
767
|
end
|
689
|
-
|
768
|
+
|
690
769
|
def test_assert_same
|
691
770
|
thing = "thing"
|
692
771
|
check_nothing_fails {
|
@@ -706,7 +785,7 @@ EOM
|
|
706
785
|
assert_same(thing, thing2, "failed assert_same")
|
707
786
|
}
|
708
787
|
end
|
709
|
-
|
788
|
+
|
710
789
|
def test_assert_nothing_raised
|
711
790
|
check_nothing_fails {
|
712
791
|
assert_nothing_raised {
|
@@ -796,7 +875,7 @@ EOM
|
|
796
875
|
assert_not_same(thing, thing, "message")
|
797
876
|
}
|
798
877
|
end
|
799
|
-
|
878
|
+
|
800
879
|
def test_assert_not_equal
|
801
880
|
check_nothing_fails {
|
802
881
|
assert_not_equal("string1", "string2")
|
@@ -827,7 +906,7 @@ EOM
|
|
827
906
|
def test_assert_not_match_fail_not_regexp
|
828
907
|
check_fail("<REGEXP> in assert_not_match(<REGEXP>, ...) " +
|
829
908
|
"should be a Regexp.\n" +
|
830
|
-
"<\"asdf\"> expected to be
|
909
|
+
"<\"asdf\"> expected to be instance_of?\n" +
|
831
910
|
"<Regexp> but was\n" +
|
832
911
|
"<String>.") do
|
833
912
|
assert_not_match("asdf", "asdf")
|
@@ -852,7 +931,7 @@ EOM
|
|
852
931
|
def test_assert_no_match
|
853
932
|
check_nothing_fails{assert_no_match(/sling/, "string")}
|
854
933
|
check_nothing_fails{assert_no_match(/sling/, "string", "message")}
|
855
|
-
check_fail(%Q{The first argument to assert_no_match should be a Regexp.\n<"asdf"> expected to be
|
934
|
+
check_fail(%Q{The first argument to assert_no_match should be a Regexp.\n<"asdf"> expected to be instance_of?\n<Regexp> but was\n<String>.}) do
|
856
935
|
assert_no_match("asdf", "asdf")
|
857
936
|
end
|
858
937
|
check_fail(%Q{</string/> expected to not match\n<"string">.}) do
|
@@ -885,7 +964,7 @@ EOM
|
|
885
964
|
end
|
886
965
|
end
|
887
966
|
end
|
888
|
-
|
967
|
+
|
889
968
|
def test_assert_nothing_thrown
|
890
969
|
check_nothing_fails do
|
891
970
|
assert_nothing_thrown("message") do
|
@@ -902,7 +981,7 @@ EOM
|
|
902
981
|
end
|
903
982
|
end
|
904
983
|
end
|
905
|
-
|
984
|
+
|
906
985
|
def test_assert_operator
|
907
986
|
check_nothing_fails {
|
908
987
|
assert_operator("thing", :==, "thing", "message")
|
@@ -915,6 +994,18 @@ EOM
|
|
915
994
|
}
|
916
995
|
end
|
917
996
|
|
997
|
+
def test_assert_not_operator
|
998
|
+
check_nothing_fails {
|
999
|
+
assert_not_operator("thing", :==, "Thing", "message")
|
1000
|
+
}
|
1001
|
+
check_fail(%Q{<42>\ngiven as the operator for #assert_not_operator must be a Symbol or #respond_to?(:to_str).}) do
|
1002
|
+
assert_not_operator("thing", 42, "message")
|
1003
|
+
end
|
1004
|
+
check_fail(%Q{message.\n<0> expected to not be\n==\n<0.0>.}) {
|
1005
|
+
assert_not_operator(0, :==, 0.0, "message")
|
1006
|
+
}
|
1007
|
+
end
|
1008
|
+
|
918
1009
|
def test_assert_respond_to
|
919
1010
|
check_nothing_fails {
|
920
1011
|
assert_respond_to("thing", :to_s, "message")
|
@@ -1316,6 +1407,14 @@ EOM
|
|
1316
1407
|
end
|
1317
1408
|
end
|
1318
1409
|
|
1410
|
+
def test_pass_block
|
1411
|
+
check_nothing_fails do
|
1412
|
+
assert do
|
1413
|
+
true
|
1414
|
+
end
|
1415
|
+
end
|
1416
|
+
end
|
1417
|
+
|
1319
1418
|
def test_fail_nil
|
1320
1419
|
check_fail("<nil> is not true.") do
|
1321
1420
|
assert(nil)
|
@@ -1344,6 +1443,14 @@ EOM
|
|
1344
1443
|
end
|
1345
1444
|
end
|
1346
1445
|
|
1446
|
+
def test_fail_block
|
1447
|
+
check_fail(//) do
|
1448
|
+
assert do
|
1449
|
+
0.odd?
|
1450
|
+
end
|
1451
|
+
end
|
1452
|
+
end
|
1453
|
+
|
1347
1454
|
def test_error_invalid_message_true
|
1348
1455
|
check_fail("assertion message must be String, Proc or " +
|
1349
1456
|
"Test::Unit::Assertions::AssertionMessage: " +
|
@@ -1355,6 +1462,33 @@ EOM
|
|
1355
1462
|
end
|
1356
1463
|
end
|
1357
1464
|
end
|
1465
|
+
|
1466
|
+
def test_error_wrong_number_of_arguments
|
1467
|
+
check_fail("wrong number of arguments (0 for 1..2)") do
|
1468
|
+
begin
|
1469
|
+
assert
|
1470
|
+
rescue ArgumentError
|
1471
|
+
raise AssertionFailedError, $!.message
|
1472
|
+
end
|
1473
|
+
end
|
1474
|
+
end
|
1475
|
+
|
1476
|
+
class TestBlock < self
|
1477
|
+
def test_with_message
|
1478
|
+
if defined?(PowerAssert)
|
1479
|
+
system_message = <<-MESSAGE
|
1480
|
+
1 == 2
|
1481
|
+
MESSAGE
|
1482
|
+
else
|
1483
|
+
system_message = "<false> is not true."
|
1484
|
+
end
|
1485
|
+
check_fail("user message.\n#{system_message}") do
|
1486
|
+
assert("user message") do
|
1487
|
+
1 == 2
|
1488
|
+
end
|
1489
|
+
end
|
1490
|
+
end
|
1491
|
+
end
|
1358
1492
|
end
|
1359
1493
|
|
1360
1494
|
class TestRefute < TestCase
|