activeldap 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +34 -0
- data/README +13 -0
- data/Rakefile +2 -1
- data/TODO +6 -0
- data/benchmark/bench-al.rb +68 -17
- data/examples/al-admin/app/helpers/application_helper.rb +3 -5
- data/examples/al-admin/app/views/layouts/_footer.html.erb +2 -0
- data/examples/al-admin/config/boot.rb +7 -7
- data/examples/al-admin/config/environment.rb +27 -12
- data/examples/al-admin/config/environments/development.rb +0 -1
- data/examples/al-admin/config/environments/production.rb +6 -1
- data/examples/al-admin/config/environments/test.rb +1 -1
- data/examples/al-admin/config/initializers/gettext.rb +15 -1
- data/examples/al-admin/po/en/al-admin.po +1 -1
- data/examples/al-admin/po/ja/al-admin.po +1 -1
- data/examples/al-admin/po/nl/al-admin.po +1 -1
- data/examples/al-admin/public/dispatch.cgi +0 -0
- data/examples/al-admin/public/dispatch.fcgi +0 -0
- data/examples/al-admin/public/dispatch.rb +0 -0
- data/examples/al-admin/public/javascripts/controls.js +73 -73
- data/examples/al-admin/public/javascripts/dragdrop.js +166 -165
- data/examples/al-admin/public/javascripts/effects.js +174 -166
- data/examples/al-admin/public/javascripts/prototype.js +362 -267
- data/examples/al-admin/script/about +0 -0
- data/examples/al-admin/script/console +0 -0
- data/examples/al-admin/script/dbconsole +3 -0
- data/examples/al-admin/script/destroy +0 -0
- data/examples/al-admin/script/generate +0 -0
- data/examples/al-admin/script/performance/benchmarker +0 -0
- data/examples/al-admin/script/performance/profiler +0 -0
- data/examples/al-admin/script/performance/request +0 -0
- data/examples/al-admin/script/plugin +0 -0
- data/examples/al-admin/script/process/inspector +0 -0
- data/examples/al-admin/script/process/reaper +0 -0
- data/examples/al-admin/script/process/spawner +0 -0
- data/examples/al-admin/script/runner +0 -0
- data/examples/al-admin/script/server +0 -0
- data/examples/al-admin/test/run-test.sh +0 -0
- data/examples/groupadd +0 -0
- data/examples/groupdel +0 -0
- data/examples/groupls +0 -0
- data/examples/groupmod +0 -0
- data/examples/lpasswd +0 -0
- data/examples/ouadd +0 -0
- data/examples/useradd +0 -0
- data/examples/useradd-binary +0 -0
- data/examples/userdel +0 -0
- data/examples/userls +0 -0
- data/examples/usermod +0 -0
- data/examples/usermod-binary-add +0 -0
- data/examples/usermod-binary-add-time +0 -0
- data/examples/usermod-binary-del +0 -0
- data/examples/usermod-lang-add +0 -0
- data/lib/active_ldap.rb +10 -4
- data/lib/active_ldap/action_controller/ldap_benchmarking.rb +28 -9
- data/lib/active_ldap/adapter/base.rb +30 -17
- data/lib/active_ldap/adapter/jndi.rb +5 -1
- data/lib/active_ldap/adapter/ldap.rb +5 -1
- data/lib/active_ldap/association/has_many_utils.rb +7 -1
- data/lib/active_ldap/associations.rb +10 -5
- data/lib/active_ldap/attributes.rb +6 -1
- data/lib/active_ldap/base.rb +154 -52
- data/lib/active_ldap/configuration.rb +1 -1
- data/lib/active_ldap/connection.rb +7 -4
- data/lib/active_ldap/get_text.rb +11 -3
- data/lib/active_ldap/ldif.rb +16 -4
- data/lib/active_ldap/operations.rb +13 -5
- data/lib/active_ldap/schema.rb +6 -2
- data/lib/active_ldap/schema/syntaxes.rb +15 -3
- data/lib/active_ldap/user_password.rb +4 -4
- data/lib/active_ldap/validations.rb +32 -44
- data/lib/active_ldap/xml.rb +125 -0
- data/po/en/active-ldap.po +740 -85
- data/po/ja/active-ldap.po +748 -547
- data/rails/README +54 -0
- data/rails/init.rb +33 -0
- data/rails/plugin/active_ldap/generators/README +2 -0
- data/rails/plugin/active_ldap/generators/model_active_ldap/model_active_ldap_generator.rb +1 -1
- data/rails/plugin/active_ldap/init.rb +3 -0
- data/rails_generators/model_active_ldap/USAGE +17 -0
- data/rails_generators/model_active_ldap/model_active_ldap_generator.rb +69 -0
- data/rails_generators/model_active_ldap/templates/model_active_ldap.rb +3 -0
- data/rails_generators/model_active_ldap/templates/unit_test.rb +8 -0
- data/rails_generators/scaffold_active_ldap/scaffold_active_ldap_generator.rb +7 -0
- data/rails_generators/scaffold_active_ldap/templates/ldap.yml +18 -0
- data/rails_generators/scaffold_al/scaffold_al_generator.rb +20 -0
- data/test-unit/History.txt +50 -1
- data/test-unit/Manifest.txt +22 -12
- data/test-unit/README.txt +31 -12
- data/test-unit/Rakefile +14 -1
- data/test-unit/TODO +5 -0
- data/test-unit/bin/testrb +0 -0
- data/test-unit/lib/test/unit.rb +62 -0
- data/test-unit/lib/test/unit/assertions.rb +419 -75
- data/test-unit/lib/test/unit/autorunner.rb +70 -13
- data/test-unit/lib/test/unit/collector.rb +1 -1
- data/test-unit/lib/test/unit/collector/load.rb +1 -1
- data/test-unit/lib/test/unit/color-scheme.rb +86 -0
- data/test-unit/lib/test/unit/color.rb +40 -5
- data/test-unit/lib/test/unit/diff.rb +14 -0
- data/test-unit/lib/test/unit/fixture.rb +7 -16
- data/test-unit/lib/test/unit/notification.rb +9 -0
- data/test-unit/lib/test/unit/omission.rb +14 -0
- data/test-unit/lib/test/unit/pending.rb +16 -0
- data/test-unit/lib/test/unit/priority.rb +17 -2
- data/test-unit/lib/test/unit/runner/console.rb +8 -2
- data/test-unit/lib/test/unit/testcase.rb +188 -2
- data/test-unit/lib/test/unit/ui/console/testrunner.rb +51 -26
- data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
- data/test-unit/lib/test/unit/version.rb +1 -1
- data/test-unit/sample/test_user.rb +22 -0
- data/test-unit/test/collector/{test_descendant.rb → test-descendant.rb} +0 -0
- data/test-unit/test/collector/{test_load.rb → test-load.rb} +1 -1
- data/test-unit/test/run-test.rb +0 -0
- data/test-unit/test/{test_attribute.rb → test-attribute.rb} +0 -0
- data/test-unit/test/test-color-scheme.rb +56 -0
- data/test-unit/test/{test_color.rb → test-color.rb} +10 -0
- data/test-unit/test/{test_diff.rb → test-diff.rb} +0 -0
- data/test-unit/test/{test_emacs_runner.rb → test-emacs-runner.rb} +0 -0
- data/test-unit/test/test-fixture.rb +287 -0
- data/test-unit/test/{test_notification.rb → test-notification.rb} +4 -4
- data/test-unit/test/{test_omission.rb → test-omission.rb} +6 -6
- data/test-unit/test/{test_pending.rb → test-pending.rb} +12 -6
- data/test-unit/test/{test_priority.rb → test-priority.rb} +30 -0
- data/test-unit/test/test_assertions.rb +411 -69
- data/test-unit/test/test_testcase.rb +70 -3
- data/test-unit/test/{testunit_test_util.rb → testunit-test-util.rb} +4 -2
- data/test-unit/test/ui/test_testrunmediator.rb +1 -1
- data/test-unit/test/util/test-method-owner-finder.rb +38 -0
- data/test/run-test.rb +0 -0
- data/test/test_adapter.rb +3 -0
- data/test/test_associations.rb +50 -7
- data/test/test_base.rb +193 -11
- data/test/test_connection_per_dn.rb +1 -1
- data/test/test_ldif.rb +86 -0
- data/test/test_load.rb +7 -0
- data/test/test_schema.rb +31 -1
- data/test/test_syntax.rb +20 -0
- data/test/test_user_password.rb +22 -14
- data/test/test_validation.rb +70 -29
- metadata +99 -77
- data/data/locale/en/LC_MESSAGES/active-ldap.mo +0 -0
- data/data/locale/ja/LC_MESSAGES/active-ldap.mo +0 -0
- data/examples/al-admin/config/initializers/ralative_url_support.rb +0 -1
- data/examples/al-admin/lib/accept_http_rails_relative_url_root.rb +0 -9
- data/test-unit-ext/misc/rd2html.rb +0 -42
- data/test-unit/test/test_fixture.rb +0 -275
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'test/unit'
|
2
|
-
require '
|
2
|
+
require 'testunit-test-util'
|
3
3
|
|
4
4
|
class TestUnitOmission < Test::Unit::TestCase
|
5
5
|
include TestUnitTestUtil
|
@@ -43,7 +43,7 @@ class TestUnitOmission < Test::Unit::TestCase
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def test_omit
|
46
|
-
result =
|
46
|
+
result = _run_test("test_omit")
|
47
47
|
assert_equal("1 tests, 0 assertions, 0 failures, 0 errors, 0 pendings, " \
|
48
48
|
"1 omissions, 0 notifications",
|
49
49
|
result.to_s)
|
@@ -51,7 +51,7 @@ class TestUnitOmission < Test::Unit::TestCase
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def test_omit_with_condition
|
54
|
-
result =
|
54
|
+
result = _run_test("test_omit_with_condition")
|
55
55
|
assert_equal("1 tests, 0 assertions, 0 failures, 0 errors, 0 pendings, " \
|
56
56
|
"1 omissions, 0 notifications",
|
57
57
|
result.to_s)
|
@@ -59,7 +59,7 @@ class TestUnitOmission < Test::Unit::TestCase
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def test_omit_with_block
|
62
|
-
result =
|
62
|
+
result = _run_test("test_omit_with_block")
|
63
63
|
assert_equal("1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, " \
|
64
64
|
"1 omissions, 0 notifications",
|
65
65
|
result.to_s)
|
@@ -67,7 +67,7 @@ class TestUnitOmission < Test::Unit::TestCase
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def test_omit_with_condition_and_block
|
70
|
-
result =
|
70
|
+
result = _run_test("test_omit_with_block_and_condition")
|
71
71
|
assert_equal("1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, " \
|
72
72
|
"1 omissions, 0 notifications",
|
73
73
|
result.to_s)
|
@@ -75,7 +75,7 @@ class TestUnitOmission < Test::Unit::TestCase
|
|
75
75
|
end
|
76
76
|
|
77
77
|
private
|
78
|
-
def
|
78
|
+
def _run_test(name)
|
79
79
|
super(TestCase, name)
|
80
80
|
end
|
81
81
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'test/unit'
|
2
|
-
require '
|
2
|
+
require 'testunit-test-util'
|
3
3
|
|
4
4
|
class TestUnitPending < Test::Unit::TestCase
|
5
5
|
include TestUnitTestUtil
|
@@ -33,32 +33,38 @@ class TestUnitPending < Test::Unit::TestCase
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_pend
|
36
|
-
|
36
|
+
test = nil
|
37
|
+
result = _run_test("test_pend") {|t| test = t}
|
37
38
|
assert_equal("1 tests, 0 assertions, 0 failures, 0 errors, 1 pendings, " \
|
38
39
|
"0 omissions, 0 notifications",
|
39
40
|
result.to_s)
|
40
41
|
assert_fault_messages(["1st pend"], result.pendings)
|
42
|
+
assert_true(test.interrupted?)
|
41
43
|
end
|
42
44
|
|
43
45
|
def test_pend_with_failure_in_block
|
44
|
-
|
46
|
+
test = nil
|
47
|
+
result = _run_test("test_pend_with_failure_in_block") {|t| test = t}
|
45
48
|
assert_equal("1 tests, 1 assertions, 0 failures, 0 errors, 1 pendings, " \
|
46
49
|
"0 omissions, 0 notifications",
|
47
50
|
result.to_s)
|
48
51
|
assert_fault_messages(["Wait a minute"], result.pendings)
|
52
|
+
assert_false(test.interrupted?)
|
49
53
|
end
|
50
54
|
|
51
55
|
def test_pend_with_no_failure_in_block
|
52
|
-
|
56
|
+
test = nil
|
57
|
+
result = _run_test("test_pend_with_no_failure_in_block") {|t| test = t}
|
53
58
|
assert_equal("1 tests, 1 assertions, 1 failures, 0 errors, 0 pendings, " \
|
54
59
|
"0 omissions, 0 notifications",
|
55
60
|
result.to_s)
|
56
61
|
assert_fault_messages(["Pending block should not be passed: Wait a minute."],
|
57
62
|
result.failures)
|
63
|
+
assert_true(test.interrupted?)
|
58
64
|
end
|
59
65
|
|
60
66
|
private
|
61
|
-
def
|
62
|
-
super(TestCase, name)
|
67
|
+
def _run_test(name, &block)
|
68
|
+
super(TestCase, name, &block)
|
63
69
|
end
|
64
70
|
end
|
@@ -86,4 +86,34 @@ class TestUnitPriority < Test::Unit::TestCase
|
|
86
86
|
end
|
87
87
|
assert_in_delta(expected, n_need_to_run.to_f / n, delta)
|
88
88
|
end
|
89
|
+
|
90
|
+
class SpecialNameTestCase < Test::Unit::TestCase
|
91
|
+
class << self
|
92
|
+
def suite
|
93
|
+
Test::Unit::TestSuite.new(name)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_question?
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_exclamation!
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_equal=
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_escaped?
|
108
|
+
assert_escaped_name("test_question.predicate", "test_question?")
|
109
|
+
assert_escaped_name("test_exclamation.destructive", "test_exclamation!")
|
110
|
+
assert_escaped_name("test_equal.equal", "test_equal=")
|
111
|
+
end
|
112
|
+
|
113
|
+
def assert_escaped_name(expected, test_method_name)
|
114
|
+
checker = Checker.new(SpecialNameTestCase.new(test_method_name))
|
115
|
+
passed_file = checker.send(:passed_file)
|
116
|
+
method_name_component = File.basename(File.dirname(passed_file))
|
117
|
+
assert_equal(expected, method_name_component)
|
118
|
+
end
|
89
119
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# Author:: Nathaniel Talbott.
|
2
2
|
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
3
|
+
# Copyright (c) 2009 Kouhei Sutou.
|
3
4
|
# License:: Ruby license.
|
4
5
|
|
5
6
|
require 'test/unit'
|
@@ -7,6 +8,10 @@ require 'test/unit'
|
|
7
8
|
module Test
|
8
9
|
module Unit
|
9
10
|
class TC_Assertions < TestCase
|
11
|
+
backtrace_pre = "---Backtrace---"
|
12
|
+
backtrace_post = "---------------"
|
13
|
+
BACKTRACE_RE = /#{backtrace_pre}\n.+\n#{backtrace_post}/m
|
14
|
+
|
10
15
|
def check(value, message="")
|
11
16
|
add_assertion
|
12
17
|
raise AssertionFailedError.new(message) unless value
|
@@ -116,9 +121,6 @@ module Test
|
|
116
121
|
check_nothing_fails {
|
117
122
|
assert_equal("string1", "string1")
|
118
123
|
}
|
119
|
-
check_nothing_fails {
|
120
|
-
assert_equal( "string1", "string1", "successful assert_equal")
|
121
|
-
}
|
122
124
|
check_nothing_fails {
|
123
125
|
assert_equal("string1", "string1", "successful assert_equal")
|
124
126
|
}
|
@@ -166,6 +168,47 @@ EOM
|
|
166
168
|
end
|
167
169
|
end
|
168
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
|
+
|
169
212
|
def test_assert_equal_for_too_small_difference
|
170
213
|
message = <<-EOM.chomp
|
171
214
|
<1> expected but was
|
@@ -203,85 +246,191 @@ EOM
|
|
203
246
|
end
|
204
247
|
end
|
205
248
|
|
206
|
-
def
|
249
|
+
def test_assert_raise_success
|
207
250
|
return_value = nil
|
208
|
-
check_nothing_fails(true)
|
209
|
-
return_value = assert_raise(RuntimeError)
|
251
|
+
check_nothing_fails(true) do
|
252
|
+
return_value = assert_raise(RuntimeError) do
|
210
253
|
raise "Error"
|
211
|
-
|
212
|
-
|
213
|
-
check(return_value.kind_of?(Exception),
|
214
|
-
|
215
|
-
|
216
|
-
|
254
|
+
end
|
255
|
+
end
|
256
|
+
check(return_value.kind_of?(Exception),
|
257
|
+
"Should have returned the exception " +
|
258
|
+
"from a successful assert_raise")
|
259
|
+
check(return_value.message == "Error",
|
260
|
+
"Should have returned the correct exception " +
|
261
|
+
"from a successful assert_raise")
|
262
|
+
|
263
|
+
check_nothing_fails(true) do
|
264
|
+
assert_raise(ArgumentError, "successful assert_raise") do
|
217
265
|
raise ArgumentError.new("Error")
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
check_nothing_fails(true) do
|
270
|
+
assert_raise(RuntimeError) do
|
222
271
|
raise "Error"
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
check_nothing_fails(true) do
|
276
|
+
assert_raise(RuntimeError, "successful assert_raise") do
|
227
277
|
raise "Error"
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
check_nothing_fails(true) do
|
282
|
+
assert_raise do
|
283
|
+
raise Exception, "Any exception"
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
def test_assert_raise_fail
|
289
|
+
check_fails("<RuntimeError> exception expected but none was thrown.") do
|
290
|
+
assert_raise(RuntimeError) do
|
232
291
|
1 + 1
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
message = <<-EOM
|
296
|
+
failed assert_raise.
|
297
|
+
<ArgumentError> exception expected but was
|
298
|
+
Class: <RuntimeError>
|
299
|
+
Message: <"Error">
|
300
|
+
EOM
|
301
|
+
check_fails(/\A#{message}#{BACKTRACE_RE}\Z/m) do
|
302
|
+
assert_raise(ArgumentError, "failed assert_raise") do
|
237
303
|
raise "Error"
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
message = <<-EOM
|
308
|
+
Should expect a class of exception, Object.
|
309
|
+
<false> is not true.
|
310
|
+
EOM
|
311
|
+
check_fails(message.chomp) do
|
312
|
+
assert_nothing_raised(Object) do
|
242
313
|
1 + 1
|
243
|
-
|
244
|
-
|
314
|
+
end
|
315
|
+
end
|
316
|
+
end
|
245
317
|
|
318
|
+
def test_assert_raise_module
|
246
319
|
exceptions = [ArgumentError, TypeError]
|
247
320
|
modules = [Math, Comparable]
|
248
321
|
rescues = exceptions + modules
|
322
|
+
|
249
323
|
exceptions.each do |exc|
|
250
|
-
|
251
|
-
|
324
|
+
return_value = nil
|
325
|
+
check_nothing_fails(true) do
|
326
|
+
return_value = assert_raise(*rescues) do
|
252
327
|
raise exc, "Error"
|
253
|
-
|
254
|
-
|
255
|
-
check(return_value.instance_of?(exc),
|
256
|
-
|
328
|
+
end
|
329
|
+
end
|
330
|
+
check(return_value.instance_of?(exc),
|
331
|
+
"Should have returned #{exc} but was #{return_value.class}")
|
332
|
+
check(return_value.message == "Error",
|
333
|
+
"Should have returned the correct exception " +
|
334
|
+
"from a successful assert_raise")
|
257
335
|
end
|
336
|
+
|
258
337
|
modules.each do |mod|
|
259
|
-
|
260
|
-
|
338
|
+
return_value = nil
|
339
|
+
check_nothing_fails(true) do
|
340
|
+
return_value = assert_raise(*rescues) do
|
261
341
|
raise Exception.new("Error").extend(mod)
|
262
|
-
|
263
|
-
|
264
|
-
check(mod === return_value,
|
265
|
-
|
342
|
+
end
|
343
|
+
end
|
344
|
+
check(mod === return_value,
|
345
|
+
"Should have returned #{mod}")
|
346
|
+
check(return_value.message == "Error",
|
347
|
+
"Should have returned the correct exception " +
|
348
|
+
"from a successful assert_raise")
|
266
349
|
end
|
267
|
-
|
268
|
-
|
350
|
+
|
351
|
+
check_fails("<[ArgumentError, TypeError, Math, Comparable]> exception " +
|
352
|
+
"expected but none was thrown.") do
|
353
|
+
assert_raise(*rescues) do
|
269
354
|
1 + 1
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
message = <<-EOM
|
359
|
+
failed assert_raise.
|
360
|
+
<[ArgumentError, TypeError]> exception expected but was
|
274
361
|
Class: <RuntimeError>
|
275
362
|
Message: <"Error">
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
assert_raise(ArgumentError, TypeError, "failed assert_raise")
|
363
|
+
EOM
|
364
|
+
message = Regexp.escape(message)
|
365
|
+
check_fails(/\A#{message}#{BACKTRACE_RE}\z/m) do
|
366
|
+
assert_raise(ArgumentError, TypeError, "failed assert_raise") do
|
280
367
|
raise "Error"
|
281
|
-
|
282
|
-
|
368
|
+
end
|
369
|
+
end
|
283
370
|
end
|
284
|
-
|
371
|
+
|
372
|
+
def test_assert_raise_instance
|
373
|
+
return_value = nil
|
374
|
+
check_nothing_fails(true) do
|
375
|
+
return_value = assert_raise(RuntimeError.new("Error")) do
|
376
|
+
raise "Error"
|
377
|
+
end
|
378
|
+
end
|
379
|
+
check(return_value.kind_of?(Exception),
|
380
|
+
"Should have returned the exception " +
|
381
|
+
"from a successful assert_raise")
|
382
|
+
check(return_value.message == "Error",
|
383
|
+
"Should have returned the correct exception " +
|
384
|
+
"from a successful assert_raise")
|
385
|
+
|
386
|
+
message = <<-EOM
|
387
|
+
<RuntimeError("XXX")> exception expected but was
|
388
|
+
Class: <RuntimeError>
|
389
|
+
Message: <"Error">
|
390
|
+
EOM
|
391
|
+
message = Regexp.escape(message)
|
392
|
+
check_fails(/\A#{message}#{BACKTRACE_RE}\z/) do
|
393
|
+
return_value = assert_raise(RuntimeError.new("XXX")) do
|
394
|
+
raise "Error"
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
different_error_class = Class.new(StandardError)
|
399
|
+
message = <<-EOM
|
400
|
+
<\#<Class:0x[a-f\\d]+>\\("Error"\\)> exception expected but was
|
401
|
+
Class: <RuntimeError>
|
402
|
+
Message: <"Error">
|
403
|
+
EOM
|
404
|
+
check_fails(/\A#{message}#{BACKTRACE_RE}\z/) do
|
405
|
+
assert_raise(different_error_class.new("Error")) do
|
406
|
+
raise "Error"
|
407
|
+
end
|
408
|
+
end
|
409
|
+
|
410
|
+
different_error = different_error_class.new("Error")
|
411
|
+
def different_error.inspect
|
412
|
+
"DifferentError: \"Error\""
|
413
|
+
end
|
414
|
+
message = <<-EOM
|
415
|
+
<\DifferentError: \\"Error\\"> exception expected but was
|
416
|
+
Class: <RuntimeError>
|
417
|
+
Message: <"Error">
|
418
|
+
EOM
|
419
|
+
check_fails(/\A#{message}#{BACKTRACE_RE}\z/) do
|
420
|
+
assert_raise(different_error) do
|
421
|
+
raise "Error"
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
check_nothing_fails(true) do
|
426
|
+
assert_raise(different_error_class.new("Error"),
|
427
|
+
RuntimeError.new("Error"),
|
428
|
+
RuntimeError.new("XXX")) do
|
429
|
+
raise "Error"
|
430
|
+
end
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
285
434
|
def test_assert_instance_of
|
286
435
|
check_nothing_fails {
|
287
436
|
assert_instance_of(String, "string")
|
@@ -496,9 +645,9 @@ Message: <"Error">
|
|
496
645
|
end
|
497
646
|
end
|
498
647
|
|
499
|
-
def
|
648
|
+
def test_assert_throw
|
500
649
|
check_nothing_fails do
|
501
|
-
|
650
|
+
assert_throw(:thing, "message") do
|
502
651
|
throw :thing
|
503
652
|
end
|
504
653
|
end
|
@@ -507,13 +656,13 @@ Message: <"Error">
|
|
507
656
|
check_fails("message.\n" +
|
508
657
|
"<:thing> expected to be thrown but\n" +
|
509
658
|
"<#{inspect_tag(tag)}> was thrown.") do
|
510
|
-
|
659
|
+
assert_throw(:thing, "message") do
|
511
660
|
throw :thing2
|
512
661
|
end
|
513
662
|
end
|
514
663
|
check_fails("message.\n" +
|
515
664
|
"<:thing> should have been thrown.") do
|
516
|
-
|
665
|
+
assert_throw(:thing, "message") do
|
517
666
|
1 + 1
|
518
667
|
end
|
519
668
|
end
|
@@ -555,10 +704,13 @@ Message: <"Error">
|
|
555
704
|
check_nothing_fails {
|
556
705
|
assert_respond_to("thing", "to_s", "message")
|
557
706
|
}
|
558
|
-
check_fails("<0.15
|
707
|
+
check_fails("<0.15>.kind_of?(Symbol) or\n" +
|
708
|
+
"<0.15>.respond_to?(:to_str) expected") {
|
559
709
|
assert_respond_to("thing", 0.15)
|
560
710
|
}
|
561
|
-
check_fails("message.\n
|
711
|
+
check_fails("message.\n" +
|
712
|
+
"<:symbol>.respond_to?(:non_existent) expected\n" +
|
713
|
+
"(Class: <Symbol>)") {
|
562
714
|
assert_respond_to(:symbol, :non_existent, "message")
|
563
715
|
}
|
564
716
|
end
|
@@ -580,10 +732,15 @@ Message: <"Error">
|
|
580
732
|
check_fails("message.\n<0.5> and\n<0.4> expected to be within\n<0.05> of each other.") {
|
581
733
|
assert_in_delta(0.5, 0.4, 0.05, "message")
|
582
734
|
}
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
735
|
+
object = Object.new
|
736
|
+
check_fails("The arguments must respond to to_f; " +
|
737
|
+
"the first float did not.\n" +
|
738
|
+
"<#{object.inspect}>.respond_to?(:to_f) expected\n" +
|
739
|
+
"(Class: <Object>)") {
|
740
|
+
assert_in_delta(object, 0.4, 0.1)
|
741
|
+
}
|
742
|
+
check_fails("The delta should not be negative.\n" +
|
743
|
+
"<-0.1> expected to be\n>=\n<0.0>.") {
|
587
744
|
assert_in_delta(0.5, 0.4, -0.1, "message")
|
588
745
|
}
|
589
746
|
end
|
@@ -675,6 +832,190 @@ Message: <"Error">
|
|
675
832
|
end
|
676
833
|
end
|
677
834
|
|
835
|
+
def test_assert_compare
|
836
|
+
check_nothing_fails do
|
837
|
+
assert_compare(1.4, "<", 10.0)
|
838
|
+
end
|
839
|
+
|
840
|
+
check_nothing_fails do
|
841
|
+
assert_compare(2, "<=", 2)
|
842
|
+
end
|
843
|
+
|
844
|
+
check_nothing_fails do
|
845
|
+
assert_compare(14, ">=", 10.0)
|
846
|
+
end
|
847
|
+
|
848
|
+
check_nothing_fails do
|
849
|
+
assert_compare(14, ">", 13.9)
|
850
|
+
end
|
851
|
+
|
852
|
+
expected_message = <<-EOM
|
853
|
+
<15> < <10> should be true
|
854
|
+
<15> expected less than
|
855
|
+
<10>.
|
856
|
+
EOM
|
857
|
+
check_fails(expected_message.chomp) do
|
858
|
+
assert_compare(15, "<", 10)
|
859
|
+
end
|
860
|
+
|
861
|
+
expected_message = <<-EOM
|
862
|
+
<15> <= <10> should be true
|
863
|
+
<15> expected less than or equal to
|
864
|
+
<10>.
|
865
|
+
EOM
|
866
|
+
check_fails(expected_message.chomp) do
|
867
|
+
assert_compare(15, "<=", 10)
|
868
|
+
end
|
869
|
+
|
870
|
+
expected_message = <<-EOM
|
871
|
+
<10> > <15> should be true
|
872
|
+
<10> expected greater than
|
873
|
+
<15>.
|
874
|
+
EOM
|
875
|
+
check_fails(expected_message.chomp) do
|
876
|
+
assert_compare(10, ">", 15)
|
877
|
+
end
|
878
|
+
|
879
|
+
expected_message = <<-EOM
|
880
|
+
<10> >= <15> should be true
|
881
|
+
<10> expected greater than or equal to
|
882
|
+
<15>.
|
883
|
+
EOM
|
884
|
+
check_fails(expected_message.chomp) do
|
885
|
+
assert_compare(10, ">=", 15)
|
886
|
+
end
|
887
|
+
end
|
888
|
+
|
889
|
+
def test_assert_fail_assertion
|
890
|
+
check_nothing_fails do
|
891
|
+
assert_fail_assertion do
|
892
|
+
flunk
|
893
|
+
end
|
894
|
+
end
|
895
|
+
|
896
|
+
check_fails("Failed assertion was expected.") do
|
897
|
+
assert_fail_assertion do
|
898
|
+
end
|
899
|
+
end
|
900
|
+
end
|
901
|
+
|
902
|
+
def test_assert_raise_message
|
903
|
+
check_nothing_fails do
|
904
|
+
assert_raise_message("Raise!") do
|
905
|
+
raise "Raise!"
|
906
|
+
end
|
907
|
+
end
|
908
|
+
|
909
|
+
check_nothing_fails do
|
910
|
+
assert_raise_message("Raise!") do
|
911
|
+
raise Exception, "Raise!"
|
912
|
+
end
|
913
|
+
end
|
914
|
+
|
915
|
+
check_nothing_fails do
|
916
|
+
assert_raise_message(/raise/i) do
|
917
|
+
raise "Raise!"
|
918
|
+
end
|
919
|
+
end
|
920
|
+
|
921
|
+
expected_message = <<-EOM
|
922
|
+
<"Expected message"> exception message expected but was
|
923
|
+
<"Actual message">.
|
924
|
+
EOM
|
925
|
+
check_fails(expected_message.chomp) do
|
926
|
+
assert_raise_message("Expected message") do
|
927
|
+
raise "Actual message"
|
928
|
+
end
|
929
|
+
end
|
930
|
+
|
931
|
+
expected_message = <<-EOM
|
932
|
+
<"Expected message"> exception message expected but none was thrown.
|
933
|
+
EOM
|
934
|
+
check_fails(expected_message.chomp) do
|
935
|
+
assert_raise_message("Expected message") do
|
936
|
+
end
|
937
|
+
end
|
938
|
+
end
|
939
|
+
|
940
|
+
def test_assert_raise_kind_of
|
941
|
+
check_nothing_fails(true) do
|
942
|
+
assert_raise_kind_of(SystemCallError) do
|
943
|
+
raise Errno::EACCES
|
944
|
+
end
|
945
|
+
end
|
946
|
+
|
947
|
+
expected_message = <<-EOM
|
948
|
+
<SystemCallError> family exception expected but was
|
949
|
+
Class: <RuntimeError>
|
950
|
+
Message: <"XXX">
|
951
|
+
---Backtrace---
|
952
|
+
EOM
|
953
|
+
check_fails(/\A#{Regexp.escape(expected_message)}(?m).+\z/) do
|
954
|
+
assert_raise_kind_of(SystemCallError) do
|
955
|
+
raise RuntimeError, "XXX"
|
956
|
+
end
|
957
|
+
end
|
958
|
+
end
|
959
|
+
|
960
|
+
def test_assert_const_defined
|
961
|
+
check_nothing_fails do
|
962
|
+
assert_const_defined(Test, :Unit)
|
963
|
+
end
|
964
|
+
|
965
|
+
check_nothing_fails do
|
966
|
+
assert_const_defined(Test, "Unit")
|
967
|
+
end
|
968
|
+
|
969
|
+
check_fails("<Test>.const_defined?(<:Nonexistence>) expected.") do
|
970
|
+
assert_const_defined(Test, :Nonexistence)
|
971
|
+
end
|
972
|
+
end
|
973
|
+
|
974
|
+
def test_assert_not_const_defined
|
975
|
+
check_nothing_fails do
|
976
|
+
assert_not_const_defined(Test, :Nonexistence)
|
977
|
+
end
|
978
|
+
|
979
|
+
check_fails("!<Test>.const_defined?(<:Unit>) expected.") do
|
980
|
+
assert_not_const_defined(Test, :Unit)
|
981
|
+
end
|
982
|
+
|
983
|
+
check_fails("!<Test>.const_defined?(<\"Unit\">) expected.") do
|
984
|
+
assert_not_const_defined(Test, "Unit")
|
985
|
+
end
|
986
|
+
end
|
987
|
+
|
988
|
+
def test_assert_predicate
|
989
|
+
check_nothing_fails do
|
990
|
+
assert_predicate([], :empty?)
|
991
|
+
end
|
992
|
+
|
993
|
+
check_fails("<[1]>.empty? is true value expected but was\n<false>") do
|
994
|
+
assert_predicate([1], :empty?)
|
995
|
+
end
|
996
|
+
|
997
|
+
check_fails("<[1]>.respond_to?(:nonexistent?) expected\n" +
|
998
|
+
"(Class: <Array>)") do
|
999
|
+
assert_predicate([1], :nonexistent?)
|
1000
|
+
end
|
1001
|
+
end
|
1002
|
+
|
1003
|
+
def test_assert_not_predicate
|
1004
|
+
check_nothing_fails do
|
1005
|
+
assert_not_predicate([1], :empty?)
|
1006
|
+
end
|
1007
|
+
|
1008
|
+
check_fails("<[]>.empty? is false value expected but was\n<true>") do
|
1009
|
+
assert_not_predicate([], :empty?)
|
1010
|
+
end
|
1011
|
+
|
1012
|
+
check_fails("<[]>.respond_to?(:nonexistent?) expected\n" +
|
1013
|
+
"(Class: <Array>)") do
|
1014
|
+
assert_not_predicate([], :nonexistent?)
|
1015
|
+
end
|
1016
|
+
end
|
1017
|
+
|
1018
|
+
private
|
678
1019
|
def add_failure(message, location=caller)
|
679
1020
|
unless @catch_assertions
|
680
1021
|
super
|
@@ -691,3 +1032,4 @@ Message: <"Error">
|
|
691
1032
|
end
|
692
1033
|
end
|
693
1034
|
end
|
1035
|
+
p
|