assay 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +7 -0
  3. data/HISTORY.md +128 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +287 -0
  6. data/demo/ae/01_overview.md +98 -0
  7. data/demo/ae/03_assert.md +398 -0
  8. data/demo/ae/04_subjunctive.md +100 -0
  9. data/demo/ae/05_expect.md +136 -0
  10. data/demo/ae/06_counts.md +33 -0
  11. data/demo/ae/07_matchers.md +34 -0
  12. data/demo/ae/08_check.md +61 -0
  13. data/demo/ae/09_assay.md +124 -0
  14. data/demo/ae/applique/setup.rb +11 -0
  15. data/{test → demo/applique}/helper.rb +8 -2
  16. data/demo/applique/setup.rb +1 -0
  17. data/demo/bang/01_bang.md +220 -0
  18. data/demo/core/00_introduction.md +2 -0
  19. data/demo/core/01_assay_classes/00_introduction.md +2 -0
  20. data/demo/core/01_assay_classes/01_nil_assay.md +35 -0
  21. data/demo/core/01_assay_classes/02_boolean_assay.md +35 -0
  22. data/demo/core/01_assay_classes/03_false_assay.md +19 -0
  23. data/demo/core/01_assay_classes/03_true_assay.md +20 -0
  24. data/demo/core/01_assay_classes/04_like_assay.md +19 -0
  25. data/demo/core/01_assay_classes/05_equal_assay.md +19 -0
  26. data/demo/core/01_assay_classes/06_unequal_assay.md +35 -0
  27. data/demo/core/01_assay_classes/07_equality_assay.md +19 -0
  28. data/demo/core/01_assay_classes/08_identity_assay.md +24 -0
  29. data/demo/core/01_assay_classes/09_case_assay.md +22 -0
  30. data/demo/core/01_assay_classes/10_match_assay.md +15 -0
  31. data/demo/core/01_assay_classes/11_nomatch_assay.md +16 -0
  32. data/demo/core/01_assay_classes/12_compare_assay.md +24 -0
  33. data/demo/core/01_assay_classes/13_less_assay.md +29 -0
  34. data/demo/core/01_assay_classes/14_more_assay.md +29 -0
  35. data/demo/core/01_assay_classes/15_less_equal_assay.md +30 -0
  36. data/demo/core/01_assay_classes/16_more_equal_assay.md +29 -0
  37. data/demo/core/01_assay_classes/17_close_assay.md +42 -0
  38. data/demo/core/01_assay_classes/17_within_assay.md +42 -0
  39. data/demo/core/01_assay_classes/18_kind_assay.md +17 -0
  40. data/demo/core/01_assay_classes/19_instance_assay.md +16 -0
  41. data/demo/core/01_assay_classes/20_include_assay.md +17 -0
  42. data/demo/core/01_assay_classes/21_empty_assay.md +15 -0
  43. data/demo/core/01_assay_classes/22_respond_assay.md +15 -0
  44. data/demo/core/01_assay_classes/23_execution_assay.md +40 -0
  45. data/demo/core/01_assay_classes/23_return_assay.md +37 -0
  46. data/demo/core/01_assay_classes/24_rescue_assay.md +40 -0
  47. data/demo/core/01_assay_classes/25_raise_assay.md +40 -0
  48. data/demo/core/01_assay_classes/26_throw_assay.md +47 -0
  49. data/demo/core/01_assay_classes/27_path_assay.md +20 -0
  50. data/demo/core/01_assay_classes/28_directory_assay.md +21 -0
  51. data/demo/core/01_assay_classes/29_file_assay.md +20 -0
  52. data/demo/core/01_assay_classes/30_output_assay.md +39 -0
  53. data/demo/core/01_assay_classes/31_stdout_assay.md +21 -0
  54. data/demo/core/01_assay_classes/32_stderr_assay.md +21 -0
  55. data/demo/core/02_lookup.md +25 -0
  56. data/demo/core/03_assertor.md +117 -0
  57. data/demo/core/04_assay.md +40 -0
  58. data/demo/fluidity/00_intro.md +7 -0
  59. data/demo/fluidity/01_should.md +52 -0
  60. data/demo/fluidity/02_must.md +58 -0
  61. data/demo/fluidity/03_assert.md +71 -0
  62. data/demo/fluidity/04_other.md +35 -0
  63. data/demo/fluidity/05_object_methods.md +102 -0
  64. data/demo/minitest/01_minitest_extensions.rdoc +217 -0
  65. data/demo/minitest/02_minitest_assertions.rdoc +250 -0
  66. data/demo/rspec/00_introduction.md +16 -0
  67. data/demo/rspec/01_should.md +24 -0
  68. data/demo/rspec/02_matchers.md +176 -0
  69. data/demo/rspec/03_have.md +51 -0
  70. data/demo/rspec/04_expect.md +49 -0
  71. data/demo/rspec/applique/setup.rb +2 -0
  72. data/demo/testunit/01_testunit_assertions.md +266 -0
  73. data/lib/assay/adapter/minitest.rb +32 -21
  74. data/lib/assay/adapter/testunit.rb +31 -38
  75. data/lib/assay/ae/assert.rb +77 -0
  76. data/lib/assay/ae/assertor.rb +453 -0
  77. data/lib/assay/ae/check.rb +154 -0
  78. data/lib/assay/ae/core_ext.rb +146 -0
  79. data/lib/assay/ae/expect.rb +72 -0
  80. data/lib/assay/ae/must.rb +64 -0
  81. data/lib/assay/ae/should.rb +58 -0
  82. data/lib/assay/ae/subjunctive.rb +66 -0
  83. data/lib/assay/ae.rb +29 -0
  84. data/lib/assay/assertable.rb +21 -5
  85. data/lib/assay/assertor.rb +4 -4
  86. data/lib/assay/bang.rb +147 -0
  87. data/lib/assay/close_assay.rb +2 -2
  88. data/lib/assay/core_ext/kernel.rb +4 -8
  89. data/lib/assay/fluidity/assert.rb +27 -0
  90. data/lib/assay/fluidity/grammar.rb +157 -0
  91. data/lib/assay/fluidity/is.rb +18 -0
  92. data/lib/assay/fluidity/must.rb +38 -0
  93. data/lib/assay/fluidity/should.rb +32 -0
  94. data/lib/assay/fluidity/will.rb +36 -0
  95. data/lib/assay/fluidity.rb +6 -0
  96. data/lib/assay/less_assay.rb +7 -1
  97. data/lib/assay/less_equal_assay.rb +7 -1
  98. data/lib/assay/minitest/assertions.rb +495 -0
  99. data/lib/assay/minitest/extensions.rb +496 -0
  100. data/lib/assay/minitest.rb +24 -0
  101. data/lib/assay/more_assay.rb +7 -1
  102. data/lib/assay/more_equal_assay.rb +7 -1
  103. data/lib/assay/rspec/expect.rb +151 -0
  104. data/lib/assay/rspec/have.rb +201 -0
  105. data/lib/assay/rspec/matchers.rb +272 -0
  106. data/lib/assay/rspec/operatics.rb +60 -0
  107. data/lib/assay/rspec/should.rb +49 -0
  108. data/lib/assay/rspec.rb +13 -0
  109. data/lib/assay/testunit/assertions.rb +484 -0
  110. data/lib/assay/testunit.rb +9 -0
  111. data/lib/assay/version.rb +3 -0
  112. data/lib/assay.rb +7 -21
  113. metadata +211 -80
  114. data/.ruby +0 -51
  115. data/COPYING.rdoc +0 -38
  116. data/HISTORY.rdoc +0 -65
  117. data/QED.rdoc +0 -1143
  118. data/README.rdoc +0 -173
  119. data/lib/assay.yml +0 -51
  120. data/test/case_compare_assay.rb +0 -59
  121. data/test/case_empty_assay.rb +0 -51
  122. data/test/case_equal_assay.rb +0 -53
  123. data/test/case_equality_assay.rb +0 -55
  124. data/test/case_false_assay.rb +0 -48
  125. data/test/case_identity_assay.rb +0 -51
  126. data/test/case_include_assay.rb +0 -51
  127. data/test/case_instance_assay.rb +0 -51
  128. data/test/case_kind_assay.rb +0 -51
  129. data/test/case_less_assay.rb +0 -53
  130. data/test/case_less_equal_assay.rb +0 -53
  131. data/test/case_like_assay.rb +0 -57
  132. data/test/case_match_assay.rb +0 -45
  133. data/test/case_more_assay.rb +0 -53
  134. data/test/case_more_equal_assay.rb +0 -53
  135. data/test/case_nil_assay.rb +0 -48
  136. data/test/case_nomatch_assay.rb +0 -47
  137. data/test/case_raise_assay.rb +0 -51
  138. data/test/case_respond_assay.rb +0 -51
  139. data/test/case_throw_assay.rb +0 -51
  140. data/test/case_true_assay.rb +0 -48
  141. data/test/case_unequal_assay.rb +0 -55
  142. data/test/case_within_assay.rb +0 -61
