assay-minitest 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.ruby +52 -0
- data/COPYING.rdoc +39 -0
- data/HISTORY.rdoc +12 -0
- data/README.rdoc +75 -0
- data/lib/assay-minitest.rb +18 -0
- data/lib/assay-minitest.yml +52 -0
- data/lib/assay-minitest/assertions.rb +495 -0
- data/lib/assay-minitest/extensions.rb +474 -0
- data/lib/assay/minitest.rb +1 -0
- data/spec/01_minitest_extensions.rdoc +217 -0
- data/spec/02_minitest_assertions.rdoc +250 -0
- data/spec/applique/helper.rb +40 -0
- data/spec/applique/setup.rb +1 -0
- metadata +102 -0
@@ -0,0 +1,474 @@
|
|
1
|
+
module Assay; end
|
2
|
+
module Assay::MiniTest
|
3
|
+
|
4
|
+
# This module provides extensions for MiniTest compatiblity.
|
5
|
+
#
|
6
|
+
# The set is not fully compataible, but provides most of MiniTest
|
7
|
+
# extensions.
|
8
|
+
#
|
9
|
+
# Compatability will improve with time.
|
10
|
+
#
|
11
|
+
module Extensions
|
12
|
+
|
13
|
+
# Passes it operator with optional argument returns successfully.
|
14
|
+
#
|
15
|
+
# 10.must_be :>, 4
|
16
|
+
# 10.must_be :even?
|
17
|
+
#
|
18
|
+
# @raise ExecutionAssay
|
19
|
+
#
|
20
|
+
def must_be(operator, argument=nil, msg=nil)
|
21
|
+
if argument
|
22
|
+
ExecutionAssay.assert!(:message=>msg) do
|
23
|
+
__send__(operator, argument)
|
24
|
+
end
|
25
|
+
else
|
26
|
+
ExecutionAssay.assert!(:message=>msg) do
|
27
|
+
__send__(operator)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# Passes it operator with optional argument returns negatively.
|
34
|
+
#
|
35
|
+
# 10.wont_be :>, 20
|
36
|
+
# 10.wont_be :odd?
|
37
|
+
#
|
38
|
+
# @raise ExecutionAssay
|
39
|
+
#
|
40
|
+
def wont_be(operator, argument=nil, msg=nil)
|
41
|
+
if argument
|
42
|
+
ExecutionAssay.refute!(:message=>msg) do
|
43
|
+
self.__send__(operator, argument)
|
44
|
+
end
|
45
|
+
else
|
46
|
+
ExecutionAssay.refute!(:message=>msg) do
|
47
|
+
self.__send__(operator)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# Passes if object is like criterion.
|
54
|
+
#
|
55
|
+
# object.must_be_like(criterion)
|
56
|
+
#
|
57
|
+
# @raise LikeAssay
|
58
|
+
#
|
59
|
+
def must_be_like(exp, msg=nil)
|
60
|
+
LikeAssay.assert!(self, exp, :message=>msg, :backtrace=>caller)
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
# Passes if object is not like criterion using {CompareAssay}.
|
65
|
+
#
|
66
|
+
# object.wont_be_like(criterion)
|
67
|
+
#
|
68
|
+
# @raise LikeAssay
|
69
|
+
#
|
70
|
+
def wont_be_like(exp, msg=nil)
|
71
|
+
LikeAssay.refute!(self, exp, :message=>msg, :backtrace=>caller)
|
72
|
+
end
|
73
|
+
|
74
|
+
#
|
75
|
+
# Passes if expected and actual are equal within delta tolerance.
|
76
|
+
#
|
77
|
+
# assert_in_delta 0.05, (50000.0 / 10**6), 0.00001
|
78
|
+
#
|
79
|
+
# @raise WithinAssay
|
80
|
+
#
|
81
|
+
def must_be_within_delta(exp, delta, msg=nil)
|
82
|
+
WithinAssay.assert!(self, exp, delta, :message=>msg, :backtrace=>caller)
|
83
|
+
end
|
84
|
+
|
85
|
+
#
|
86
|
+
# Passes if expected and actual are equal not within delta tolerance.
|
87
|
+
#
|
88
|
+
# assert_not_in_delta 0.05, (50000.0 / 10**6), 0.00001
|
89
|
+
#
|
90
|
+
# @raise WithinAssay
|
91
|
+
#
|
92
|
+
def wont_be_within_delta(exp, delta, msg=nil)
|
93
|
+
WithinAssay.refute!(self, exp, delta, :message=>msg, :backtrace=>caller)
|
94
|
+
end
|
95
|
+
|
96
|
+
#
|
97
|
+
# Passes if object is empty.
|
98
|
+
#
|
99
|
+
# object.must_be_empty
|
100
|
+
#
|
101
|
+
# @raise EmptyAssay
|
102
|
+
#
|
103
|
+
def must_be_empty(msg=nil)
|
104
|
+
EmptyAssay.assert!(self, :message=>msg, :backtrace=>caller)
|
105
|
+
end
|
106
|
+
|
107
|
+
#
|
108
|
+
# Passes if object is not empty.
|
109
|
+
#
|
110
|
+
# object.wont_be_empty
|
111
|
+
#
|
112
|
+
# @raise EmptyAssay
|
113
|
+
#
|
114
|
+
def wont_be_empty(msg=nil)
|
115
|
+
EmptyAssay.refute!(self, :message=>msg, :backtrace=>caller)
|
116
|
+
end
|
117
|
+
|
118
|
+
#
|
119
|
+
# Passes if expected == +actual.
|
120
|
+
#
|
121
|
+
# Note that the ordering of arguments is important,
|
122
|
+
# since a helpful error message is generated when this
|
123
|
+
# one fails that tells you the values of expected and actual.
|
124
|
+
#
|
125
|
+
# 'MY STRING'.must_equal('my string'.upcase)
|
126
|
+
#
|
127
|
+
# @raise EqualAssay
|
128
|
+
#
|
129
|
+
def must_equal(exp, msg=nil)
|
130
|
+
EqualAssay.assert!(self, exp, :message=>msg, :backtrace=>caller)
|
131
|
+
end
|
132
|
+
|
133
|
+
#
|
134
|
+
# Passes if expected != actual
|
135
|
+
#
|
136
|
+
# 'some string'.wont_equal('some other string')
|
137
|
+
#
|
138
|
+
# @raise EqualAssay
|
139
|
+
#
|
140
|
+
def wont_equal(exp, msg=nil)
|
141
|
+
EqualAssay.refute!(self, exp, :message=>msg, :backtrace=>caller)
|
142
|
+
end
|
143
|
+
|
144
|
+
#
|
145
|
+
# Passes if method call returns successfully.
|
146
|
+
#
|
147
|
+
# "string".must_send([:upcase], "Doesn't upcase!")
|
148
|
+
#
|
149
|
+
# @raise ExecutionAssay
|
150
|
+
#
|
151
|
+
def must_send(send_array, msg=nil)
|
152
|
+
ExecutionAssay.assert!(:message=>msg, :backtrace=>caller) do
|
153
|
+
self.__send__(*send_array)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
#
|
158
|
+
# Passes if method call does not return successfully.
|
159
|
+
#
|
160
|
+
# "string".wont_send([:upcase], "Damn you, Uppercase!")
|
161
|
+
#
|
162
|
+
# @raise ExecutionAssay
|
163
|
+
#
|
164
|
+
def wont_send(send_array, msg=nil)
|
165
|
+
ExecutionAssay.refute!(:message=>msg, :backtrace=>caller) do
|
166
|
+
self.__send__(*send_array)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
#
|
171
|
+
# Passes if the block yields successfully.
|
172
|
+
#
|
173
|
+
# 5.must_satisfy{ |x| x > 3 }
|
174
|
+
#
|
175
|
+
# @raise ExecutionAssay
|
176
|
+
#
|
177
|
+
def must_satisfy(msg=nil, &block)
|
178
|
+
ExecutionAssay.assert!(self, :message=>msg, :backtrace=>caller, &block)
|
179
|
+
end
|
180
|
+
|
181
|
+
#
|
182
|
+
# Passes if the block does not yield successfully.
|
183
|
+
#
|
184
|
+
# 5.wont_satisfy{ |x| x < 3 }
|
185
|
+
#
|
186
|
+
# @raise ExecutionAssay
|
187
|
+
#
|
188
|
+
def wont_satisfy(msg=nil, &block)
|
189
|
+
ExecutionAssay.refute!(self, :message=>msg, :backtrace=>caller, &block)
|
190
|
+
end
|
191
|
+
|
192
|
+
#
|
193
|
+
# Passed if object is +false+.
|
194
|
+
#
|
195
|
+
# @raise FalseAssay
|
196
|
+
#
|
197
|
+
def must_be_false(msg=nil)
|
198
|
+
FalseAssay.assert!(self, :message=>msg, :backtrace=>caller)
|
199
|
+
end
|
200
|
+
|
201
|
+
#
|
202
|
+
# Passed if object is not +false+.
|
203
|
+
#
|
204
|
+
# assert_not_false(false)
|
205
|
+
#
|
206
|
+
# @raise FalseAssay
|
207
|
+
#
|
208
|
+
def wont_be_false(msg=nil)
|
209
|
+
FalseAssay.refute!(self, :message=>msg, :backtrace=>caller)
|
210
|
+
end
|
211
|
+
|
212
|
+
#
|
213
|
+
# Passes if `self` is the same exact object as expected.
|
214
|
+
#
|
215
|
+
# object.must_be_same_as(object)
|
216
|
+
#
|
217
|
+
# @raise IdentityAssay
|
218
|
+
#
|
219
|
+
def must_be_same_as(exp, msg=nil)
|
220
|
+
IdentityAssay.assert!(self, exp, :message=>msg, :backtrace=>caller)
|
221
|
+
end
|
222
|
+
|
223
|
+
#
|
224
|
+
# Passes if actual is not the same exact object as expected.
|
225
|
+
#
|
226
|
+
# object.wont_be_same_as(other)
|
227
|
+
#
|
228
|
+
# @raise IdentityAssay
|
229
|
+
#
|
230
|
+
def wont_be_same_as(exp, msg=nil)
|
231
|
+
IdentityAssay.refute!(self, exp, :message=>msg, :backtrace=>caller)
|
232
|
+
end
|
233
|
+
|
234
|
+
#
|
235
|
+
# Passes if object is an instance of class.
|
236
|
+
#
|
237
|
+
# 'foo'.must_be_instance_of(String)
|
238
|
+
#
|
239
|
+
# @raise InstanceAssay
|
240
|
+
#
|
241
|
+
def must_be_instance_of(cls, msg=nil)
|
242
|
+
InstanceAssay.assert!(self, cls, :message=>msg, :backtrace=>caller)
|
243
|
+
end
|
244
|
+
|
245
|
+
#
|
246
|
+
# Passes if object is not an instance of class.
|
247
|
+
#
|
248
|
+
# 'foo'.wont_be_instance_of(Integer)
|
249
|
+
#
|
250
|
+
# @raise InstanceAssay
|
251
|
+
#
|
252
|
+
def wont_be_instance_of(cls, msg=nil)
|
253
|
+
InstanceAssay.refute!(self, cls, :message=>msg, :backtrace=>caller)
|
254
|
+
end
|
255
|
+
|
256
|
+
#
|
257
|
+
# Passes if object is a kind of class.
|
258
|
+
#
|
259
|
+
# assert_kind_of(Object, 'foo')
|
260
|
+
#
|
261
|
+
# @raise KindAssay
|
262
|
+
#
|
263
|
+
def must_be_kind_of(cls, msg=nil)
|
264
|
+
KindAssay.assert!(self, cls, :message=>msg, :backtrace=>caller)
|
265
|
+
end
|
266
|
+
|
267
|
+
#
|
268
|
+
# Passes if object is not a kind of class.
|
269
|
+
#
|
270
|
+
# assert_not_kind_of(Object, 'foo')
|
271
|
+
#
|
272
|
+
# @raise KindAssay
|
273
|
+
#
|
274
|
+
def wont_be_kind_of(cls, msg=nil)
|
275
|
+
KindAssay.refute!(self, cls, :message=>msg, :backtrace=>caller)
|
276
|
+
end
|
277
|
+
|
278
|
+
#
|
279
|
+
# Passes if object matches pattern using `#=~` method.
|
280
|
+
#
|
281
|
+
# 'one 2 three'.must_match(/two/)
|
282
|
+
#
|
283
|
+
# @raise MatchAssay
|
284
|
+
#
|
285
|
+
def must_match(exp, msg=nil)
|
286
|
+
MatchAssay.assert!(self, exp, :message=>msg, :backtrace=>caller)
|
287
|
+
end
|
288
|
+
|
289
|
+
#
|
290
|
+
# Passes if object does not match pattern using `#=~` method.
|
291
|
+
#
|
292
|
+
# 'one 2 three'.wont_match(/two/)
|
293
|
+
#
|
294
|
+
# @raise MatchAssay
|
295
|
+
#
|
296
|
+
def wont_match(exp, msg=nil)
|
297
|
+
MatchAssay.refute!(self, exp, :message=>msg, :backtrace=>caller)
|
298
|
+
end
|
299
|
+
|
300
|
+
#
|
301
|
+
# Passed if object is +nil+.
|
302
|
+
#
|
303
|
+
# @raise NilAssay
|
304
|
+
#
|
305
|
+
def must_be_nil(msg=nil)
|
306
|
+
NilAssay.assert!(self, :message=>msg, :backtrace=>caller)
|
307
|
+
end
|
308
|
+
|
309
|
+
#
|
310
|
+
# Passed if object is not +nil+.
|
311
|
+
#
|
312
|
+
# assert_not_nil(true)
|
313
|
+
#
|
314
|
+
# @raise NilAssay
|
315
|
+
#
|
316
|
+
def wont_be_nil(msg=nil)
|
317
|
+
NilAssay.refute!(self, :message=>msg, :backtrace=>caller)
|
318
|
+
end
|
319
|
+
|
320
|
+
#
|
321
|
+
# Passes if the procedure raises a given exception.
|
322
|
+
#
|
323
|
+
# lambda{ raise 'Boom!!!' }.must_raise(RuntimeError)
|
324
|
+
#
|
325
|
+
# @raise RaiseAssay
|
326
|
+
#
|
327
|
+
def must_raise(exp, msg=nil, call=nil)
|
328
|
+
RaiseAssay.assert!(exp, msg=nil, call=nil, &self)
|
329
|
+
end
|
330
|
+
|
331
|
+
#
|
332
|
+
# Passes if the procedure *does not* raise a given exceptions.
|
333
|
+
#
|
334
|
+
# lambda{ raise 'Boom!!!' }.wont_raise(IOError)
|
335
|
+
#
|
336
|
+
# @raise RaiseAssay
|
337
|
+
#
|
338
|
+
def wont_raise(exp, msg=nil, call=nil)
|
339
|
+
RaiseAssay.refute!(exp, msg, call, &self)
|
340
|
+
end
|
341
|
+
|
342
|
+
#
|
343
|
+
# Passes if +object+ respond_to? +methods+.
|
344
|
+
#
|
345
|
+
# 'bugbear'.must_respond_to(:slice)
|
346
|
+
#
|
347
|
+
# @raise RespondAssay
|
348
|
+
#
|
349
|
+
def must_respond_to(method, msg=nil)
|
350
|
+
RespondAssay.assert!(self, method, :message=>msg, :backtrace=>caller)
|
351
|
+
end
|
352
|
+
|
353
|
+
#
|
354
|
+
# Passes if +object+ does not respond_to? +methods+.
|
355
|
+
#
|
356
|
+
# 'bugbear'.wont_respond_to(:slice)
|
357
|
+
#
|
358
|
+
# @raise RespondAssay
|
359
|
+
#
|
360
|
+
def wont_respond_to(method, msg=nil)
|
361
|
+
RespondAssay.refute!(self, method, :message=>msg, :backtrace=>caller)
|
362
|
+
end
|
363
|
+
|
364
|
+
#
|
365
|
+
# Passes if `criterion.eql?(actual)`.
|
366
|
+
#
|
367
|
+
# Note that the ordering of arguments is important,
|
368
|
+
# since a helpful error message is generated when this
|
369
|
+
# one fails that tells you the values of expected and actual.
|
370
|
+
#
|
371
|
+
# 'MY STRING'.must_be_equivalent_to('my string'.upcase)
|
372
|
+
#
|
373
|
+
# @raise EqualityAssay
|
374
|
+
#
|
375
|
+
def must_be_equivalent_to(criterion, msg=nil)
|
376
|
+
EqualityAssay.assert!(self, criterion, :message=>msg, :backtrace=>caller)
|
377
|
+
end
|
378
|
+
|
379
|
+
alias_method :must_eql, :must_be_equivalent_to
|
380
|
+
|
381
|
+
#
|
382
|
+
# Passes if NOT `criterion.eql?(actual)`.
|
383
|
+
#
|
384
|
+
# 'MY STRING'.wont_be_equivalent_to('some other string')
|
385
|
+
#
|
386
|
+
# @raise EqualityAssay
|
387
|
+
#
|
388
|
+
def wont_be_equivalent_to(criterion, msg=nil)
|
389
|
+
EqualityAssay.refute!(self, criterion, :message=>msg, :backtrace=>caller)
|
390
|
+
end
|
391
|
+
|
392
|
+
alias_method :wont_eql, :wont_be_equivalent_to
|
393
|
+
|
394
|
+
#
|
395
|
+
# Passes if the block throws expected_symbol
|
396
|
+
#
|
397
|
+
# assert_throws :done do
|
398
|
+
# throw :done
|
399
|
+
# end
|
400
|
+
#
|
401
|
+
# @raise ThrowAssay
|
402
|
+
#
|
403
|
+
def must_throw(sym, msg=nil)
|
404
|
+
ThrowAssay.assert!(sym, :message=>msg, :backtrace=>caller, &self)
|
405
|
+
end
|
406
|
+
|
407
|
+
#
|
408
|
+
# Passes if the block throws expected_symbol
|
409
|
+
#
|
410
|
+
# refute_throws :done do
|
411
|
+
# throw :chimp
|
412
|
+
# end
|
413
|
+
#
|
414
|
+
# @raise ThrowAssay
|
415
|
+
#
|
416
|
+
def wont_throw(sym, msg=nil)
|
417
|
+
ThrowAssay.refute!(sym, :message=>msg, :backtrace=>caller, &self)
|
418
|
+
end
|
419
|
+
|
420
|
+
#
|
421
|
+
# Passed if object is +true+.
|
422
|
+
#
|
423
|
+
# object.must_be_true
|
424
|
+
#
|
425
|
+
# @raise TrueAssay
|
426
|
+
#
|
427
|
+
def must_be_true(msg=nil)
|
428
|
+
TrueAssay.assert!(self, :message=>msg, :backtrace=>caller)
|
429
|
+
end
|
430
|
+
|
431
|
+
#
|
432
|
+
# Passed if object is not +true+.
|
433
|
+
#
|
434
|
+
# object.wont_be_true
|
435
|
+
#
|
436
|
+
# @raise TrueAssay
|
437
|
+
#
|
438
|
+
def wont_be_true(msg=nil)
|
439
|
+
TrueAssay.refute!(self, :message=>msg, :backtrace=>caller)
|
440
|
+
end
|
441
|
+
|
442
|
+
#
|
443
|
+
# Passes if `self.include?(object)`.
|
444
|
+
#
|
445
|
+
# @raise IncludeAssay
|
446
|
+
#
|
447
|
+
def must_include(object, msg=nil)
|
448
|
+
IncludeAssay.assert!(self, object, :message=>msg, :backtrace=>caller)
|
449
|
+
end
|
450
|
+
|
451
|
+
#
|
452
|
+
# Passes if `self.include?(object)`.
|
453
|
+
#
|
454
|
+
# @raise IncludeAssay
|
455
|
+
#
|
456
|
+
def wont_include(object, msg=nil)
|
457
|
+
IncludeAssay.refute!(self, object, :message=>msg, :backtrace=>caller)
|
458
|
+
end
|
459
|
+
|
460
|
+
#
|
461
|
+
# Passes if output matches +pattern+.
|
462
|
+
#
|
463
|
+
# @example
|
464
|
+
# proc{ puts "fun!" }.must_output('fun!')
|
465
|
+
#
|
466
|
+
# @raise OutputAssay
|
467
|
+
#
|
468
|
+
def must_output(pattern, msg=nil)
|
469
|
+
OutputAssay.assert!(pattern, :message=>msg, :backtrace=>caller, &self)
|
470
|
+
end
|
471
|
+
|
472
|
+
end
|
473
|
+
|
474
|
+
end
|