activesambaldap 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. data/Gemfile +21 -0
  2. data/NEWS.en +1 -1
  3. data/NEWS.ja +1 -1
  4. data/README.en +12 -8
  5. data/README.ja +6 -3
  6. data/Rakefile +27 -121
  7. data/lib/active_samba_ldap.rb +1 -1
  8. data/lib/active_samba_ldap/get_text_support.rb +1 -1
  9. data/lib/active_samba_ldap/version.rb +1 -1
  10. data/license/lgpl-2.1.txt +165 -0
  11. data/po/ja/active-samba-ldap.po +2 -2
  12. data/test/run-test.rb +3 -3
  13. metadata +145 -277
  14. data/bin/asl-groupadd.help +0 -16
  15. data/bin/asl-groupdel.help +0 -13
  16. data/bin/asl-groupmod.help +0 -19
  17. data/bin/asl-groupshow.help +0 -11
  18. data/bin/asl-passwd.help +0 -15
  19. data/bin/asl-populate.help +0 -28
  20. data/bin/asl-purge.help +0 -11
  21. data/bin/asl-samba-computeradd.help +0 -13
  22. data/bin/asl-samba-groupadd.help +0 -11
  23. data/bin/asl-samba-groupdel.help +0 -11
  24. data/bin/asl-samba-groupmod.help +0 -15
  25. data/bin/asl-samba-useradd.help +0 -13
  26. data/bin/asl-samba-userdel.help +0 -11
  27. data/bin/asl-samba-usermod.help +0 -15
  28. data/bin/asl-useradd.help +0 -49
  29. data/bin/asl-userdel.help +0 -18
  30. data/bin/asl-usermod.help +0 -47
  31. data/bin/asl-usershow.help +0 -11
  32. data/data/locale/ja/LC_MESSAGES/active-samba-ldap.mo +0 -0
  33. data/example/asl-admin/README +0 -243
  34. data/example/asl-admin/Rakefile +0 -10
  35. data/example/asl-admin/app/controllers/application_controller.rb +0 -10
  36. data/example/asl-admin/app/controllers/samba_controller.rb +0 -12
  37. data/example/asl-admin/app/helpers/application_helper.rb +0 -3
  38. data/example/asl-admin/app/helpers/samba_helper.rb +0 -2
  39. data/example/asl-admin/app/models/computer.rb +0 -3
  40. data/example/asl-admin/app/models/dc.rb +0 -3
  41. data/example/asl-admin/app/models/group.rb +0 -3
  42. data/example/asl-admin/app/models/idmap.rb +0 -3
  43. data/example/asl-admin/app/models/ou.rb +0 -3
  44. data/example/asl-admin/app/models/unix_id_pool.rb +0 -3
  45. data/example/asl-admin/app/models/user.rb +0 -3
  46. data/example/asl-admin/app/views/samba/index.html.erb +0 -17
  47. data/example/asl-admin/app/views/samba/populate.html.erb +0 -15
  48. data/example/asl-admin/app/views/samba/purge.html.erb +0 -10
  49. data/example/asl-admin/config/boot.rb +0 -110
  50. data/example/asl-admin/config/database.yml +0 -22
  51. data/example/asl-admin/config/environment.rb +0 -48
  52. data/example/asl-admin/config/environments/development.rb +0 -17
  53. data/example/asl-admin/config/environments/production.rb +0 -28
  54. data/example/asl-admin/config/environments/test.rb +0 -28
  55. data/example/asl-admin/config/initializers/backtrace_silencers.rb +0 -7
  56. data/example/asl-admin/config/initializers/inflections.rb +0 -10
  57. data/example/asl-admin/config/initializers/mime_types.rb +0 -5
  58. data/example/asl-admin/config/initializers/new_rails_defaults.rb +0 -19
  59. data/example/asl-admin/config/initializers/session_store.rb +0 -15
  60. data/example/asl-admin/config/ldap.yml.sample +0 -24
  61. data/example/asl-admin/config/locales/en.yml +0 -5
  62. data/example/asl-admin/config/routes.rb +0 -43
  63. data/example/asl-admin/log/test.log +0 -5
  64. data/example/asl-admin/public/404.html +0 -30
  65. data/example/asl-admin/public/422.html +0 -30
  66. data/example/asl-admin/public/500.html +0 -30
  67. data/example/asl-admin/public/favicon.ico +0 -0
  68. data/example/asl-admin/public/images/rails.png +0 -0
  69. data/example/asl-admin/public/index.html +0 -275
  70. data/example/asl-admin/public/javascripts/application.js +0 -2
  71. data/example/asl-admin/public/javascripts/controls.js +0 -963
  72. data/example/asl-admin/public/javascripts/dragdrop.js +0 -973
  73. data/example/asl-admin/public/javascripts/effects.js +0 -1128
  74. data/example/asl-admin/public/javascripts/prototype.js +0 -4320
  75. data/example/asl-admin/public/robots.txt +0 -5
  76. data/example/asl-admin/script/about +0 -4
  77. data/example/asl-admin/script/console +0 -3
  78. data/example/asl-admin/script/dbconsole +0 -3
  79. data/example/asl-admin/script/destroy +0 -3
  80. data/example/asl-admin/script/generate +0 -3
  81. data/example/asl-admin/script/performance/benchmarker +0 -3
  82. data/example/asl-admin/script/performance/profiler +0 -3
  83. data/example/asl-admin/script/plugin +0 -3
  84. data/example/asl-admin/script/runner +0 -3
  85. data/example/asl-admin/script/server +0 -3
  86. data/example/asl-admin/test/performance/browsing_test.rb +0 -9
  87. data/example/asl-admin/test/test_helper.rb +0 -38
  88. data/po/active-samba-ldap.pot +0 -463
  89. data/rails_generators/scaffold_active_samba_ldap/scaffold_active_samba_ldap_generator.rb +0 -28
  90. data/rails_generators/scaffold_active_samba_ldap/templates/computer.rb +0 -3
  91. data/rails_generators/scaffold_active_samba_ldap/templates/dc.rb +0 -3
  92. data/rails_generators/scaffold_active_samba_ldap/templates/group.rb +0 -3
  93. data/rails_generators/scaffold_active_samba_ldap/templates/idmap.rb +0 -3
  94. data/rails_generators/scaffold_active_samba_ldap/templates/ldap.yml +0 -24
  95. data/rails_generators/scaffold_active_samba_ldap/templates/ou.rb +0 -3
  96. data/rails_generators/scaffold_active_samba_ldap/templates/samba_controller.rb +0 -12
  97. data/rails_generators/scaffold_active_samba_ldap/templates/samba_helper.rb +0 -2
  98. data/rails_generators/scaffold_active_samba_ldap/templates/samba_index.html.erb +0 -17
  99. data/rails_generators/scaffold_active_samba_ldap/templates/samba_populate.html.erb +0 -15
  100. data/rails_generators/scaffold_active_samba_ldap/templates/samba_purge.html.erb +0 -10
  101. data/rails_generators/scaffold_active_samba_ldap/templates/unix_id_pool.rb +0 -3
  102. data/rails_generators/scaffold_active_samba_ldap/templates/user.rb +0 -3
  103. data/setup.rb +0 -1585
  104. data/test-unit/History.txt +0 -107
  105. data/test-unit/README.txt +0 -52
  106. data/test-unit/Rakefile +0 -40
  107. data/test-unit/TODO +0 -5
  108. data/test-unit/bin/testrb +0 -5
  109. data/test-unit/lib/test/unit.rb +0 -342
  110. data/test-unit/lib/test/unit/assertionfailederror.rb +0 -14
  111. data/test-unit/lib/test/unit/assertions.rb +0 -1149
  112. data/test-unit/lib/test/unit/attribute.rb +0 -125
  113. data/test-unit/lib/test/unit/autorunner.rb +0 -344
  114. data/test-unit/lib/test/unit/collector.rb +0 -43
  115. data/test-unit/lib/test/unit/collector/descendant.rb +0 -23
  116. data/test-unit/lib/test/unit/collector/dir.rb +0 -108
  117. data/test-unit/lib/test/unit/collector/load.rb +0 -137
  118. data/test-unit/lib/test/unit/collector/objectspace.rb +0 -34
  119. data/test-unit/lib/test/unit/color-scheme.rb +0 -90
  120. data/test-unit/lib/test/unit/color.rb +0 -96
  121. data/test-unit/lib/test/unit/diff.rb +0 -538
  122. data/test-unit/lib/test/unit/error.rb +0 -126
  123. data/test-unit/lib/test/unit/exceptionhandler.rb +0 -39
  124. data/test-unit/lib/test/unit/failure.rb +0 -110
  125. data/test-unit/lib/test/unit/fixture.rb +0 -176
  126. data/test-unit/lib/test/unit/notification.rb +0 -125
  127. data/test-unit/lib/test/unit/omission.rb +0 -143
  128. data/test-unit/lib/test/unit/pending.rb +0 -146
  129. data/test-unit/lib/test/unit/priority.rb +0 -181
  130. data/test-unit/lib/test/unit/runner/console.rb +0 -52
  131. data/test-unit/lib/test/unit/runner/emacs.rb +0 -8
  132. data/test-unit/lib/test/unit/runner/tap.rb +0 -8
  133. data/test-unit/lib/test/unit/testcase.rb +0 -425
  134. data/test-unit/lib/test/unit/testresult.rb +0 -89
  135. data/test-unit/lib/test/unit/testsuite.rb +0 -110
  136. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +0 -14
  137. data/test-unit/lib/test/unit/ui/console/testrunner.rb +0 -278
  138. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +0 -49
  139. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +0 -92
  140. data/test-unit/lib/test/unit/ui/testrunner.rb +0 -20
  141. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +0 -77
  142. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +0 -41
  143. data/test-unit/lib/test/unit/util/backtracefilter.rb +0 -41
  144. data/test-unit/lib/test/unit/util/method-owner-finder.rb +0 -28
  145. data/test-unit/lib/test/unit/util/observable.rb +0 -90
  146. data/test-unit/lib/test/unit/util/procwrapper.rb +0 -48
  147. data/test-unit/lib/test/unit/version.rb +0 -7
  148. data/test-unit/sample/adder.rb +0 -13
  149. data/test-unit/sample/subtracter.rb +0 -12
  150. data/test-unit/sample/tc_adder.rb +0 -18
  151. data/test-unit/sample/tc_subtracter.rb +0 -18
  152. data/test-unit/sample/test_user.rb +0 -22
  153. data/test-unit/sample/ts_examples.rb +0 -7
  154. data/test-unit/test/collector/test-descendant.rb +0 -135
  155. data/test-unit/test/collector/test-load.rb +0 -329
  156. data/test-unit/test/collector/test_dir.rb +0 -406
  157. data/test-unit/test/collector/test_objectspace.rb +0 -98
  158. data/test-unit/test/run-test.rb +0 -13
  159. data/test-unit/test/test-attribute.rb +0 -86
  160. data/test-unit/test/test-color-scheme.rb +0 -60
  161. data/test-unit/test/test-color.rb +0 -47
  162. data/test-unit/test/test-diff.rb +0 -477
  163. data/test-unit/test/test-emacs-runner.rb +0 -60
  164. data/test-unit/test/test-fixture.rb +0 -287
  165. data/test-unit/test/test-notification.rb +0 -33
  166. data/test-unit/test/test-omission.rb +0 -81
  167. data/test-unit/test/test-pending.rb +0 -70
  168. data/test-unit/test/test-priority.rb +0 -119
  169. data/test-unit/test/test-testcase.rb +0 -507
  170. data/test-unit/test/test_assertions.rb +0 -1082
  171. data/test-unit/test/test_error.rb +0 -26
  172. data/test-unit/test/test_failure.rb +0 -33
  173. data/test-unit/test/test_testresult.rb +0 -113
  174. data/test-unit/test/test_testsuite.rb +0 -129
  175. data/test-unit/test/testunit-test-util.rb +0 -14
  176. data/test-unit/test/ui/test_testrunmediator.rb +0 -20
  177. data/test-unit/test/util/test-method-owner-finder.rb +0 -38
  178. data/test-unit/test/util/test_backtracefilter.rb +0 -41
  179. data/test-unit/test/util/test_observable.rb +0 -102
  180. data/test-unit/test/util/test_procwrapper.rb +0 -36