@@ -0,0 +1,496 @@
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 absolute delta tolerance.
76
+ #
77
+ # 0.05.must_be_within_delta (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 NOT equal within absolute delta tolerance.
87
+ #
88
+ # 0.05.wont_be_within_delta (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 expected and actual are equal within relative epsilon tolerance.
98
+ #
99
+ # 0.05.must_be_within_epsilon (50000.0 / 10**6), 0.00001
100
+ #
101
+ # @raise CloseAssay
102
+ #
103
+ def must_be_within_epsilon(exp, epsilon, msg=nil)
104
+ CloseAssay.assert!(self, exp, epsilon, :message=>msg, :backtrace=>caller)
105
+ end
106
+
107
+ #
108
+ # Passes if expected and actual are NOT equal within relative epsilon tolerance.
109
+ #
110
+ # 0.05.wont_be_within_epsilon (50000.0 / 10**6), 0.00001
111
+ #
112
+ # @raise CloseAssay
113
+ #
114
+ def wont_be_within_epsilon(exp, epsilon, msg=nil)
115
+ WithinAssay.refute!(self, exp, epsilon, :message=>msg, :backtrace=>caller)
116
+ end
117
+
118
+ #
119
+ # Passes if object is empty.
120
+ #
121
+ # object.must_be_empty
122
+ #
123
+ # @raise EmptyAssay
124
+ #
125
+ def must_be_empty(msg=nil)
126
+ EmptyAssay.assert!(self, :message=>msg, :backtrace=>caller)
127
+ end
128
+
129
+ #
130
+ # Passes if object is not empty.
131
+ #
132
+ # object.wont_be_empty
133
+ #
134
+ # @raise EmptyAssay
135
+ #
136
+ def wont_be_empty(msg=nil)
137
+ EmptyAssay.refute!(self, :message=>msg, :backtrace=>caller)
138
+ end
139
+
140
+ #
141
+ # Passes if expected == +actual.
142
+ #
143
+ # Note that the ordering of arguments is important,
144
+ # since a helpful error message is generated when this
145
+ # one fails that tells you the values of expected and actual.
146
+ #
147
+ # 'MY STRING'.must_equal('my string'.upcase)
148
+ #
149
+ # @raise EqualAssay
150
+ #
151
+ def must_equal(exp, msg=nil)
152
+ EqualAssay.assert!(self, exp, :message=>msg, :backtrace=>caller)
153
+ end
154
+
155
+ #
156
+ # Passes if expected != actual
157
+ #
158
+ # 'some string'.wont_equal('some other string')
159
+ #
160
+ # @raise EqualAssay
161
+ #
162
+ def wont_equal(exp, msg=nil)
163
+ EqualAssay.refute!(self, exp, :message=>msg, :backtrace=>caller)
164
+ end
165
+
166
+ #
167
+ # Passes if method call returns successfully.
168
+ #
169
+ # "string".must_send([:upcase], "Doesn't upcase!")
170
+ #
171
+ # @raise ExecutionAssay
172
+ #
173
+ def must_send(send_array, msg=nil)
174
+ ExecutionAssay.assert!(:message=>msg, :backtrace=>caller) do
175
+ self.__send__(*send_array)
176
+ end
177
+ end
178
+
179
+ #
180
+ # Passes if method call does not return successfully.
181
+ #
182
+ # "string".wont_send([:upcase], "Damn you, Uppercase!")
183
+ #
184
+ # @raise ExecutionAssay
185
+ #
186
+ def wont_send(send_array, msg=nil)
187
+ ExecutionAssay.refute!(:message=>msg, :backtrace=>caller) do
188
+ self.__send__(*send_array)
189
+ end
190
+ end
191
+
192
+ #
193
+ # Passes if the block yields successfully.
194
+ #
195
+ # 5.must_satisfy{ |x| x > 3 }
196
+ #
197
+ # @raise ExecutionAssay
198
+ #
199
+ def must_satisfy(msg=nil, &block)
200
+ ExecutionAssay.assert!(self, :message=>msg, :backtrace=>caller, &block)
201
+ end
202
+
203
+ #
204
+ # Passes if the block does not yield successfully.
205
+ #
206
+ # 5.wont_satisfy{ |x| x < 3 }
207
+ #
208
+ # @raise ExecutionAssay
209
+ #
210
+ def wont_satisfy(msg=nil, &block)
211
+ ExecutionAssay.refute!(self, :message=>msg, :backtrace=>caller, &block)
212
+ end
213
+
214
+ #
215
+ # Passed if object is +false+.
216
+ #
217
+ # @raise FalseAssay
218
+ #
219
+ def must_be_false(msg=nil)
220
+ FalseAssay.assert!(self, :message=>msg, :backtrace=>caller)
221
+ end
222
+
223
+ #
224
+ # Passed if object is not +false+.
225
+ #
226
+ # assert_not_false(false)
227
+ #
228
+ # @raise FalseAssay
229
+ #
230
+ def wont_be_false(msg=nil)
231
+ FalseAssay.refute!(self, :message=>msg, :backtrace=>caller)
232
+ end
233
+
234
+ #
235
+ # Passes if `self` is the same exact object as expected.
236
+ #
237
+ # object.must_be_same_as(object)
238
+ #
239
+ # @raise IdentityAssay
240
+ #
241
+ def must_be_same_as(exp, msg=nil)
242
+ IdentityAssay.assert!(self, exp, :message=>msg, :backtrace=>caller)
243
+ end
244
+
245
+ #
246
+ # Passes if actual is not the same exact object as expected.
247
+ #
248
+ # object.wont_be_same_as(other)
249
+ #
250
+ # @raise IdentityAssay
251
+ #
252
+ def wont_be_same_as(exp, msg=nil)
253
+ IdentityAssay.refute!(self, exp, :message=>msg, :backtrace=>caller)
254
+ end
255
+
256
+ #
257
+ # Passes if object is an instance of class.
258
+ #
259
+ # 'foo'.must_be_instance_of(String)
260
+ #
261
+ # @raise InstanceAssay
262
+ #
263
+ def must_be_instance_of(cls, msg=nil)
264
+ InstanceAssay.assert!(self, cls, :message=>msg, :backtrace=>caller)
265
+ end
266
+
267
+ #
268
+ # Passes if object is not an instance of class.
269
+ #
270
+ # 'foo'.wont_be_instance_of(Integer)
271
+ #
272
+ # @raise InstanceAssay
273
+ #
274
+ def wont_be_instance_of(cls, msg=nil)
275
+ InstanceAssay.refute!(self, cls, :message=>msg, :backtrace=>caller)
276
+ end
277
+
278
+ #
279
+ # Passes if object is a kind of class.
280
+ #
281
+ # assert_kind_of(Object, 'foo')
282
+ #
283
+ # @raise KindAssay
284
+ #
285
+ def must_be_kind_of(cls, msg=nil)
286
+ KindAssay.assert!(self, cls, :message=>msg, :backtrace=>caller)
287
+ end
288
+
289
+ #
290
+ # Passes if object is not a kind of class.
291
+ #
292
+ # assert_not_kind_of(Object, 'foo')
293
+ #
294
+ # @raise KindAssay
295
+ #
296
+ def wont_be_kind_of(cls, msg=nil)
297
+ KindAssay.refute!(self, cls, :message=>msg, :backtrace=>caller)
298
+ end
299
+
300
+ #
301
+ # Passes if object matches pattern using `#=~` method.
302
+ #
303
+ # 'one 2 three'.must_match(/two/)
304
+ #
305
+ # @raise MatchAssay
306
+ #
307
+ def must_match(exp, msg=nil)
308
+ MatchAssay.assert!(self, exp, :message=>msg, :backtrace=>caller)
309
+ end
310
+
311
+ #
312
+ # Passes if object does not match pattern using `#=~` method.
313
+ #
314
+ # 'one 2 three'.wont_match(/two/)
315
+ #
316
+ # @raise MatchAssay
317
+ #
318
+ def wont_match(exp, msg=nil)
319
+ MatchAssay.refute!(self, exp, :message=>msg, :backtrace=>caller)
320
+ end
321
+
322
+ #
323
+ # Passed if object is +nil+.
324
+ #
325
+ # @raise NilAssay
326
+ #
327
+ def must_be_nil(msg=nil)
328
+ NilAssay.assert!(self, :message=>msg, :backtrace=>caller)
329
+ end
330
+
331
+ #
332
+ # Passed if object is not +nil+.
333
+ #
334
+ # assert_not_nil(true)
335
+ #
336
+ # @raise NilAssay
337
+ #
338
+ def wont_be_nil(msg=nil)
339
+ NilAssay.refute!(self, :message=>msg, :backtrace=>caller)
340
+ end
341
+
342
+ #
343
+ # Passes if the procedure raises a given exception.
344
+ #
345
+ # lambda{ raise 'Boom!!!' }.must_raise(RuntimeError)
346
+ #
347
+ # @raise RaiseAssay
348
+ #
349
+ def must_raise(exp, msg=nil, call=nil)
350
+ RaiseAssay.assert!(exp, :message=>msg, :backtrace=>(call || caller), &self)
351
+ end
352
+
353
+ #
354
+ # Passes if the procedure *does not* raise a given exceptions.
355
+ #
356
+ # lambda{ raise 'Boom!!!' }.wont_raise(IOError)
357
+ #
358
+ # @raise RaiseAssay
359
+ #
360
+ def wont_raise(exp, msg=nil, call=nil)
361
+ RaiseAssay.refute!(exp, :message=>msg, :backtrace=>(call || caller), &self)
362
+ end
363
+
364
+ #
365
+ # Passes if +object+ respond_to? +methods+.
366
+ #
367
+ # 'bugbear'.must_respond_to(:slice)
368
+ #
369
+ # @raise RespondAssay
370
+ #
371
+ def must_respond_to(method, msg=nil)
372
+ RespondAssay.assert!(self, method, :message=>msg, :backtrace=>caller)
373
+ end
374
+
375
+ #
376
+ # Passes if +object+ does not respond_to? +methods+.
377
+ #
378
+ # 'bugbear'.wont_respond_to(:slice)
379
+ #
380
+ # @raise RespondAssay
381
+ #
382
+ def wont_respond_to(method, msg=nil)
383
+ RespondAssay.refute!(self, method, :message=>msg, :backtrace=>caller)
384
+ end
385
+
386
+ #
387
+ # Passes if `criterion.eql?(actual)`.
388
+ #
389
+ # Note that the ordering of arguments is important,
390
+ # since a helpful error message is generated when this
391
+ # one fails that tells you the values of expected and actual.
392
+ #
393
+ # 'MY STRING'.must_be_equivalent_to('my string'.upcase)
394
+ #
395
+ # @raise EqualityAssay
396
+ #
397
+ def must_be_equivalent_to(criterion, msg=nil)
398
+ EqualityAssay.assert!(self, criterion, :message=>msg, :backtrace=>caller)
399
+ end
400
+
401
+ alias_method :must_eql, :must_be_equivalent_to
402
+
403
+ #
404
+ # Passes if NOT `criterion.eql?(actual)`.
405
+ #
406
+ # 'MY STRING'.wont_be_equivalent_to('some other string')
407
+ #
408
+ # @raise EqualityAssay
409
+ #
410
+ def wont_be_equivalent_to(criterion, msg=nil)
411
+ EqualityAssay.refute!(self, criterion, :message=>msg, :backtrace=>caller)
412
+ end
413
+
414
+ alias_method :wont_eql, :wont_be_equivalent_to
415
+
416
+ #
417
+ # Passes if the block throws expected_symbol
418
+ #
419
+ # assert_throws :done do
420
+ # throw :done
421
+ # end
422
+ #
423
+ # @raise ThrowAssay
424
+ #
425
+ def must_throw(sym, msg=nil)
426
+ ThrowAssay.assert!(sym, :message=>msg, :backtrace=>caller, &self)
427
+ end
428
+
429
+ #
430
+ # Passes if the block throws expected_symbol
431
+ #
432
+ # refute_throws :done do
433
+ # throw :chimp
434
+ # end
435
+ #
436
+ # @raise ThrowAssay
437
+ #
438
+ def wont_throw(sym, msg=nil)
439
+ ThrowAssay.refute!(sym, :message=>msg, :backtrace=>caller, &self)
440
+ end
441
+
442
+ #
443
+ # Passed if object is +true+.
444
+ #
445
+ # object.must_be_true
446
+ #
447
+ # @raise TrueAssay
448
+ #
449
+ def must_be_true(msg=nil)
450
+ TrueAssay.assert!(self, :message=>msg, :backtrace=>caller)
451
+ end
452
+
453
+ #
454
+ # Passed if object is not +true+.
455
+ #
456
+ # object.wont_be_true
457
+ #
458
+ # @raise TrueAssay
459
+ #
460
+ def wont_be_true(msg=nil)
461
+ TrueAssay.refute!(self, :message=>msg, :backtrace=>caller)
462
+ end
463
+
464
+ #
465
+ # Passes if `self.include?(object)`.
466
+ #
467
+ # @raise IncludeAssay
468
+ #
469
+ def must_include(object, msg=nil)
470
+ IncludeAssay.assert!(self, object, :message=>msg, :backtrace=>caller)
471
+ end
472
+
473
+ #
474
+ # Passes if `self.include?(object)`.
475
+ #
476
+ # @raise IncludeAssay
477
+ #
478
+ def wont_include(object, msg=nil)
479
+ IncludeAssay.refute!(self, object, :message=>msg, :backtrace=>caller)
480
+ end
481
+
482
+ #
483
+ # Passes if output matches +pattern+.
484
+ #
485
+ # @example
486
+ # proc{ puts "fun!" }.must_output('fun!')
487
+ #
488
+ # @raise OutputAssay
489
+ #
490
+ def must_output(pattern, msg=nil)
491
+ OutputAssay.assert!(pattern, :message=>msg, :backtrace=>caller, &self)
492
+ end
493
+
494
+ end
495
+
496
+ end
@@ -0,0 +1,24 @@
1
+ require_relative '../assay'
2
+
3
+ require_relative 'minitest/assertions'
4
+ require_relative 'minitest/extensions'
5
+
6
+ module Assay
7
+ # `Minitest` is how the framework spells its name now.
8
+ Minitest = MiniTest unless const_defined?(:Minitest, false)
9
+ end
10
+
11
+ # Minitest-compatible assertion methods (`assert_equal`, ...), to mix
12
+ # into a test scope.
13
+ module Assay::Assertions
14
+ include Assay::MiniTest::Assertions
15
+ end
16
+
17
+ # Minitest-compatible expectation methods (`must_equal`, ...).
18
+ module Assay::Extensions
19
+ include Assay::MiniTest::Extensions
20
+ end
21
+
22
+ class Object
23
+ include Assay::Extensions
24
+ end
@@ -14,5 +14,11 @@ class MoreAssay < CompareAssay
14
14
  subject > criterion
