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
data/QED.rdoc DELETED
@@ -1,1143 +0,0 @@
1
- Assay is an foundational assertion framework.
2
-
3
-
4
- # Assay Classes
5
-
6
-
7
- ## NilAssay
8
-
9
- The `NilAssay` asserts that an object reference is `nil`.
10
- Reference to any other object will fail.
11
-
12
- assert NilAssay.pass?(nil)
13
-
14
- refute NilAssay.pass?(true)
15
- refute NilAssay.pass?(false)
16
- refute NilAssay.pass?("foo")
17
-
18
- And conversely,
19
-
20
- assert NilAssay.fail?(true)
21
- assert NilAssay.fail?(false)
22
- assert NilAssay.fail?("foo")
23
-
24
- refute NilAssay.fail?(nil)
25
-
26
- Making assertions,
27
-
28
- assert NilAssay.assert!(nil)
29
-
30
- expect ::NilAssay do
31
- NilAssay.assert!(true)
32
- end
33
-
34
- And refutations,
35
-
36
- assert NilAssay.refute!(true)
37
-
38
- expect ::NilAssay do
39
- NilAssay.refute!(nil)
40
- end
41
-
42
-
43
- ## BooleanAssay
44
-
45
- The `BooleanAssay` asserts that an object reference is `nil`.
46
- Reference to any other object will fail.
47
-
48
- assert BooleanAssay.pass?(true)
49
- assert BooleanAssay.pass?(false)
50
-
51
- refute BooleanAssay.pass?(nil)
52
- refute BooleanAssay.pass?("foo")
53
-
54
- And conversely,
55
-
56
- assert BooleanAssay.fail?(nil)
57
- assert BooleanAssay.fail?("foo")
58
-
59
- refute BooleanAssay.fail?(true)
60
- refute BooleanAssay.fail?(false)
61
-
62
- Making assertions,
63
-
64
- assert BooleanAssay.assert!(true)
65
-
66
- expect ::BooleanAssay do
67
- BooleanAssay.assert!(nil)
68
- end
69
-
70
- And refutations,
71
-
72
- assert BooleanAssay.refute!(nil)
73
-
74
- expect ::BooleanAssay do
75
- BooleanAssay.refute!(true)
76
- end
77
-
78
-
79
- ## FalseAssay
80
-
81
- The `FalseAssay` class asserts that an object is `false.
82
- Reference to any other object will fail.
83
-
84
- assert FalseAssay.pass?(false)
85
-
86
- refute FalseAssay.pass?(true)
87
- refute FalseAssay.pass?(nil)
88
- refute FalseAssay.pass?('foo')
89
-
90
- And conversely,
91
-
92
- assert FalseAssay.fail?(true)
93
- assert FalseAssay.fail?(nil)
94
- assert FalseAssay.fail?('foo')
95
-
96
- refute FalseAssay.fail?(false)
97
-
98
-
99
- ## TrueAssay
100
-
101
- The `TrueAssay` class asserts that an object is `true`.
102
- Reference to any other object will fail.
103
-
104
- assert TrueAssay.pass?(true)
105
-
106
- refute TrueAssay.pass?(false)
107
- refute TrueAssay.pass?(nil)
108
- refute TrueAssay.pass?('foo')
109
-
110
- And conversely,
111
-
112
- assert TrueAssay.fail?(false)
113
- assert TrueAssay.fail?(nil)
114
- assert TrueAssay.fail?('foo')
115
-
116
- refute TrueAssay.fail?(true)
117
-
118
-
119
-
120
- ## LikeAssay
121
-
122
- The `LikeAssay` is a very ... assertion. It is a comparison that
123
- evaluates to true for any of Ruby's many "equal" operators, `equal?`
124
- (same as `identical?`), `eql?`, `==`, `===` and `=~`. If any one
125
- of these evaluates to true, than two objects can be said to be alike.
126
-
127
- assert LikeAssay.pass?(1, 1)
128
- assert LikeAssay.pass?(1, 1.0)
129
- assert LikeAssay.pass?("1", /\d/)
130
-
131
- refute LikeAssay.pass?(1, "1")
132
- refute LikeAssay.pass?("1", /\D/)
133
-
134
- And conversely,
135
-
136
- assert LikeAssay.fail?(1, "1")
137
- assert LikeAssay.fail?("1", /\D/)
138
-
139
-
140
- ## EqualAssay
141
-
142
- The `EqualAssay` class defines an assertion for equality based on the `==` method.
143
-
144
- assert EqualAssay.pass?(1, 1)
145
- assert EqualAssay.pass?(1, 1.0)
146
-
147
- refute EqualAssay.pass?(1, 2)
148
- refute EqualAssay.pass?(1, 'foo')
149
-
150
- And conversely,
151
-
152
- assert EqualAssay.fail?(1, 2)
153
- assert EqualAssay.fail?(1, 'foo')
154
-
155
- refute EqualAssay.fail?(1, 1)
156
- refute EqualAssay.fail?(1, 1.0)
157
-
158
-
159
-
160
- ## UnequalAssay
161
-
162
- The `UnequalAssay` class defines an assertion for equality based on the `!=`
163
- method, which in Ruby 1.8 is a redefinable method all it's own.
164
-
165
- assert UnequalAssay.pass?(1, 2)
166
- assert UnequalAssay.pass?(1, 'foo')
167
-
168
- refute UnequalAssay.pass?(1, 1)
169
- refute UnequalAssay.pass?(1, 1.0)
170
-
171
- And conversely,
172
-
173
- assert UnequalAssay.fail?(1, 1)
174
- assert UnequalAssay.fail?(1, 1.0)
175
-
176
- refute UnequalAssay.fail?(1, 2)
177
- refute UnequalAssay.fail?(1, 'foo')
178
-
179
- Making assertions,
180
-
181
- assert UnequalAssay.assert!(10, 20)
182
-
183
- expect ::UnequalAssay do
184
- UnequalAssay.assert!(10, 10)
185
- end
186
-
187
- And refutations,
188
-
189
- assert UnequalAssay.refute!(10, 10)
190
-
191
- expect ::UnequalAssay do
192
- UnequalAssay.refute!(10, 20)
193
- end
194
-
195
-
196
- ## EqualityAssay
197
-
198
- The `EqualityAssay` class defines an assertion for strict equality via
199
- the `eql?` method.
200
-
201
- assert EqualityAssay.pass?(1, 1)
202
-
203
- refute EqualityAssay.pass?(1, 1.0)
204
- refute EqualityAssay.pass?(1, 2)
205
- refute EqualityAssay.pass?(1, 'foo')
206
-
207
- And conversely,
208
-
209
- assert EqualityAssay.fail?(1, 2)
210
- assert EqualityAssay.fail?(1, 1.0)
211
- assert EqualityAssay.fail?(1, 'foo')
212
-
213
- refute EqualityAssay.fail?(1, 1)
214
-
215
-
216
- ## IdentityAssay
217
-
218
- The `IdentityAssay` class defines an assertion for identity comparison via
219
- the `#identical?` method, which is an alias for the `#equal?` method.
220
- We have choosen not to use the term `equal` to avoid confusion with the
221
- ordinary `==` type of equality.
222
-
223
- assert IdentityAssay.pass?(1, 1)
224
- assert IdentityAssay.pass?(:a, :a)
225
-
226
- refute IdentityAssay.pass?('a', 'a')
227
- refute IdentityAssay.pass?(1, 1.0)
228
- refute IdentityAssay.pass?(1, 2)
229
- refute IdentityAssay.pass?(1, 'foo')
230
-
231
- And conversely,
232
-
233
- assert IdentityAssay.fail?(1, 2)
234
- assert IdentityAssay.fail?(1, 1.0)
235
- assert IdentityAssay.fail?(1, 'foo')
236
- assert IdentityAssay.fail?('a', 'a')
237
-
238
- refute IdentityAssay.fail?(1, 1)
239
- refute IdentityAssay.fail?(:a, :a)
240
-
241
- ## CaseAssay
242
-
243
- The `CaseAssay` class defines an assertion for case equality using the `#===`
244
- method.
245
-
246
- assert CaseAssay.pass?(1, 1)
247
- assert CaseAssay.pass?(1, 1.0)
248
- assert CaseAssay.pass?(/a/, 'a')
249
- assert CaseAssay.pass?(String, 'foo')
250
-
251
- refute CaseAssay.pass?(1, 2)
252
- refute CaseAssay.pass?(1, 'foo')
253
-
254
- And conversely,
255
-
256
- assert CaseAssay.fail?(1, 2)
257
- assert CaseAssay.fail?(1, 'foo')
258
-
259
- refute CaseAssay.fail?(1, 1)
260
- refute CaseAssay.fail?(1, 1.0)
261
- refute CaseAssay.fail?(/a/, 'a')
262
- refute CaseAssay.fail?(String, 'foo')
263
-
264
- ## MatchAssay
265
-
266
- The `MatchAssay` class defines an assertion for matching using the `#=~`
267
- method.
268
-
269
- assert MatchAssay.pass?('a', /a/)
270
-
271
- refute MatchAssay.pass?('a', /b/)
272
-
273
- And conversely,
274
-
275
- assert MatchAssay.fail?('a', /b/)
276
-
277
- refute MatchAssay.fail?('a', /a/)
278
-
279
-
280
- ## NoMatchAssay
281
-
282
- The `NoMatchAssay` class defines an assertion for matching using the `#!~`
283
- method. As of Ruby 1.9, the `#!~` method is redefinable independent of `#=~`,
284
- so a separate assertion class is needed to cover it.
285
-
286
- assert NoMatchAssay.pass?('a', /b/)
287
-
288
- refute NoMatchAssay.pass?('a', /a/)
289
-
290
- And conversely,
291
-
292
- assert NoMatchAssay.fail?('a', /a/)
293
-
294
- refute NoMatchAssay.fail?('a', /b/)
295
-
296
-
297
- ## CompareAssay
298
-
299
- The `CompareAssay` class defines an assertion of comparison around the `#<=>`
300
- method. Since `#<=>` can return either a `1`, `0` or `-1`, an extra criterion
301
- is needed when making testing the assertion.
302
-
303
- assert CompareAssay.pass?(1, 1, 0)
304
- assert CompareAssay.pass?(1, 2, -1)
305
- assert CompareAssay.pass?(2, 1, 1)
306
-
307
- refute CompareAssay.pass?(1, 1, 1)
308
- refute CompareAssay.pass?(1, 1, -1)
309
-
310
- refute CompareAssay.pass?(1, 'foo', 0)
311
-
312
- And conversely,
313
-
314
- assert CompareAssay.fail?(1, 1, 1)
315
- assert CompareAssay.fail?(1, 1, -1)
316
-
317
- refute CompareAssay.fail?(1, 1, 0)
318
- refute CompareAssay.fail?(1, 2, -1)
319
- refute CompareAssay.fail?(2, 1, 1)
320
-
321
-
322
- ## LessAssay
323
-
324
- The `LessAssay` class defines an assertion of comparison around the `#<`
325
- method. This method usually depends on the `#<=>` method via Ruby's Comparable
326
- mixin, so `LessAssay` is a subclass of `ComapreAssay`, though techincally
327
- the `#<` method can be defined independently.
328
-
329
- assert LessAssay.pass?( 1, 2)
330
- assert LessAssay.pass?(-1, 0)
331
-
332
- refute LessAssay.pass?(1, 1)
333
- refute LessAssay.pass?(1, 0)
334
-
335
- And conversely,
336
-
337
- assert LessAssay.fail?(1, 1)
338
- assert LessAssay.fail?(1, 0)
339
-
340
- refute LessAssay.fail?( 1, 2)
341
- refute LessAssay.fail?(-1, 0)
342
-
343
- This applies to any type of object that defines `#<=`, not just numbers.
344
-
345
- assert LessAssay.pass?('a', 'b')
346
- refute LessAssay.pass?('b', 'a')
347
-
348
- assert LessAssay.fail?('b', 'a')
349
- refute LessAssay.fail?('a', 'b')
350
-
351
-
352
- ## MoreAssay
353
-
354
- The `MoreAssay` class defines an assertion of comparison around the `#>`
355
- method. This method usually depends on the `#<=>` method via Ruby's Comparable
356
- mixin, so `MoreAssay` is a subclass of `ComapreAssay`, though techincally
357
- the `#>` method can be defined indenpendently.
358
-
359
- assert MoreAssay.pass?(2, 1)
360
- assert MoreAssay.pass?(0, -1)
361
- assert MoreAssay.pass?(1, 0)
362
-
363
- refute MoreAssay.pass?(1, 1)
364
- refute MoreAssay.pass?(1, 2)
365
-
366
- And conversely,
367
-
368
- assert MoreAssay.fail?(1, 1)
369
- assert MoreAssay.fail?(0, 1)
370
-
371
- refute MoreAssay.fail?(2, 1)
372
- refute MoreAssay.fail?(0, -1)
373
-
374
- This applies to any type of object that defines `#>`, not just numbers.
375
-
376
- assert MoreAssay.pass?('b', 'a')
377
- refute MoreAssay.pass?('a', 'b')
378
-
379
- assert MoreAssay.fail?('a', 'b')
380
- refute MoreAssay.fail?('b', 'a')
381
-
382
- ## LessEqualAssay
383
-
384
- The `LessEqualAssay` class defines an assertion of comparison around the `#<=`
385
- method. This method usually depends on the `#<=>` method via Ruby's Comparable
386
- mixin, so `LessEqualAssay` is a subclass of `ComapreAssay`, though techincally
387
- the `#<=` method can be defined indenpendently.
388
-
389
- assert LessEqualAssay.pass?( 1, 2)
390
- assert LessEqualAssay.pass?(-1, 0)
391
- assert LessEqualAssay.pass?( 1, 1)
392
-
393
- refute LessEqualAssay.pass?(1, 0)
394
-
395
- And conversely,
396
-
397
- assert LessEqualAssay.fail?(1, 0)
398
-
399
- refute LessEqualAssay.fail?( 1, 1)
400
- refute LessEqualAssay.fail?( 1, 2)
401
- refute LessEqualAssay.fail?(-1, 0)
402
-
403
- This applies to any type of object that defines `#<=`, not just numbers.
404
-
405
- assert LessEqualAssay.pass?('a', 'b')
406
- refute LessEqualAssay.pass?('b', 'a')
407
-
408
- assert LessEqualAssay.fail?('b', 'a')
409
- refute LessEqualAssay.fail?('a', 'b')
410
-
411
-
412
-
413
- ## MoreEqualAssay
414
-
415
- The `MoreEqualAssay` class defines an assertion of comparison around the `#>=`
416
- method. This method usually depends on the `#<=>` method via Ruby's Comparable
417
- mixin, so `MoreEqualAssay` is a subclass of `ComapreAssay`, though techincally
418
- the `#>=` method can be defined indenpendently.
419
-
420
- assert MoreEqualAssay.pass?(2, 1)
421
- assert MoreEqualAssay.pass?(0, -1)
422
- assert MoreEqualAssay.pass?(1, 1)
423
-
424
- refute MoreEqualAssay.pass?(0, 1)
425
-
426
- And conversely,
427
-
428
- assert MoreEqualAssay.fail?(0, 1)
429
-
430
- refute MoreEqualAssay.fail?( 1, 1)
431
- refute MoreEqualAssay.fail?( 2, 1)
432
- refute MoreEqualAssay.fail?( 0, -1)
433
-
434
- This applies to any type of object that defines `#<=`, not just numbers.
435
-
436
- assert MoreEqualAssay.pass?('b', 'a')
437
- refute MoreEqualAssay.pass?('a', 'b')
438
-
439
- assert MoreEqualAssay.fail?('a', 'b')
440
- refute MoreEqualAssay.fail?('b', 'a')
441
-
442
-
443
- ## CloseAssay
444
-
445
- The `CloseAssay` class defines an assertion for matching that two values
446
- are within a relative difference.
447
-
448
- assert CloseAssay.pass?(1, 1, 0)
449
- assert CloseAssay.pass?(1, 1.1, 0.1)
450
-
451
- refute CloseAssay.pass?(1, 2, 0)
452
- refute CloseAssay.pass?(1, 1.2, 0.1)
453
-
454
- And conversely,
455
-
456
- assert CloseAssay.fail?(1, 2, 0)
457
- assert CloseAssay.fail?(1, 1.2, 0.1)
458
-
459
- refute CloseAssay.fail?(1, 1, 0)
460
- refute CloseAssay.fail?(1, 1.1, 0.1)
461
-
462
- The object do not have to be numbers necessaity, just so long as they
463
- are comparable and subtractable.
464
-
465
- time = Time.now
466
-
467
- assert CloseAssay.pass?(time, time+1, 2)
468
-
469
- Making assertions,
470
-
471
- assert CloseAssay.assert!(10, 11, 1)
472
-
473
- expect ::CloseAssay do
474
- CloseAssay.assert!(10, 15, 0.25)
475
- end
476
-
477
- And refutations,
478
-
479
- assert CloseAssay.refute!(10, 11, 0.01)
480
-
481
- expect ::CloseAssay do
482
- CloseAssay.refute!(10, 11, 1)
483
- end
484
-
485
-
486
- ## WithinAssay
487
-
488
- The `WithinAssay` class defines an assertion for matching that two values
489
- lie with a range.
490
-
491
- assert WithinAssay.pass?(1, 1, 0)
492
- assert WithinAssay.pass?(1, 1.1, 0.1)
493
-
494
- refute WithinAssay.pass?(1, 2, 0)
495
- refute WithinAssay.pass?(1, 1.2, 0.1)
496
-
497
- And conversely,
498
-
499
- assert WithinAssay.fail?(1, 2, 0)
500
- assert WithinAssay.fail?(1, 1.2, 0.1)
501
-
502
- refute WithinAssay.fail?(1, 1, 0)
503
- refute WithinAssay.fail?(1, 1.1, 0.1)
504
-
505
- The object do not have to be numbers necessaity, just so long as they
506
- are comparable and subtractable.
507
-
508
- time = Time.now
509
-
510
- assert WithinAssay.pass?(time, time+1, 2)
511
-
512
- Making assertions,
513
-
514
- assert WithinAssay.assert!(10, 11, 1)
515
-
516
- expect ::WithinAssay do
517
- WithinAssay.assert!(10, 15, 2)
518
- end
519
-
520
- And refutations,
521
-
522
- assert WithinAssay.refute!(10, 11, 0.1)
523
-
524
- expect ::WithinAssay do
525
- WithinAssay.refute!(10, 11, 1)
526
- end
527
-
528
-
529
- ## KindAssay
530
-
531
- The `KindAssay` asserts that an object is a class or any ancestor
532
- of that class.
533
-
534
- assert KindAssay.pass?(1, Fixnum)
535
- assert KindAssay.pass?(1, Numeric)
536
-
537
- refute KindAssay.pass?(1, String)
538
-
539
- And conversely,
540
-
541
- assert KindAssay.fail?(1, String)
542
-
543
- refute KindAssay.fail?(1, Fixnum)
544
- refute KindAssay.fail?(1, Numeric)
545
-
546
-
547
- ## InstanceAssay
548
-
549
- The `InstanceAssay` asserts that an object is an instance of a specific class.
550
-
551
- assert InstanceAssay.pass?(1, Fixnum)
552
-
553
- refute InstanceAssay.pass?(1, Numeric)
554
- refute InstanceAssay.pass?(1, String)
555
-
556
- And conversely,
557
-
558
- assert InstanceAssay.fail?(1, String)
559
- assert InstanceAssay.fail?(1, Numeric)
560
-
561
- refute InstanceAssay.fail?(1, Fixnum)
562
-
563
-
564
- ## IncludeAssay
565
-
566
- The `IncludeAssay` asserts that a collection includes a specific member, using
567
- the `#include?` method.
568
-
569
- assert IncludeAssay.pass?([1], 1)
570
-
571
- refute IncludeAssay.pass?([], 1)
572
- refute IncludeAssay.pass?([2], 1)
573
-
574
- And conversely,
575
-
576
- assert IncludeAssay.fail?([], 1)
577
- assert IncludeAssay.fail?([2], 1)
578
-
579
- refute IncludeAssay.fail?([1], 1)
580
-
581
-
582
- ## EmptyAssay
583
-
584
- The `EmptyAssay` asserts that a collection includes no members, using the
585
- `#empty?` method.
586
-
587
- assert EmptyAssay.pass?([])
588
-
589
- refute EmptyAssay.pass?([1])
590
-
591
- And conversely,
592
-
593
- assert EmptyAssay.fail?([1])
594
-
595
- refute EmptyAssay.fail?([])
596
-
597
-
598
- ## RespondAssay
599
-
600
- The `RespondAssay` asserts if a an object responds to a message using
601
- then `#respond_to?` method.
602
-
603
- assert RespondAssay.pass?('a', :to_s)
604
-
605
- refute RespondAssay.pass?('a', :foo)
606
-
607
- And conversely,
608
-
609
- assert RespondAssay.fail?('a', :foo)
610
-
611
- refute RespondAssay.fail?('a', :to_s)
612
-
613
-
614
- ## ExecutionAssay
615
-
616
- The `ExecutionAssay` asserts that a procedure runs without error and returns
617
- a result other than `false` or `nil`. It is not particularly useful, because
618
- what it does is effectively what testing in itself does. So it is rather
619
- redundant. However, it serves as the base class for the more specific
620
- `ReturnAssay`.
621
-
622
- assert ExecutionAssay.pass?{ true }
623
- assert ExecutionAssay.pass?{ :foo }
624
-
625
- refute ExecutionAssay.pass?{ nil }
626
- refute ExecutionAssay.pass?{ false }
627
- refute ExecutionAssay.pass?{ raise }
628
-
629
- And conversely,
630
-
631
- assert ExecutionAssay.fail?{ raise }
632
- assert ExecutionAssay.fail?{ nil }
633
- assert ExecutionAssay.fail?{ false }
634
-
635
- refute ExecutionAssay.fail?{ true }
636
- refute ExecutionAssay.fail?{ :foo }
637
-
638
- Making assertions,
639
-
640
- assert ExecutionAssay.assert!{ true }
641
-
642
- expect ::ExecutionAssay do
643
- assert ExecutionAssay.assert!{ false }
644
- end
645
-
646
- And refutations,
647
-
648
- assert ExecutionAssay.refute!{ false }
649
-
650
- expect ::ExecutionAssay do
651
- assert ExecutionAssay.refute!{ true }
652
- end
653
-
654
-
655
- ## ReturnAssay
656
-
657
- The `ReturnAssay` asserts that a procedure runs without error and returns
658
- a specified result.
659
-
660
- assert ReturnAssay.pass?(:foo){ :foo }
661
- assert ReturnAssay.pass?(true){ true }
662
-
663
- refute ReturnAssay.pass?(:foo){ :bar }
664
- refute ReturnAssay.pass?(:foo){ true }
665
- refute ReturnAssay.pass?(:foo){ raise }
666
-
667
- And conversely,
668
-
669
- assert ReturnAssay.fail?(:foo){ :bar }
670
- assert ReturnAssay.fail?(:foo){ true }
671
- assert ReturnAssay.fail?(:foo){ raise }
672
-
673
- refute ReturnAssay.fail?(:foo){ :foo }
674
- refute ReturnAssay.fail?(true){ true }
675
-
676
- Making assertions,
677
-
678
- assert ReturnAssay.assert!(true){ true }
679
-
680
- expect ::ReturnAssay do
681
- assert ReturnAssay.assert!(:foo){ :bar }
682
- end
683
-
684
- And refutations,
685
-
686
- assert ReturnAssay.refute!(:foo){ :bar }
687
-
688
- expect ::ReturnAssay do
689
- assert ReturnAssay.refute!(:foo){ :foo }
690
- end
691
-
692
-
693
- ## RescueAssay
694
-
695
- The `RescueAssay` asserts that a procedure will raise a specific error.
696
-
697
- assert RescueAssay.pass?{ raise }
698
- assert RescueAssay.pass?(RuntimeError){ raise }
699
- assert RescueAssay.pass?(ArgumentError){ raise ArgumentError }
700
- assert RescueAssay.pass?(Exception){ raise ArgumentError }
701
-
702
- refute RescueAssay.pass?{ raise Exception }
703
- refute RescueAssay.pass?(RuntimeError){ nil }
704
- refute RescueAssay.pass?(ArgumentError){ raise }
705
-
706
- And conversely,
707
-
708
- assert RescueAssay.fail?{ raise Exception }
709
- assert RescueAssay.fail?(RuntimeError){ nil }
710
- assert RescueAssay.fail?(ArgumentError){ raise }
711
-
712
- refute RescueAssay.fail?{ raise }
713
- refute RescueAssay.fail?(RuntimeError){ raise }
714
- refute RescueAssay.fail?(ArgumentError){ raise ArgumentError }
715
- refute RescueAssay.fail?(Exception){ raise ArgumentError }
716
-
717
- Making assertions,
718
-
719
- assert RescueAssay.assert!(RuntimeError){ raise }
720
-
721
- expect ::RescueAssay do
722
- RaiseAssay.assert!(RuntimeError){ nil }
723
- end
724
-
725
- And refutations,
726
-
727
- assert RescueAssay.refute!(RuntimeError){ nil }
728
-
729
- expect ::RescueAssay do
730
- RaiseAssay.refute!(RuntimeError){ raise }
731
- end
732
-
733
-
734
- ## RaiseAssay
735
-
736
- The `RaiseAssay` asserts that a procedure will raise a specific error.
737
-
738
- assert RaiseAssay.pass?{ raise }
739
- assert RaiseAssay.pass?(RuntimeError){ raise }
740
- assert RaiseAssay.pass?(ArgumentError){ raise ArgumentError }
741
-
742
- refute RaiseAssay.pass?{ raise Exception }
743
- refute RaiseAssay.pass?(Exception){ raise ArgumentError }
744
- refute RaiseAssay.pass?(StandardError){ nil }
745
- refute RaiseAssay.pass?(ArgumentError){ raise }
746
-
747
- And conversely,
748
-
749
- assert RaiseAssay.fail?{ raise Exception }
750
- assert RaiseAssay.fail?(RuntimeError){ nil }
751
- assert RaiseAssay.fail?(ArgumentError){ raise }
752
- assert RaiseAssay.fail?(Exception){ raise ArgumentError }
753
-
754
- refute RaiseAssay.fail?{ raise }
755
- refute RaiseAssay.fail?(RuntimeError){ raise }
756
- refute RaiseAssay.fail?(ArgumentError){ raise ArgumentError }
757
-
758
- Making assertions,
759
-
760
- assert RaiseAssay.assert!(RuntimeError){ raise }
761
-
762
- expect ::RaiseAssay do
763
- RaiseAssay.assert!(RuntimeError){ nil }
764
- end
765
-
766
- And refutations,
767
-
768
- assert RaiseAssay.refute!(RuntimeError){ nil }
769
-
770
- expect ::RaiseAssay do
771
- RaiseAssay.refute!(RuntimeError){ raise }
772
- end
773
-
774
-
775
- ## ThrowAssay
776
-
777
- The `ThrowAssay` asserts that a procedure will call `throw` and optionally
778
- of a specific type.
779
-
780
- assert ThrowAssay.pass?(:foo){ throw :foo }
781
- refute ThrowAssay.pass?(:foo){ throw :bar }
782
-
783
- And conversely,
784
-
785
- assert ThrowAssay.fail?(:foo){ throw :bar }
786
- refute ThrowAssay.fail?(:foo){ throw :foo }
787
-
788
- In addition `ThrowAssay` can assert that there is a throw, regardless
789
- of tag.
790
-
791
- assert ThrowAssay.pass?{ throw :foo }
792
- refute ThrowAssay.pass?{ nil }
793
-
794
- And converselry,
795
-
796
- assert ThrowAssay.fail?{ nil }
797
- refute ThrowAssay.fail?{ throw :bar }
798
-
799
- Making assertions, notice that the `#assert!` method requires a `nil`
800
- argument in order to test for any throw. This is not needed on the
801
- `#pass?` method because the `#pass` method can't take aditional options
802
- for setting the message or backtrace.
803
-
804
- assert ThrowAssay.assert!(nil){ throw :foo }
805
-
806
- assert ThrowAssay.assert!(nil, :message=>"optional message"){
807
- throw :foo
808
- }
809
-
810
- expect ThrowAssay do
811
- ThrowAssay.assert!(nil){ 'nothing' }
812
- end
813
-
814
- And refutations,
815
-
816
- assert ThrowAssay.refute!(:foo){ throw :bar }
817
-
818
- expect ThrowAssay do
819
- ThrowAssay.refute!(:foo){ throw :foo }
820
- end
821
-
822
-
823
- ## PathAssay
824
-
825
- The `PathAssay` asserts that a file-system path exists.
826
-
827
- file = __FILE__
828
- dir = File.dirname(file)
829
- dne = __FILE__ + '~'
830
-
831
- assert PathAssay.pass?(file)
832
- assert PathAssay.pass?(dir)
833
-
834
- refute PathAssay.pass?(dne)
835
-
836
- And conversely,
837
-
838
- assert PathAssay.fail?(dne)
839
-
840
- refute PathAssay.fail?(file)
841
- refute PathAssay.fail?(dir)
842
-
843
-
844
- ## DirectoryAssay
845
-
846
- The `DirectoryAssay` asserts that a file-system path exists
847
- and it is a directory.
848
-
849
- file = __FILE__
850
- dir = File.dirname(file)
851
- dne = __FILE__ + '~'
852
-
853
- assert DirectoryAssay.pass?(dir)
854
-
855
- refute DirectoryAssay.pass?(file)
856
- refute DirectoryAssay.pass?(dne)
857
-
858
- And conversely,
859
-
860
- assert DirectoryAssay.fail?(file)
861
- assert DirectoryAssay.fail?(dne)
862
-
863
- refute DirectoryAssay.fail?(dir)
864
-
865
-
866
- ## FileAssay
867
-
868
- The `FileAssay` asserts that a file-system path exists and it is a file.
869
-
870
- file = __FILE__
871
- dir = File.dirname(file)
872
- dne = __FILE__ + '~'
873
-
874
- assert FileAssay.pass?(file)
875
-
876
- refute FileAssay.pass?(dir)
877
- refute FileAssay.pass?(dne)
878
-
879
- And conversely,
880
-
881
- assert FileAssay.fail?(dir)
882
- assert FileAssay.fail?(dne)
883
-
884
- refute FileAssay.fail?(file)
885
-
886
-
887
- ## OutputAssay
888
-
889
- The `OutputAssay` asserts that a output is sent to either `$stdout` or `$stderr`.
890
-
891
- Let's do the simple stdout case first.
892
-
893
- assert OutputAssay.pass?('foo'){ puts 'foo' }
894
-
895
- refute OutputAssay.pass?('foo'){ nil }
896
- refute OutputAssay.pass?('foo'){ puts 'bar' }
897
-
898
- And conversely,
899
-
900
- refute OutputAssay.fail?('foo'){ puts 'foo' }
901
-
902
- assert OutputAssay.fail?('foo'){ nil }
903
- assert OutputAssay.fail?('foo'){ puts 'bar' }
904
-
905
- Now the same for `$stderr`.
906
-
907
- assert OutputAssay.pass?('foo'){ $stderr.puts 'foo' }
908
-
909
- refute OutputAssay.pass?('foo'){ nil }
910
- refute OutputAssay.pass?('foo'){ $stderr.puts 'bar' }
911
-
912
- And conversely,
913
-
914
- refute OutputAssay.fail?('foo'){ $stderr.puts 'foo' }
915
-
916
- assert OutputAssay.fail?('foo'){ nil }
917
- assert OutputAssay.fail?('foo'){ $stderr.puts 'bar' }
918
-
919
- The OutputAssay uses `#===` to test the match so we can also
920
- match against a regular expression.
921
-
922
- assert OutputAssay.pass?(/f/){ puts 'foo' }
923
-
924
- assert OutputAssay.pass?(/f/){ $stderr.puts 'foo' }
925
-
926
-
927
- ## StdoutAssay
928
-
929
- The `StdoutAssay` asserts that a output is sent to `$stdout`.
930
-
931
- assert StdoutAssay.pass?('foo'){ puts 'foo' }
932
-
933
- refute StdoutAssay.pass?('foo'){ nil }
934
- refute StdoutAssay.pass?('foo'){ puts 'bar' }
935
-
936
- And conversely,
937
-
938
- refute StdoutAssay.fail?('foo'){ puts 'foo' }
939
-
940
- assert StdoutAssay.fail?('foo'){ nil }
941
- assert StdoutAssay.fail?('foo'){ puts 'bar' }
942
-
943
- The StdoutAssay uses `#===` to test the match so we can also
944
- match against a regular expression.
945
-
946
- assert StdoutAssay.pass?(/f/){ puts 'foo' }
947
-
948
-
949
- ## StderrAssay
950
-
951
- The `StderrAssay` asserts that a output is sent to `$stderr`.
952
-
953
- assert StderrAssay.pass?('foo'){ $stderr.puts 'foo' }
954
-
955
- refute StderrAssay.pass?('foo'){ nil }
956
- refute StderrAssay.pass?('foo'){ $stderr.puts 'bar' }
957
-
958
- And conversely,
959
-
960
- refute StderrAssay.fail?('foo'){ $stderr.puts 'foo' }
961
-
962
- assert StderrAssay.fail?('foo'){ nil }
963
- assert StderrAssay.fail?('foo'){ $stderr.puts 'bar' }
964
-
965
- The StderrAssay uses `#===` to test the match so we can also
966
- match against a regular expression.
967
-
968
- assert StderrAssay.pass?(/f/){ $stderr.puts 'foo' }
969
-
970
-
971
- # Asay Lookup
972
-
973
- Assay classes are indexed by both name and associated operation, so they
974
- can be looked-up by either. The indexes are stored as class attributes of
975
- the Assertion base class.
976
-
977
- Let's lookup the class for `==` equality.
978
-
979
- Assertion.by_operator(:==) #=> ::EqualAssay
980
-
981
- Let's lookup the assertion class for `#empty?`.
982
-
983
- Assertion.by_operator(:empty?) #=> ::EmptyAssay
984
-
985
- If we wish to lookup by assertive name instead of operator, we can use
986
- the `by_name` method instead.
987
-
988
- Assertion.by_name(:empty) #=> ::EmptyAssay
989
-
990
- We can also use the `Assay.lookup` module method, which will lookup an assay
991
- class by either assertion name or associated operator.
992
-
993
- Assay.lookup(:==) #=> ::EqualAssay
994
- Assay.lookup(:empty?) #=> ::EmptyAssay
995
-
996
-
997
- # Assay as Assertor
998
-
999
- Assay classes can be converted to assertors, otherwise known as *matchers* in
1000
- RSpec circles. The idea behind Assertors is that they can be initialized with
1001
- pre-set criteria and then applied to target subjects.
1002
-
1003
- ## Standard Target Matching
1004
-
1005
- assertor = EqualAssay[1]
1006
-
1007
- assertor.assert!(1)
1008
-
1009
- expect EqualAssay do
1010
- assertor.assert!(2)
1011
- end
1012
-
1013
- ## Partial Arguments
1014
-
1015
- assertor = LessAssay[1,__]
1016
-
1017
- We can apply the assertor using the `#pass!` method.
1018
-
1019
- assertor.assert!(2)
1020
-
1021
- Likewise we can assert the negated expression using `#fail!`.
1022
-
1023
- assertor.refute!(0)
1024
-
1025
- Assay partial a very versile because they allow any argument to become
1026
- the target of a assertor.
1027
-
1028
- assertor = CompareAssay[2,1,__]
1029
-
1030
- assertor.assert!(1)
1031
- assertor.refute!(0)
1032
-
1033
- ## Match Operator
1034
-
1035
- The `#=~` method is an alias for `#assert!`.
1036
-
1037
- assertor = EqualAssay[1]
1038
- assertor =~ 1
1039
-
1040
- Conversely, `#!~` method is an alias for `#refute!`.
1041
-
1042
- assertor !~ 2
1043
-
1044
- ## Case Operator
1045
-
1046
- The `#===` method is also an alias for `#assert!`.
1047
-
1048
- assertor === 1
1049
-
1050
- This allows the `case` statement to be used in an intersting way.
1051
-
1052
- case 10
1053
- when KindAssay[Numeric]
1054
- when EqualAssay[10.0]
1055
- end
1056
-
1057
- ## Negated Assertors
1058
-
1059
- Assertors can also be negated so that pass and fail methods swap behaviors.
1060
-
1061
- assertor = EqualityAssay[1]
1062
-
1063
- assertor.not =~ 2
1064
- assertor.not !~ 1
1065
-
1066
- For conveience we can also negate the assertor using the `~` unary operator.
1067
-
1068
- !assertor === 2
1069
-
1070
- ## Just Cheking
1071
-
1072
- Assertors can also be used just to test the assertion without actually
1073
- raising the associated exception.
1074
-
1075
- assertor = EqualityAssay[__,1]
1076
-
1077
- assertor.pass?(1)
1078
- assertor.fail?(2)
1079
-
1080
- ## RSpec Compatability
1081
-
1082
- RSpec compatibality is provided via neccessary method alias, in particular
1083
- `#matches?` and `#does_not_match?`.
1084
-
1085
- assertor = EqualityAssay[__,1]
1086
-
1087
- assert assertor.matches?(1)
1088
- assert assertor.does_not_match?(2)
1089
-
1090
- Error messages are handle by RSpec by `#failure_message_for_should` and
1091
- `#failure_message_for_should_not`.
1092
-
1093
- assertor.failure_message_for_should(1)
1094
- assertor.failure_message_for_should_not(2)
1095
-
1096
-
1097
- # Assay Class Methods
1098
-
1099
- ## Metadata
1100
-
1101
- Assay support full project metadata access thanks to the `.ruby`
1102
- standard.
1103
-
1104
- Assay.metadata['name'] #=> 'assay'
1105
-
1106
- The metadata also dynamically translates into constants, so we
1107
- can work with this information in the traditional fashion.
1108
-
1109
- Assay::NAME #=> 'assay'
1110
-
1111
- ## Color Messages
1112
-
1113
- We can have some Assay error messages use ANSI color output by
1114
- setting the `Assay.color` setting to `true`.
1115
-
1116
- Assay.color = true
1117
-
1118
- Keep in mind that this requires the `ansi` library.
1119
-
1120
- In particular it is the equality related assertions that utilize color
1121
- output when the objects compared are large. This helps the developer
1122
- pinpint the differences quickly.
1123
-
1124
- expect EqualAssay do
1125
- EqualAssay['really long string'] === 'other string'
1126
- end
1127
-
1128
- ## Lookup Assay Classes
1129
-
1130
- Assay tracks all created Assay classes by both associated operation
1131
- and assertive name.
1132
-
1133
- Assay.lookup_by_operator(:==) #=> EqualAssay
1134
-
1135
- Assay.lookup_by_name(:equal) #=> EqualAssay
1136
-
1137
- We can look for either with just `lookup`.
1138
-
1139
- Assay.lookup(:==) #=> EqualAssay
1140
- Assay.lookup(:equal) #=> EqualAssay
1141
-
1142
-
1143
-