@@ -1,14 +0,0 @@
1
- #--
2
- #
3
- # Author:: Nathaniel Talbott.
4
- # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
5
- # License:: Ruby license.
6
-
7
- module Test
8
- module Unit
9
-
10
- # Thrown by Test::Unit::Assertions when an assertion fails.
11
- class AssertionFailedError < StandardError
12
- end
13
- end
14
- end
@@ -1,1149 +0,0 @@
1
- # Author:: Nathaniel Talbott.
2
- # Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
3
- # Copyright (c) 2009 Kouhei Sutou.
4
- # License:: Ruby license.
5
-
6
- require 'test/unit/assertionfailederror'
7
- require 'test/unit/util/backtracefilter'
8
- require 'test/unit/util/method-owner-finder'
9
- require 'test/unit/diff'
10
-
11
- module Test
12
- module Unit
13
-
14
- ##
15
- # Test::Unit::Assertions contains the standard Test::Unit assertions.
16
- # Assertions is included in Test::Unit::TestCase.
17
- #
18
- # To include it in your own code and use its functionality, you simply
19
- # need to rescue Test::Unit::AssertionFailedError. Additionally you may
20
- # override add_assertion to get notified whenever an assertion is made.
21
- #
22
- # Notes:
23
- # * The message to each assertion, if given, will be propagated with the
24
- # failure.
25
- # * It is easy to add your own assertions based on assert_block().
26
- #
27
- # = Example Custom Assertion
28
- #
29
- # def deny(boolean, message = nil)
30
- # message = build_message message, '<?> is not false or nil.', boolean
31
- # assert_block message do
32
- # not boolean
33
- # end
34
- # end
35
-
36
- module Assertions
37
-
38
- ##
39
- # The assertion upon which all other assertions are based. Passes if the
40
- # block yields true.
41
- #
42
- # Example:
43
- # assert_block "Couldn't do the thing" do
44
- # do_the_thing
45
- # end
46
-
47
- public
48
- def assert_block(message="assert_block failed.") # :yields:
49
- _wrap_assertion do
50
- if (! yield)
51
- raise AssertionFailedError.new(message.to_s)
52
- end
53
- end
54
- end
55
-
56
- ##
57
- # Asserts that +boolean+ is not false or nil.
58
- #
59
- # Example:
60
- # assert [1, 2].include?(5)
61
-
62
- public
63
- def assert(boolean, message=nil)
64
- _wrap_assertion do
65
- assert_block("assert should not be called with a block.") { !block_given? }
66
- assert_block(build_message(message, "<?> is not true.", boolean)) { boolean }
67
- end
68
- end
69
-
70
- ##
71
- # Passes if +expected+ == +actual.
72
- #
73
- # Note that the ordering of arguments is important, since a helpful
74
- # error message is generated when this one fails that tells you the
75
- # values of expected and actual.
76
- #
77
- # Example:
78
- # assert_equal 'MY STRING', 'my string'.upcase
79
-
80
- public
81
- def assert_equal(expected, actual, message=nil)
82
- diff = AssertionMessage.delayed_diff(expected, actual)
83
- full_message = build_message(message, <<EOT, expected, actual, diff)
84
- <?> expected but was
85
- <?>.?
86
- EOT
87
- assert_block(full_message) { expected == actual }
88
- end
89
-
90
- ##
91
- # Passes if the block raises one of the expected
92
- # exceptions. When an expected exception is an Exception
93
- # object, passes if expected_exception == actual_exception.
94
- #
95
- # Example:
96
- # assert_raise(RuntimeError, LoadError) do
97
- # raise 'Boom!!!'
98
- # end # -> pass
99
- #
100
- # assert_raise do
101
- # raise Exception, 'Any exception should be raised!!!'
102
- # end # -> pass
103
- #
104
- # assert_raise(RuntimeError.new("XXX")) {raise "XXX"} # -> pass
105
- # assert_raise(MyError.new("XXX")) {raise "XXX"} # -> fail
106
- # assert_raise(RuntimeError.new("ZZZ")) {raise "XXX"} # -> fail
107
- public
108
- def assert_raise(*args, &block)
109
- assert_expected_exception = Proc.new do |*_args|
110
- message, assert_exception_helper, actual_exception = _args
111
- expected = assert_exception_helper.expected_exceptions
112
- full_message = build_message(message,
113
- "<?> exception expected but was\n?",
114
- expected, actual_exception)
115
- assert_block(full_message) do
116
- expected == [] or assert_exception_helper.expected?(actual_exception)
117
- end
118
- end
119
- _assert_raise(assert_expected_exception, *args, &block)
120
- end
121
-
122
- ##
123
- # Alias of assert_raise.
124
- #
125
- # Will be deprecated in 1.9, and removed in 2.0.
126
-
127
- public
128
- def assert_raises(*args, &block)
129
- assert_raise(*args, &block)
130
- end
131
-
132
- ##
133
- # Passes if the block raises one of the given
134
- # exceptions or sub exceptions of the given exceptions.
135
- #
136
- # Example:
137
- # assert_raise_kind_of(SystemCallError) do
138
- # raise Errno::EACCES
139
- # end
140
- def assert_raise_kind_of(*args, &block)
141
- assert_expected_exception = Proc.new do |*_args|
142
- message, assert_exception_helper, actual_exception = _args
143
- expected = assert_exception_helper.expected_exceptions
144
- full_message = build_message(message,
145
- "<?> family exception expected " +
146
- "but was\n?",
147
- expected, actual_exception)
148
- assert_block(full_message) do
149
- assert_exception_helper.expected?(actual_exception, :kind_of?)
150
- end
151
- end
152
- _assert_raise(assert_expected_exception, *args, &block)
153
- end
154
-
155
-
156
- ##
157
- # Passes if +object+.instance_of?(+klass+). When +klass+ is
158
- # an array of classes, it passes if any class
159
- # satisfies +object.instance_of?(class).
160
- #
161
- # Example:
162
- # assert_instance_of(String, 'foo') # -> pass
163
- # assert_instance_of([Fixnum, NilClass], 100) # -> pass
164
- # assert_instance_of([Numeric, NilClass], 100) # -> fail
165
-
166
- public
167
- def assert_instance_of(klass, object, message="")
168
- _wrap_assertion do
169
- klasses = nil
170
- klasses = klass if klass.is_a?(Array)
171
- assert_block("The first parameter to assert_instance_of should be " +
172
- "a Class or an Array of Class.") do
173
- if klasses
174
- klasses.all? {|k| k.is_a?(Class)}
175
- else
176
- klass.is_a?(Class)
177
- end
178
- end
179
- klass_message = AssertionMessage.maybe_container(klass) do |value|
180
- "<#{value}>"
181
- end
182
- full_message = build_message(message, <<EOT, object, klass_message, object.class)
183
- <?> expected to be an instance of
184
- ? but was
185
- <?>.
186
- EOT
187
- assert_block(full_message) do
188
- if klasses
189
- klasses.any? {|k| object.instance_of?(k)}
190
- else
191
- object.instance_of?(klass)
192
- end
193
- end
194
- end
195
- end
196
-
197
- ##
198
- # Passes if +object+ is nil.
199
- #
200
- # Example:
201
- # assert_nil [1, 2].uniq!
202
-
203
- public
204
- def assert_nil(object, message="")
205
- full_message = build_message(message, <<EOT, object)
206
- <?> expected to be nil.
207
- EOT
208
- assert_block(full_message) { object.nil? }
209
- end
210
-
211
- ##
212
- # Passes if +object+.kind_of?(+klass+). When +klass+ is
213
- # an array of classes or modules, it passes if any
214
- # class or module satisfies +object.kind_of?(class_or_module).
215
- #
216
- # Example:
217
- # assert_kind_of(Object, 'foo') # -> pass
218
- # assert_kind_of([Fixnum, NilClass], 100) # -> pass
219
- # assert_kind_of([Fixnum, NilClass], "string") # -> fail
220
-
221
- public
222
- def assert_kind_of(klass, object, message="")
223
- _wrap_assertion do
224
- klasses = nil
225
- klasses = klass if klass.is_a?(Array)
226
- assert_block("The first parameter to assert_kind_of should be " +
227
- "a kind_of Module or an Array of a kind_of Module.") do
228
- if klasses
229
- klasses.all? {|k| k.kind_of?(Module)}
230
- else
231
- klass.kind_of?(Module)
232
- end
233
- end
234
- klass_message = AssertionMessage.maybe_container(klass) do |value|
235
- "<#{value}>"
236
- end
237
- full_message = build_message(message,
238
- "<?> expected to be kind_of\\?\n" +
239
- "? but was\n" +
240
- "<?>.",
241
- object,
242
- klass_message,
243
- object.class)
244
- assert_block(full_message) do
245
- if klasses
246
- klasses.any? {|k| object.kind_of?(k)}
247
- else
248
- object.kind_of?(klass)
249
- end
250
- end
251
- end
252
- end
253
-
254
- ##
255
- # Passes if +object+ .respond_to? +method+
256
- #
257
- # Example:
258
- # assert_respond_to 'bugbear', :slice
259
-
260
- public
261
- def assert_respond_to(object, method, message="")
262
- _wrap_assertion do
263
- full_message = build_message(message,
264
- "<?>.kind_of\\?(Symbol) or\n" +
265
- "<?>.respond_to\\?(:to_str) expected",
266
- method, method)
267
- assert_block(full_message) do
268
- method.kind_of?(Symbol) or method.respond_to?(:to_str)
269
- end
270
- full_message = build_message(message,
271
- "<?>.respond_to\\?(?) expected\n" +
272
- "(Class: <?>)",
273
- object, method, object.class)
274
- assert_block(full_message) {object.respond_to?(method)}
275
- end
276
- end
277
-
278
- ##
279
- # Passes if +string+ =~ +pattern+.
280
- #
281
- # Example:
282
- # assert_match(/\d+/, 'five, 6, seven')
283
-
284
- public
285
- def assert_match(pattern, string, message="")
286
- _wrap_assertion do
287
- pattern = case(pattern)
288
- when String
289
- Regexp.new(Regexp.escape(pattern))
290
- else
291
- pattern
292
- end
293
- full_message = build_message(message, "<?> expected to be =~\n<?>.", string, pattern)
294
- assert_block(full_message) { string =~ pattern }
295
- end
296
- end
297
-
298
- ##
299
- # Passes if +actual+ .equal? +expected+ (i.e. they are the same
300
- # instance).
301
- #
302
- # Example:
303
- # o = Object.new
304
- # assert_same o, o
305
-
306
- public
307
- def assert_same(expected, actual, message="")
308
- full_message = build_message(message, <<EOT, expected, expected.__id__, actual, actual.__id__)
309
- <?>
310
- with id <?> expected to be equal\\? to
311
- <?>
312
- with id <?>.
313
- EOT
314
- assert_block(full_message) { actual.equal?(expected) }
315
- end
316
-
317
- ##
318
- # Compares the +object1+ with +object2+ using +operator+.
319
- #
320
- # Passes if object1.__send__(operator, object2) is true.
321
- #
322
- # Example:
323
- # assert_operator 5, :>=, 4
324
-
325
- public
326
- def assert_operator(object1, operator, object2, message="")
327
- _wrap_assertion do
328
- full_message = build_message(nil, "<?>\ngiven as the operator for #assert_operator must be a Symbol or #respond_to\\?(:to_str).", operator)
329
- assert_block(full_message){operator.kind_of?(Symbol) || operator.respond_to?(:to_str)}
330
- full_message = build_message(message, <<EOT, object1, AssertionMessage.literal(operator), object2)
331
- <?> expected to be
332
- ?
333
- <?>.
334
- EOT
335
- assert_block(full_message) { object1.__send__(operator, object2) }
336
- end
337
- end
338
-
339
- ##
340
- # Passes if block does not raise an exception.
341
- #
342
- # Example:
343
- # assert_nothing_raised do
344
- # [1, 2].uniq
345
- # end
346
-
347
- public
348
- def assert_nothing_raised(*args)
349
- _wrap_assertion do
350
- if args.last.is_a?(String)
351
- message = args.pop
352
- else
353
- message = ""
354
- end
355
-
356
- assert_exception_helper = AssertExceptionHelper.new(self, args)
357
- begin
358
- yield
359
- rescue Exception => e
360
- if ((args.empty? && !e.instance_of?(AssertionFailedError)) ||
361
- assert_exception_helper.expected?(e))
362
- failure_message = build_message(message, "Exception raised:\n?", e)
363
- assert_block(failure_message) {false}
364
- else
365
- raise
366
- end
367
- end
368
- nil
369
- end
370
- end
371
-
372
- ##
373
- # Flunk always fails.
374
- #
375
- # Example:
376
- # flunk 'Not done testing yet.'
377
-
378
- public
379
- def flunk(message="Flunked")
380
- assert_block(build_message(message)){false}
381
- end
382
-
383
- ##
384
- # Passes if ! +actual+ .equal? +expected+
385
- #
386
- # Example:
387
- # assert_not_same Object.new, Object.new
388
-
389
- public
390
- def assert_not_same(expected, actual, message="")
391
- full_message = build_message(message, <<EOT, expected, expected.__id__, actual, actual.__id__)
392
- <?>
393
- with id <?> expected to not be equal\\? to
394
- <?>
395
- with id <?>.
396
- EOT
397
- assert_block(full_message) { !actual.equal?(expected) }
398
- end
399
-
400
- ##
401
- # Passes if +expected+ != +actual+
402
- #
403
- # Example:
404
- # assert_not_equal 'some string', 5
405
-
406
- public
407
- def assert_not_equal(expected, actual, message="")
408
- full_message = build_message(message, "<?> expected to be != to\n<?>.", expected, actual)
409
- assert_block(full_message) { expected != actual }
410
- end
411
-
412
- ##
413
- # Passes if ! +object+ .nil?
414
- #
415
- # Example:
416
- # assert_not_nil '1 two 3'.sub!(/two/, '2')
417
-
418
- public
419
- def assert_not_nil(object, message="")
420
- full_message = build_message(message, "<?> expected to not be nil.", object)
421
- assert_block(full_message){!object.nil?}
422
- end
423
-
424
- ##
425
- # Passes if +regexp+ !~ +string+
426
- #
427
- # Example:
428
- # assert_no_match(/two/, 'one 2 three')
429
-
430
- public
431
- def assert_no_match(regexp, string, message="")
432
- _wrap_assertion do
433
- assert_instance_of(Regexp, regexp, "The first argument to assert_no_match should be a Regexp.")
434
- full_message = build_message(message, "<?> expected to not match\n<?>.", regexp, string)
435
- assert_block(full_message) { regexp !~ string }
436
- end
437
- end
438
-
439
- UncaughtThrow = {
440
- NameError => /^uncaught throw \`(.+)\'$/,
441
- ArgumentError => /^uncaught throw (.+)$/,
442
- ThreadError => /^uncaught throw \`(.+)\' in thread /
443
- } #`
444
-
445
- ##
446
- # Passes if the block throws +expected_object+
447
- #
448
- # Example:
449
- # assert_throw(:done) do
450
- # throw(:done)
451
- # end
452
-
453
- public
454
- def assert_throw(expected_object, message="", &proc)
455
- _wrap_assertion do
456
- begin
457
- catch([]) {}
458
- rescue TypeError
459
- assert_instance_of(Symbol, expected_object,
460
- "assert_throws expects the symbol that should be thrown for its first argument")
461
- end
462
- assert_block("Should have passed a block to assert_throw.") do
463
- block_given?
464
- end
465
- caught = true
466
- begin
467
- catch(expected_object) do
468
- proc.call
469
- caught = false
470
- end
471
- full_message = build_message(message,
472
- "<?> should have been thrown.",
473
- expected_object)
474
- assert_block(full_message) {caught}
475
- rescue NameError, ArgumentError, ThreadError => error
476
- raise unless UncaughtThrow[error.class] =~ error.message
477
- tag = $1
478
- tag = tag[1..-1].intern if tag[0, 1] == ":"
479
- full_message = build_message(message,
480
- "<?> expected to be thrown but\n" +
481
- "<?> was thrown.",
482
- expected_object, tag)
483
- flunk(full_message)
484
- end
485
- end
486
- end
487
-
488
- ##
489
- # Alias of assert_throw.
490
- #
491
- # Will be deprecated in 1.9, and removed in 2.0.
492
- def assert_throws(*args, &block)
493
- assert_throw(*args, &block)
494
- end
495
-
496
- ##
497
- # Passes if block does not throw anything.
498
- #
499
- # Example:
500
- # assert_nothing_thrown do
501
- # [1, 2].uniq
502
- # end
503
-
504
- public
505
- def assert_nothing_thrown(message="", &proc)
506
- _wrap_assertion do
507
- assert(block_given?, "Should have passed a block to assert_nothing_thrown")
508
- begin
509
- proc.call
510
- rescue NameError, ArgumentError, ThreadError => error
511
- raise unless UncaughtThrow[error.class] =~ error.message
512
- tag = $1
513
- tag = tag[1..-1].intern if tag[0, 1] == ":"
514
- full_message = build_message(message,
515
- "<?> was thrown when nothing was expected",
516
- tag)
517
- flunk(full_message)
518
- end
519
- assert(true, "Expected nothing to be thrown")
520
- end
521
- end
522
-
523
- ##
524
- # Passes if +expected_float+ and +actual_float+ are equal
525
- # within +delta+ tolerance.
526
- #
527
- # Example:
528
- # assert_in_delta 0.05, (50000.0 / 10**6), 0.00001
529
-
530
- public
531
- def assert_in_delta(expected_float, actual_float, delta, message="")
532
- _wrap_assertion do
533
- {expected_float => "first float", actual_float => "second float", delta => "delta"}.each do |float, name|
534
- assert_respond_to(float, :to_f, "The arguments must respond to to_f; the #{name} did not")
535
- end
536
- assert_operator(delta, :>=, 0.0, "The delta should not be negative")
537
- full_message = build_message(message, <<EOT, expected_float, actual_float, delta)
538
- <?> and
539
- <?> expected to be within
540
- <?> of each other.
541
- EOT
542
- assert_block(full_message) { (expected_float.to_f - actual_float.to_f).abs <= delta.to_f }
543
- end
544
- end
545
-
546
- ##
547
- # Passes if the method send returns a true value.
548
- #
549
- # +send_array+ is composed of:
550
- # * A receiver
551
- # * A method
552
- # * Arguments to the method
553
- #
554
- # Example:
555
- # assert_send [[1, 2], :include?, 4]
556
-
557
- public
558
- def assert_send(send_array, message="")
559
- _wrap_assertion do
560
- assert_instance_of(Array, send_array, "assert_send requires an array of send information")
561
- assert(send_array.size >= 2, "assert_send requires at least a receiver and a message name")
562
- full_message = build_message(message, <<EOT, send_array[0], AssertionMessage.literal(send_array[1].to_s), send_array[2..-1])
563
- <?> expected to respond to
564
- <?(?)> with a true value.
565
- EOT
566
- assert_block(full_message) { send_array[0].__send__(send_array[1], *send_array[2..-1]) }
567
- end
568
- end
569
-
570
- ##
571
- # Passes if +actual+ is a boolean value.
572
- #
573
- # Example:
574
- # assert_boolean(true) # -> pass
575
- # assert_boolean(nil) # -> fail
576
- def assert_boolean(actual, message=nil)
577
- _wrap_assertion do
578
- assert_block(build_message(message,
579
- "<true> or <false> expected but was\n<?>",
580
- actual)) do
581
- [true, false].include?(actual)
582
- end
583
- end
584
- end
585
-
586
- ##
587
- # Passes if +actual+ is true.
588
- #
589
- # Example:
590
- # assert_true(true) # -> pass
591
- # assert_true(:true) # -> fail
592
- def assert_true(actual, message=nil)
593
- _wrap_assertion do
594
- assert_block(build_message(message,
595
- "<true> expected but was\n<?>",
596
- actual)) do
597
- actual == true
598
- end
599
- end
600
- end
601
-
602
- ##
603
- # Passes if +actual+ is false.
604
- #
605
- # Example:
606
- # assert_false(false) # -> pass
607
- # assert_false(nil) # -> fail
608
- def assert_false(actual, message=nil)
609
- _wrap_assertion do
610
- assert_block(build_message(message,
611
- "<false> expected but was\n<?>",
612
- actual)) do
613
- actual == false
614
- end
615
- end
616
- end
617
-
618
- ##
619
- # Passes if expression "+expected+ +operator+
620
- # +actual+" is true.
621
- #
622
- # Example:
623
- # assert_compare(1, "<", 10) # -> pass
624
- # assert_compare(1, ">=", 10) # -> fail
625
- def assert_compare(expected, operator, actual, message=nil)
626
- _wrap_assertion do
627
- assert_send([["<", "<=", ">", ">="], :include?, operator.to_s])
628
- case operator.to_s
629
- when "<"
630
- operator_description = "less than"
631
- when "<="
632
- operator_description = "less than or equal to"
633
- when ">"
634
- operator_description = "greater than"
635
- when ">="
636
- operator_description = "greater than or equal to"
637
- end
638
- template = <<-EOT
639
- <?> #{operator} <?> should be true
640
- <?> expected #{operator_description}
641
- <?>.
642
- EOT
643
- full_message = build_message(message, template,
644
- expected, actual,
645
- expected, actual)
646
- assert_block(full_message) do
647
- expected.send(operator, actual)
648
- end
649
- end
650
- end
651
-
652
- ##
653
- # Passes if assertion is failed in block.
654
- #
655
- # Example:
656
- # assert_fail_assertion {assert_equal("A", "B")} # -> pass
657
- # assert_fail_assertion {assert_equal("A", "A")} # -> fail
658
- def assert_fail_assertion(message=nil)
659
- _wrap_assertion do
660
- full_message = build_message(message,
661
- "Failed assertion was expected.")
662
- assert_block(full_message) do
663
- begin
664
- yield
665
- false
666
- rescue AssertionFailedError
667
- true
668
- end
669
- end
670
- end
671
- end
672
-
673
- ##
674
- # Passes if an exception is raised in block and its
675
- # message is +expected+.
676
- #
677
- # Example:
678
- # assert_raise_message("exception") {raise "exception"} # -> pass
679
- # assert_raise_message(/exc/i) {raise "exception"} # -> pass
680
- # assert_raise_message("exception") {raise "EXCEPTION"} # -> fail
681
- # assert_raise_message("exception") {} # -> fail
682
- def assert_raise_message(expected, message=nil)
683
- _wrap_assertion do
684
- full_message = build_message(message,
685
- "<?> exception message expected " +
686
- "but none was thrown.",
687
- expected)
688
- exception = nil
689
- assert_block(full_message) do
690
- begin
691
- yield
692
- false
693
- rescue Exception => exception
694
- true
695
- end
696
- end
697
-
698
- actual = exception.message
699
- diff = AssertionMessage.delayed_diff(expected, actual)
700
- full_message =
701
- build_message(message,
702
- "<?> exception message expected but was\n" +
703
- "<?>.?", expected, actual, diff)
704
- assert_block(full_message) do
705
- if expected.is_a?(Regexp)
706
- expected =~ actual
707
- else
708
- expected == actual
709
- end
710
- end
711
- end
712
- end
713
-
714
- ##
715
- # Passes if +object+.const_defined?(+constant_name+)
716
- #
717
- # Example:
718
- # assert_const_defined(Test, :Unit) # -> pass
719
- # assert_const_defined(Object, :Nonexistent) # -> fail
720
- def assert_const_defined(object, constant_name, message=nil)
721
- _wrap_assertion do
722
- full_message = build_message(message,
723
- "<?>.const_defined\\?(<?>) expected.",
724
- object, constant_name)
725
- assert_block(full_message) do
726
- object.const_defined?(constant_name)
727
- end
728
- end
729
- end
730
-
731
- ##
732
- # Passes if !+object+.const_defined?(+constant_name+)
733
- #
734
- # Example:
735
- # assert_not_const_defined(Object, :Nonexistent) # -> pass
736
- # assert_not_const_defined(Test, :Unit) # -> fail
737
- def assert_not_const_defined(object, constant_name, message=nil)
738
- _wrap_assertion do
739
- full_message = build_message(message,
740
- "!<?>.const_defined\\?(<?>) expected.",
741
- object, constant_name)
742
- assert_block(full_message) do
743
- !object.const_defined?(constant_name)
744
- end
745
- end
746
- end
747
-
748
- ##
749
- # Passes if +object+.+predicate+
750
- #
751
- # Example:
752
- # assert_predicate([], :empty?) # -> pass
753
- # assert_predicate([1], :empty?) # -> fail
754
- def assert_predicate(object, predicate, message=nil)
755
- _wrap_assertion do
756
- assert_respond_to(object, predicate, message)
757
- actual = object.send(predicate)
758
- full_message = build_message(message,
759
- "<?>.? is true value expected but was\n" +
760
- "<?>",
761
- object,
762
- AssertionMessage.literal(predicate),
763
- actual)
764
- assert_block(full_message) do
765
- actual
766
- end
767
- end
768
- end
769
-
770
- ##
771
- # Passes if +object+.+predicate+
772
- #
773
- # Example:
774
- # assert_not_predicate([1], :empty?) # -> pass
775
- # assert_not_predicate([], :empty?) # -> fail
776
- def assert_not_predicate(object, predicate, message=nil)
777
- _wrap_assertion do
778
- assert_respond_to(object, predicate, message)
779
- actual = object.send(predicate)
780
- full_message = build_message(message,
781
- "<?>.? is false value expected but was\n" +
782
- "<?>",
783
- object,
784
- AssertionMessage.literal(predicate),
785
- actual)
786
- assert_block(full_message) do
787
- not actual
788
- end
789
- end
790
- end
791
-
792
- ##
793
- # Builds a failure message. +head+ is added before the +template+ and
794
- # +arguments+ replaces the '?'s positionally in the template.
795
-
796
- public
797
- def build_message(head, template=nil, *arguments)
798
- template &&= template.chomp
799
- return AssertionMessage.new(head, template, arguments)
800
- end
801
-
802
- private
803
- def _wrap_assertion
804
- @_assertion_wrapped ||= false
805
- unless (@_assertion_wrapped)
806
- @_assertion_wrapped = true
807
- begin
808
- add_assertion
809
- return yield
810
- ensure
811
- @_assertion_wrapped = false
812
- end
813
- else
814
- return yield
815
- end
816
- end
817
-
818
- ##
819
- # Called whenever an assertion is made. Define this in classes that
820
- # include Test::Unit::Assertions to record assertion counts.
821
-
822
- private
823
- def add_assertion
824
- end
825
-
826
- ##
827
- # Select whether or not to use the pretty-printer. If this option is set
828
- # to false before any assertions are made, pp.rb will not be required.
829
-
830
- public
831
- def self.use_pp=(value)
832
- AssertionMessage.use_pp = value
833
- end
834
-
835
- # :stopdoc:
836
- private
837
- def _assert_raise(assert_expected_exception, *args, &block)
838
- _wrap_assertion do
839
- if args.last.is_a?(String)
840
- message = args.pop
841
- else
842
- message = ""
843
- end
844
-
845
- assert_exception_helper = AssertExceptionHelper.new(self, args)
846
- expected = assert_exception_helper.expected_exceptions
847
- actual_exception = nil
848
- full_message = build_message(message,
849
- "<?> exception expected " +
850
- "but none was thrown.",
851
- expected)
852
- assert_block(full_message) do
853
- begin
854
- yield
855
- false
856
- rescue Exception => actual_exception
857
- true
858
- end
859
- end
860
- assert_expected_exception.call(message, assert_exception_helper,
861
- actual_exception)
862
- actual_exception
863
- end
864
- end
865
-
866
- class AssertionMessage
867
- @use_pp = true
868
- class << self
869
- attr_accessor :use_pp
870
-
871
- def literal(value)
872
- Literal.new(value)
873
- end
874
-
875
- def delayed_literal(&block)
876
- DelayedLiteral.new(block)
877
- end
878
-
879
- def maybe_container(value, &formatter)
880
- MaybeContainer.new(value, &formatter)
881
- end
882
-
883
- MAX_DIFF_TARGET_STRING_SIZE = 1000
884
- def diff_target_string?(string)
885
- if string.respond_to?(:bytesize)
886
- string.bytesize < MAX_DIFF_TARGET_STRING_SIZE
887
- else
888
- string.size < MAX_DIFF_TARGET_STRING_SIZE
889
- end
890
- end
891
-
892
- def delayed_diff(from, to)
893
- delayed_literal do
894
- if !from.is_a?(String) or !to.is_a?(String)
895
- from = convert(from)
896
- to = convert(to)
897
- end
898
-
899
- diff = nil
900
- diff = "" if !diff_target_string?(from) or !diff_target_string?(to)
901
- diff ||= Diff.readable(from, to)
902
- if /^[-+]/ !~ diff
903
- diff = ""
904
- elsif /^[ ?]/ =~ diff or /(?:.*\n){2,}/ =~ diff
905
- diff = "\n\ndiff:\n#{diff}"
906
- else
907
- diff = ""
908
- end
909
-
910
- if Diff.need_fold?(diff)
911
- folded_diff = Diff.folded_readable(from, to)
912
- diff << "\n\nfolded diff:\n#{folded_diff}"
913
- end
914
-
915
- diff
916
- end
917
- end
918
-
919
- def convert(object)
920
- case object
921
- when Exception
922
- <<EOM.chop
923
- Class: <#{convert(object.class)}>
924
- Message: <#{convert(object.message)}>
925
- ---Backtrace---
926
- #{Util::BacktraceFilter.filter_backtrace(object.backtrace).join("\n")}
927
- ---------------
928
- EOM
929
- else
930
- if use_pp
931
- begin
932
- require 'pp' unless defined?(PP)
933
- return PP.pp(object, '').chomp
934
- rescue LoadError
935
- self.use_pp = false
936
- end
937
- end
938
- object.inspect
939
- end
940
- end
941
- end
942
-
943
- class Literal
944
- def initialize(value)
945
- @value = value
946
- end
947
-
948
- def inspect
949
- @value.to_s
950
- end
951
- end
952
-
953
- class DelayedLiteral
954
- def initialize(value)
955
- @value = value
956
- end
957
-
958
- def inspect
959
- @value.call.to_s
960
- end
961
- end
962
-
963
- class MaybeContainer
964
- def initialize(value, &formatter)
965
- @value = value
966
- @formatter = formatter
967
- end
968
-
969
- def inspect
970
- if @value.is_a?(Array)
971
- values = @value.collect do |value|
972
- @formatter.call(AssertionMessage.convert(value))
973
- end
974
- "[#{values.join(', ')}]"
975
- else
976
- @formatter.call(AssertionMessage.convert(@value))
977
- end
978
- end
979
- end
980
-
981
- class Template
982
- def self.create(string)
983
- parts = (string ? string.scan(/(?=[^\\])\?|(?:\\\?|[^\?])+/m) : [])
984
- self.new(parts)
985
- end
986
-
987
- attr_reader :count
988
-
989
- def initialize(parts)
990
- @parts = parts
991
- @count = parts.find_all{|e| e == '?'}.size
992
- end
993
-
994
- def result(parameters)
995
- raise "The number of parameters does not match the number of substitutions." if(parameters.size != count)
996
- params = parameters.dup
997
- @parts.collect{|e| e == '?' ? params.shift : e.gsub(/\\\?/m, '?')}.join('')
998
- end
999
- end
1000
-
1001
- include Util::BacktraceFilter
1002
-
1003
- def initialize(head, template_string, parameters)
1004
- @head = head
1005
- @template_string = template_string
1006
- @parameters = parameters
1007
- end
1008
-
1009
- def convert(object)
1010
- self.class.convert(object)
1011
- end
1012
-
1013
- def template
1014
- @template ||= Template.create(@template_string)
1015
- end
1016
-
1017
- def add_period(string)
1018
- (string =~ /\.\Z/ ? string : string + '.')
1019
- end
1020
-
1021
- def to_s
1022
- message_parts = []
1023
- if (@head)
1024
- head = @head.to_s
1025
- unless(head.empty?)
1026
- message_parts << add_period(head)
1027
- end
1028
- end
1029
- tail = template.result(@parameters.collect{|e| convert(e)})
1030
- message_parts << tail unless(tail.empty?)
1031
- message_parts.join("\n")
1032
- end
1033
- end
1034
-
1035
- class AssertExceptionHelper
1036
- class WrappedException
1037
- def initialize(exception)
1038
- @exception = exception
1039
- end
1040
-
1041
- def inspect
1042
- if default_inspect?
1043
- "#{@exception.class.inspect}(#{@exception.message.inspect})"
1044
- else
1045
- @exception.inspect
1046
- end
1047
- end
1048
-
1049
- def method_missing(name, *args, &block)
1050
- @exception.send(name, *args, &block)
1051
- end
1052
-
1053
- private
1054
- def default_inspect?
1055
- inspect_method = @exception.method(:inspect)
1056
- if inspect_method.respond_to?(:owner) and
1057
- inspect_method.owner == Exception
1058
- true
1059
- else
1060
- default_inspect_method = Exception.instance_method(:inspect)
1061
- default_inspect_method.bind(@exception).call == @exception.inspect
1062
- end
1063
- end
1064
- end
1065
-
1066
- def initialize(test_case, expected_exceptions)
1067
- @test_case = test_case
1068
- @expected_exceptions = expected_exceptions
1069
- @expected_classes, @expected_modules, @expected_objects =
1070
- split_expected_exceptions(expected_exceptions)
1071
- end
1072
-
1073
- def expected_exceptions
1074
- exceptions = @expected_exceptions.collect do |exception|
1075
- if exception.is_a?(Exception)
1076
- WrappedException.new(exception)
1077
- else
1078
- exception
1079
- end
1080
- end
1081
- if exceptions.size == 1
1082
- exceptions[0]
1083
- else
1084
- exceptions
1085
- end
1086
- end
1087
-
1088
- def expected?(actual_exception, equality=nil)
1089
- equality ||= :instance_of?
1090
- expected_class?(actual_exception, equality) or
1091
- expected_module?(actual_exception) or
1092
- expected_object?(actual_exception)
1093
- end
1094
-
1095
- private
1096
- def split_expected_exceptions(expected_exceptions)
1097
- exception_modules = []
1098
- exception_objects = []
1099
- exception_classes = []
1100
- expected_exceptions.each do |exception_type|
1101
- if exception_type.instance_of?(Module)
1102
- exception_modules << exception_type
1103
- elsif exception_type.is_a?(Exception)
1104
- exception_objects << exception_type
1105
- else
1106
- @test_case.send(:assert,
1107
- Exception >= exception_type,
1108
- "Should expect a class of exception, " +
1109
- "#{exception_type}")
1110
- exception_classes << exception_type
1111
- end
1112
- end
1113
- [exception_classes, exception_modules, exception_objects]
1114
- end
1115
-
1116
- def expected_class?(actual_exception, equality)
1117
- @expected_classes.any? do |expected_class|
1118
- actual_exception.send(equality, expected_class)
1119
- end
1120
- end
1121
-
1122
- def expected_module?(actual_exception)
1123
- @expected_modules.any? do |expected_module|
1124
- actual_exception.is_a?(expected_module)
1125
- end
1126
- end
1127
-
1128
- def expected_object?(actual_exception)
1129
- @expected_objects.any? do |expected_object|
1130
- expected_object == actual_exception or
1131
- fallback_exception_object_equal(expected_object, actual_exception)
1132
- end
1133
- end
1134
-
1135
- def fallback_exception_object_equal(expected_object, actual_exception)
1136
- owner = Util::MethodOwnerFinder.find(expected_object, :==)
1137
- if owner == Kernel or owner == Exception
1138
- expected_object.class == actual_exception.class and
1139
- expected_object.message == actual_exception.message
1140
- else
1141
- false
1142
- end
1143
- end
1144
- end
1145
-
1146
- # :startdoc:
1147
- end
1148
- end
1149
- end