15
15
  end
16
16
 
17
- end
17
+ #
18
+ # Error message, e.g. `5 > 3`.
19
+ #
20
+ def self.assert_message(subject, criterion)
21
+ standard_message(subject, criterion)
22
+ end
18
23
 
24
+ end
@@ -21,5 +21,11 @@ class MoreEqualAssay < CompareAssay
21
21
  subject >= criterion
22
22
  end
23
23
 
24
- end
24
+ #
25
+ # Error message, e.g. `5 >= 3`.
26
+ #
27
+ def self.assert_message(subject, criterion)
28
+ standard_message(subject, criterion)
29
+ end
25
30
 
31
+ end
@@ -0,0 +1,151 @@
1
+ module Assay::RSpec
2
+
3
+ # Wraps the target of an expectation.
4
+ #
5
+ # @example
6
+ # expect(something) # => Expect
7
+ #
8
+ # # used with `to`
9
+ # expect(actual).to eq(3)
10
+ #
11
+ # # with `to_not`
12
+ # expect(actual).to_not eq(3)
13
+ #
14
+ class Expect
15
+
16
+ # @api private
17
+ def initialize(target)
18
+ @target = target
19
+ end
20
+
21
+ # Runs the given expectation, passing if `matcher` returns true.
22
+ #
23
+ # @example
24
+ # expect(value).to eq(5)
25
+ # expect { perform }.to raise_error
26
+ #
27
+ # @param [Matcher]
28
+ # matcher
29
+ #
30
+ # @param [String] message optional message to display when the expectation fails
31
+ #
32
+ # @return [Boolean] true if the expectation succeeds (else raises)
33
+ #
34
+ # @see RSpec::Matchers
35
+ #
36
+ def to(matcher=nil, message=nil, &block)
37
+ #prevent_operator_matchers(:to, matcher)
38
+ handle_positive_matcher(@target, matcher, message, &block)
39
+ end
40
+
41
+ # Runs the given expectation, passing if `matcher` returns false.
42
+ #
43
+ # @example
44
+ # expect(value).to_not eq(5)
45
+ # expect(value).not_to eq(5)
46
+ #
47
+ # @param [Matcher]
48
+ # matcher
49
+ #
50
+ # @param [String] message optional message to display when the expectation fails
51
+ #
52
+ # @return [Boolean] false if the negative expectation succeeds (else raises)
53
+ #
54
+ # @see RSpec::Matchers
55
+ #
56
+ def to_not(matcher=nil, message=nil, &block)
57
+ #prevent_operator_matchers(:to_not, matcher)
58
+ handle_negative_matcher(@target, matcher, message, &block)
59
+ end
60
+
61
+ alias :not_to :to_not
62
+
63
+ private
64
+
65
+ #def prevent_operator_matchers(verb, matcher)
66
+ # return if matcher
67
+ #
68
+ # raise ArgumentError, "The expect syntax does not support operator matchers, " +
69
+ # "so you must pass a matcher to `##{verb}`."
70
+ #end
71
+
72
+ #
73
+ # @todo how to customize the message?
74
+ #
75
+ def handle_positive_matcher(actual, matcher, message=nil, &block)
76
+ check_message(message)
77
+
78
+ #::RSpec::Matchers.last_should = :should
79
+ #::RSpec::Matchers.last_matcher = matcher
80
+
81
+ if block
82
+ actual = block.call(actual)
83
+ end
84
+
85
+ #return ::RSpec::Matchers::BuiltIn::PositiveOperatorMatcher.new(actual) if matcher.nil?
86
+
87
+ return Operatics.new(actual) if matcher.nil?
88
+
89
+ matcher =~ actual
90
+
91
+ #match = matcher.matches?(actual, &block)
92
+ #return match if match
93
+
94
+ #message ||= matcher.respond_to?(:failure_message_for_should) ?
95
+ # matcher.failure_message_for_should :
96
+ # matcher.failure_message
97
+
98
+ #if matcher.respond_to?(:diffable?) && matcher.diffable?
99
+ # ::RSpec::Expectations.fail_with message, matcher.expected, matcher.actual
100
+ #else
101
+ # ::RSpec::Expectations.fail_with message
102
+ #end
103
+ end
104
+
105
+ #
106
+ # @todo how to customize the message?
107
+ #
108
+ def handle_negative_matcher(actual, matcher, message=nil, &block)
109
+ check_message(message)
110
+
111
+ #::RSpec::Matchers.last_should = :should_not
112
+ #::RSpec::Matchers.last_matcher = matcher
113
+
114
+ if block
115
+ actual = block.call(actual)
116
+ end
117
+
118
+ #return ::RSpec::Matchers::BuiltIn::NegativeOperatorMatcher.new(actual) if matcher.nil?
119
+
120
+ return Operatics.new(actual, true) if matcher.nil?
121
+
122
+ matcher !~ actual
123
+
124
+ #match = matcher.respond_to?(:does_not_match?) ?
125
+ # !matcher.does_not_match?(actual, &block) :
126
+ # matcher.matches?(actual, &block)
127
+ #return match unless match
128
+
129
+ #message ||= matcher.respond_to?(:failure_message_for_should_not) ?
130
+ # matcher.failure_message_for_should_not :
131
+ # matcher.negative_failure_message
132
+
133
+ #if matcher.respond_to?(:diffable?) && matcher.diffable?
134
+ # ::RSpec::Expectations.fail_with message, matcher.expected, matcher.actual
135
+ #else
136
+ # ::RSpec::Expectations.fail_with message
137
+ #end
138
+ end
139
+
140
+ def message_must_be_string(msg)
141
+ "WARNING: ignoring the provided expectation message argument " +
142
+ "(#{msg.inspect}) since it is not a string."
143
+ end
144
+
145
+ def check_message(msg)
146
+ ::Kernel.warn message_must_be_string(msg) unless msg.nil? || msg.is_a?(String)
147
+ end
148
+
149
+ end
150
+
151
+ end