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