dfect 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +15 -0
- data/doc/api/classes/Dfect.html +872 -0
- data/doc/api/classes/Object.html +72 -0
- data/doc/api/created.rid +1 -0
- data/doc/api/css/main.css +263 -0
- data/doc/api/css/panel.css +383 -0
- data/doc/api/css/reset.css +53 -0
- data/doc/api/files/ANN_txt.html +80 -0
- data/doc/api/files/LICENSE.html +74 -0
- data/doc/api/files/lib/dfect/auto_rb.html +78 -0
- data/doc/api/files/lib/dfect_rb.html +72 -0
- data/doc/api/i/arrows.png +0 -0
- data/doc/api/i/results_bg.png +0 -0
- data/doc/api/i/tree_bg.png +0 -0
- data/doc/api/index.html +14 -0
- data/doc/api/js/jquery-1.3.2.min.js +19 -0
- data/doc/api/js/jquery-effect.js +593 -0
- data/doc/api/js/main.js +22 -0
- data/doc/api/js/searchdoc.js +606 -0
- data/doc/api/panel/index.html +63 -0
- data/doc/api/panel/search_index.js +1 -0
- data/doc/api/panel/tree.js +1 -0
- data/doc/history.erb +4 -0
- data/doc/index.erb +6 -0
- data/doc/intro.erb +78 -0
- data/doc/setup.erb +34 -0
- data/doc/usage.erb +186 -0
- data/lib/dfect/auto.rb +24 -0
- data/lib/dfect.rb +621 -0
- data/rakefile +19 -0
- data/test/dfect.rb +146 -0
- metadata +95 -0
@@ -0,0 +1,872 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<title>Dfect</title>
|
7
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
8
|
+
<link rel="stylesheet" href="../css/reset.css" type="text/css" media="screen" />
|
9
|
+
<link rel="stylesheet" href="../css/main.css" type="text/css" media="screen" />
|
10
|
+
<script src="../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
|
11
|
+
<script src="../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
|
12
|
+
<script src="../js/main.js" type="text/javascript" charset="utf-8"></script>
|
13
|
+
</head>
|
14
|
+
|
15
|
+
<body>
|
16
|
+
<div class="banner">
|
17
|
+
<h1>
|
18
|
+
<span class="type">Module</span>
|
19
|
+
Dfect
|
20
|
+
|
21
|
+
</h1>
|
22
|
+
<ul class="files">
|
23
|
+
|
24
|
+
<li><a href="../files/lib/dfect_rb.html">lib/dfect.rb</a></li>
|
25
|
+
|
26
|
+
</ul>
|
27
|
+
</div>
|
28
|
+
<div id="bodyContent">
|
29
|
+
<div id="content">
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
<div class="sectiontitle">Methods</div>
|
40
|
+
<dl class="methods">
|
41
|
+
|
42
|
+
<dt>#</dt>
|
43
|
+
<dd>
|
44
|
+
<ul>
|
45
|
+
|
46
|
+
<li><a href="#M000001"><</a>,</li>
|
47
|
+
|
48
|
+
<li><a href="#M000003"><<</a>,</li>
|
49
|
+
|
50
|
+
<li><a href="#M000002">></a>,</li>
|
51
|
+
|
52
|
+
<li><a href="#M000004">>></a></li>
|
53
|
+
|
54
|
+
</ul>
|
55
|
+
</dd>
|
56
|
+
|
57
|
+
<dt>C</dt>
|
58
|
+
<dd>
|
59
|
+
<ul>
|
60
|
+
|
61
|
+
<li><a href="#M000008">C</a></li>
|
62
|
+
|
63
|
+
</ul>
|
64
|
+
</dd>
|
65
|
+
|
66
|
+
<dt>D</dt>
|
67
|
+
<dd>
|
68
|
+
<ul>
|
69
|
+
|
70
|
+
<li><a href="#M000000">D</a></li>
|
71
|
+
|
72
|
+
</ul>
|
73
|
+
</dd>
|
74
|
+
|
75
|
+
<dt>E</dt>
|
76
|
+
<dd>
|
77
|
+
<ul>
|
78
|
+
|
79
|
+
<li><a href="#M000007">E</a></li>
|
80
|
+
|
81
|
+
</ul>
|
82
|
+
</dd>
|
83
|
+
|
84
|
+
<dt>F</dt>
|
85
|
+
<dd>
|
86
|
+
<ul>
|
87
|
+
|
88
|
+
<li><a href="#M000006">F</a></li>
|
89
|
+
|
90
|
+
</ul>
|
91
|
+
</dd>
|
92
|
+
|
93
|
+
<dt>T</dt>
|
94
|
+
<dd>
|
95
|
+
<ul>
|
96
|
+
|
97
|
+
<li><a href="#M000005">T</a></li>
|
98
|
+
|
99
|
+
</ul>
|
100
|
+
</dd>
|
101
|
+
|
102
|
+
<dt>R</dt>
|
103
|
+
<dd>
|
104
|
+
<ul>
|
105
|
+
|
106
|
+
<li><a href="#M000009">run</a></li>
|
107
|
+
|
108
|
+
</ul>
|
109
|
+
</dd>
|
110
|
+
|
111
|
+
<dt>S</dt>
|
112
|
+
<dd>
|
113
|
+
<ul>
|
114
|
+
|
115
|
+
<li><a href="#M000010">stop</a></li>
|
116
|
+
|
117
|
+
</ul>
|
118
|
+
</dd>
|
119
|
+
|
120
|
+
</dl>
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
<div class="sectiontitle">Constants</div>
|
131
|
+
<table border='0' cellpadding='5'>
|
132
|
+
|
133
|
+
<tr valign='top'>
|
134
|
+
<td class="attr-name">D</td>
|
135
|
+
<td>=</td>
|
136
|
+
<td class="attr-value">self</td>
|
137
|
+
</tr>
|
138
|
+
|
139
|
+
<tr valign='top'>
|
140
|
+
<td> </td>
|
141
|
+
<td colspan="2" class="attr-desc"><p>
|
142
|
+
Allows before and after hooks to be specified via the D() method syntax
|
143
|
+
when this module is mixed-in:
|
144
|
+
</p>
|
145
|
+
<pre>
|
146
|
+
D .< { puts "before each nested test" }
|
147
|
+
D .> { puts "after each nested test" }
|
148
|
+
D .<< { puts "before all nested tests" }
|
149
|
+
D .>> { puts "after all nested tests" }
|
150
|
+
</pre>
|
151
|
+
</td>
|
152
|
+
</tr>
|
153
|
+
|
154
|
+
|
155
|
+
</table>
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
<div class="sectiontitle">Attributes</div>
|
160
|
+
<table border='0' cellpadding='5'>
|
161
|
+
|
162
|
+
<tr valign='top'>
|
163
|
+
<td class='attr-rw'>
|
164
|
+
[R]
|
165
|
+
</td>
|
166
|
+
<td class='attr-name'>report</td>
|
167
|
+
<td class='attr-desc'><p>
|
168
|
+
Hash of test results, assembled by <a href="Dfect.html#M000009">run</a>.
|
169
|
+
</p>
|
170
|
+
<dl>
|
171
|
+
<dt>:execution</dt><dd>Hierarchical trace of all tests executed, where each test is represented by
|
172
|
+
its description, is mapped to an Array of nested tests, and may contain
|
173
|
+
zero or more assertion failures.
|
174
|
+
|
175
|
+
<p>
|
176
|
+
Assertion failures are represented as a Hash:
|
177
|
+
</p>
|
178
|
+
<dl>
|
179
|
+
<dt>“fail“</dt><dd>Description of the assertion failure.
|
180
|
+
|
181
|
+
</dd>
|
182
|
+
<dt>“code“</dt><dd>Source code surrounding the point of failure.
|
183
|
+
|
184
|
+
</dd>
|
185
|
+
<dt>“vars“</dt><dd>Local variables visible at the point of failure.
|
186
|
+
|
187
|
+
</dd>
|
188
|
+
<dt>“call“</dt><dd>Stack trace leading to the point of failure.
|
189
|
+
|
190
|
+
</dd>
|
191
|
+
</dl>
|
192
|
+
</dd>
|
193
|
+
<dt>:statistics</dt><dd>Hash of counts of major events in test execution:
|
194
|
+
|
195
|
+
<dl>
|
196
|
+
<dt>:passed_assertions</dt><dd>Number of assertions that held true.
|
197
|
+
|
198
|
+
</dd>
|
199
|
+
<dt>:failed_assertions</dt><dd>Number of assertions that did not hold true.
|
200
|
+
|
201
|
+
</dd>
|
202
|
+
<dt>:uncaught_exceptions</dt><dd>Number of exceptions that were not rescued.
|
203
|
+
|
204
|
+
</dd>
|
205
|
+
</dl>
|
206
|
+
</dd>
|
207
|
+
</dl></td>
|
208
|
+
</tr>
|
209
|
+
|
210
|
+
<tr valign='top'>
|
211
|
+
<td class='attr-rw'>
|
212
|
+
[RW]
|
213
|
+
</td>
|
214
|
+
<td class='attr-name'>options</td>
|
215
|
+
<td class='attr-desc'><p>
|
216
|
+
Hash of choices that affect how <a href="Dfect.html">Dfect</a> operates.
|
217
|
+
</p>
|
218
|
+
<dl>
|
219
|
+
<dt>:debug</dt><dd>Launch an interactive debugger during assertion failures so the user can
|
220
|
+
investigate them.
|
221
|
+
|
222
|
+
<p>
|
223
|
+
The default value is $DEBUG.
|
224
|
+
</p>
|
225
|
+
</dd>
|
226
|
+
<dt>:quiet</dt><dd>Do not print the report after executing all tests.
|
227
|
+
|
228
|
+
<p>
|
229
|
+
The default value is false.
|
230
|
+
</p>
|
231
|
+
</dd>
|
232
|
+
</dl></td>
|
233
|
+
</tr>
|
234
|
+
|
235
|
+
</table>
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
<div class="sectiontitle">Class Public methods</div>
|
240
|
+
|
241
|
+
<div class="method">
|
242
|
+
<div class="title" id="M000001">
|
243
|
+
|
244
|
+
<a name="M000001"></a><b><</b>(&block)
|
245
|
+
|
246
|
+
</div>
|
247
|
+
|
248
|
+
<div class="description">
|
249
|
+
|
250
|
+
<p>
|
251
|
+
Registers the given block to be executed before each nested test inside
|
252
|
+
this test.
|
253
|
+
</p>
|
254
|
+
<h4>Examples</h4>
|
255
|
+
<pre>
|
256
|
+
D .< { puts "before each nested test" }
|
257
|
+
|
258
|
+
D .< do
|
259
|
+
puts "before each nested test"
|
260
|
+
end
|
261
|
+
</pre>
|
262
|
+
|
263
|
+
</div>
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
|
268
|
+
<div class="sourcecode">
|
269
|
+
<p class="source-link">
|
270
|
+
Source: <a href="javascript:toggleSource('M000001_source')" id="l_M000001_source">show</a>
|
271
|
+
|
272
|
+
| <a href="http://github.com/sunaku/dfect/blob/92165fb328974d547b1a9656a2ae92f9c84c96fb/lib/dfect.rb#L124" target="_blank" class="github_url">on GitHub</a>
|
273
|
+
|
274
|
+
</p>
|
275
|
+
<div id="M000001_source" class="dyn-source">
|
276
|
+
<pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 124</span>
|
277
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-operator"><</span> <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>
|
278
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'block must be given'</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">block</span>
|
279
|
+
<span class="ruby-ivar">@curr_suite</span>.<span class="ruby-identifier">before_each</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">block</span>
|
280
|
+
<span class="ruby-keyword kw">end</span></pre>
|
281
|
+
</div>
|
282
|
+
</div>
|
283
|
+
|
284
|
+
</div>
|
285
|
+
|
286
|
+
<div class="method">
|
287
|
+
<div class="title" id="M000003">
|
288
|
+
|
289
|
+
<a name="M000003"></a><b><<</b>(&block)
|
290
|
+
|
291
|
+
</div>
|
292
|
+
|
293
|
+
<div class="description">
|
294
|
+
|
295
|
+
<p>
|
296
|
+
Registers the given block to be executed before all nested tests inside
|
297
|
+
this test.
|
298
|
+
</p>
|
299
|
+
<h4>Examples</h4>
|
300
|
+
<pre>
|
301
|
+
D .<< { puts "before all nested tests" }
|
302
|
+
|
303
|
+
D .<< do
|
304
|
+
puts "before all nested tests"
|
305
|
+
end
|
306
|
+
</pre>
|
307
|
+
|
308
|
+
</div>
|
309
|
+
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
<div class="sourcecode">
|
314
|
+
<p class="source-link">
|
315
|
+
Source: <a href="javascript:toggleSource('M000003_source')" id="l_M000003_source">show</a>
|
316
|
+
|
317
|
+
| <a href="http://github.com/sunaku/dfect/blob/92165fb328974d547b1a9656a2ae92f9c84c96fb/lib/dfect.rb#L158" target="_blank" class="github_url">on GitHub</a>
|
318
|
+
|
319
|
+
</p>
|
320
|
+
<div id="M000003_source" class="dyn-source">
|
321
|
+
<pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 158</span>
|
322
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-operator"><<</span> <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>
|
323
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'block must be given'</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">block</span>
|
324
|
+
<span class="ruby-ivar">@curr_suite</span>.<span class="ruby-identifier">before_all</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">block</span>
|
325
|
+
<span class="ruby-keyword kw">end</span></pre>
|
326
|
+
</div>
|
327
|
+
</div>
|
328
|
+
|
329
|
+
</div>
|
330
|
+
|
331
|
+
<div class="method">
|
332
|
+
<div class="title" id="M000002">
|
333
|
+
|
334
|
+
<a name="M000002"></a><b>></b>(&block)
|
335
|
+
|
336
|
+
</div>
|
337
|
+
|
338
|
+
<div class="description">
|
339
|
+
|
340
|
+
<p>
|
341
|
+
Registers the given block to be executed after each nested test inside this
|
342
|
+
test.
|
343
|
+
</p>
|
344
|
+
<h4>Examples</h4>
|
345
|
+
<pre>
|
346
|
+
D .> { puts "after each nested test" }
|
347
|
+
|
348
|
+
D .> do
|
349
|
+
puts "after each nested test"
|
350
|
+
end
|
351
|
+
</pre>
|
352
|
+
|
353
|
+
</div>
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
|
358
|
+
<div class="sourcecode">
|
359
|
+
<p class="source-link">
|
360
|
+
Source: <a href="javascript:toggleSource('M000002_source')" id="l_M000002_source">show</a>
|
361
|
+
|
362
|
+
| <a href="http://github.com/sunaku/dfect/blob/92165fb328974d547b1a9656a2ae92f9c84c96fb/lib/dfect.rb#L141" target="_blank" class="github_url">on GitHub</a>
|
363
|
+
|
364
|
+
</p>
|
365
|
+
<div id="M000002_source" class="dyn-source">
|
366
|
+
<pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 141</span>
|
367
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-operator">></span> <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>
|
368
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'block must be given'</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">block</span>
|
369
|
+
<span class="ruby-ivar">@curr_suite</span>.<span class="ruby-identifier">after_each</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">block</span>
|
370
|
+
<span class="ruby-keyword kw">end</span></pre>
|
371
|
+
</div>
|
372
|
+
</div>
|
373
|
+
|
374
|
+
</div>
|
375
|
+
|
376
|
+
<div class="method">
|
377
|
+
<div class="title" id="M000004">
|
378
|
+
|
379
|
+
<a name="M000004"></a><b>>></b>(&block)
|
380
|
+
|
381
|
+
</div>
|
382
|
+
|
383
|
+
<div class="description">
|
384
|
+
|
385
|
+
<p>
|
386
|
+
Registers the given block to be executed after all nested tests inside this
|
387
|
+
test.
|
388
|
+
</p>
|
389
|
+
<h4>Examples</h4>
|
390
|
+
<pre>
|
391
|
+
D .>> { puts "after all nested tests" }
|
392
|
+
|
393
|
+
D .>> do
|
394
|
+
puts "after all nested tests"
|
395
|
+
end
|
396
|
+
</pre>
|
397
|
+
|
398
|
+
</div>
|
399
|
+
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
<div class="sourcecode">
|
404
|
+
<p class="source-link">
|
405
|
+
Source: <a href="javascript:toggleSource('M000004_source')" id="l_M000004_source">show</a>
|
406
|
+
|
407
|
+
| <a href="http://github.com/sunaku/dfect/blob/92165fb328974d547b1a9656a2ae92f9c84c96fb/lib/dfect.rb#L175" target="_blank" class="github_url">on GitHub</a>
|
408
|
+
|
409
|
+
</p>
|
410
|
+
<div id="M000004_source" class="dyn-source">
|
411
|
+
<pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 175</span>
|
412
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-operator">>></span> <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>
|
413
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'block must be given'</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">block</span>
|
414
|
+
<span class="ruby-ivar">@curr_suite</span>.<span class="ruby-identifier">after_all</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">block</span>
|
415
|
+
<span class="ruby-keyword kw">end</span></pre>
|
416
|
+
</div>
|
417
|
+
</div>
|
418
|
+
|
419
|
+
</div>
|
420
|
+
|
421
|
+
<div class="method">
|
422
|
+
<div class="title" id="M000008">
|
423
|
+
|
424
|
+
<a name="M000008"></a><b>C</b>(message = nil, symbol = nil, &block)
|
425
|
+
|
426
|
+
</div>
|
427
|
+
|
428
|
+
<div class="description">
|
429
|
+
|
430
|
+
<p>
|
431
|
+
Asserts that the given symbol is thrown when the given block is executed,
|
432
|
+
and returns the value that was thrown along with the symbol.
|
433
|
+
</p>
|
434
|
+
<h4>Parameters</h4>
|
435
|
+
<dl>
|
436
|
+
<dt>message</dt><dd>Optional message to show in the report if this assertion fails.
|
437
|
+
|
438
|
+
</dd>
|
439
|
+
<dt>symbol</dt><dd>Symbol that must be thrown by the given block.
|
440
|
+
|
441
|
+
</dd>
|
442
|
+
</dl>
|
443
|
+
<h4>Examples</h4>
|
444
|
+
<pre>
|
445
|
+
# no message specified:
|
446
|
+
|
447
|
+
C(:foo) { throw :foo } # passes
|
448
|
+
|
449
|
+
C(:foo) { throw :bar } # fails
|
450
|
+
C(:foo) { } # fails
|
451
|
+
|
452
|
+
# message specified:
|
453
|
+
|
454
|
+
C( ":foo must be thrown", :foo ) { throw :bar } # fails
|
455
|
+
</pre>
|
456
|
+
|
457
|
+
</div>
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
|
462
|
+
<div class="sourcecode">
|
463
|
+
<p class="source-link">
|
464
|
+
Source: <a href="javascript:toggleSource('M000008_source')" id="l_M000008_source">show</a>
|
465
|
+
|
466
|
+
| <a href="http://github.com/sunaku/dfect/blob/92165fb328974d547b1a9656a2ae92f9c84c96fb/lib/dfect.rb#L342" target="_blank" class="github_url">on GitHub</a>
|
467
|
+
|
468
|
+
</p>
|
469
|
+
<div id="M000008_source" class="dyn-source">
|
470
|
+
<pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 342</span>
|
471
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">C</span> <span class="ruby-identifier">message</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">symbol</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>
|
472
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'block must be given'</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">block</span>
|
473
|
+
|
474
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">message</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Symbol</span> <span class="ruby-keyword kw">and</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">symbol</span>
|
475
|
+
<span class="ruby-identifier">symbol</span> = <span class="ruby-identifier">message</span>
|
476
|
+
<span class="ruby-identifier">message</span> = <span class="ruby-keyword kw">nil</span>
|
477
|
+
<span class="ruby-keyword kw">end</span>
|
478
|
+
|
479
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'symbol must be given'</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">symbol</span>
|
480
|
+
|
481
|
+
<span class="ruby-identifier">symbol</span> = <span class="ruby-identifier">symbol</span>.<span class="ruby-identifier">to_sym</span>
|
482
|
+
<span class="ruby-identifier">message</span> <span class="ruby-operator">||=</span> <span class="ruby-node">"block must throw #{symbol.inspect}"</span>
|
483
|
+
|
484
|
+
<span class="ruby-comment cmt"># if nothing was thrown, the result of catch()</span>
|
485
|
+
<span class="ruby-comment cmt"># is simply the result of executing the block</span>
|
486
|
+
<span class="ruby-identifier">result</span> = <span class="ruby-identifier">catch</span>(<span class="ruby-identifier">symbol</span>) { <span class="ruby-identifier">call</span> <span class="ruby-identifier">block</span>; <span class="ruby-keyword kw">self</span> }
|
487
|
+
|
488
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">result</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">self</span>
|
489
|
+
<span class="ruby-ivar">@exec_stats</span>[<span class="ruby-identifier">:failed_assertions</span>] <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
490
|
+
<span class="ruby-identifier">debug</span> <span class="ruby-identifier">block</span>, <span class="ruby-identifier">message</span>
|
491
|
+
<span class="ruby-keyword kw">else</span>
|
492
|
+
<span class="ruby-ivar">@exec_stats</span>[<span class="ruby-identifier">:passed_assertions</span>] <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
493
|
+
<span class="ruby-identifier">result</span>
|
494
|
+
<span class="ruby-keyword kw">end</span>
|
495
|
+
<span class="ruby-keyword kw">end</span></pre>
|
496
|
+
</div>
|
497
|
+
</div>
|
498
|
+
|
499
|
+
</div>
|
500
|
+
|
501
|
+
<div class="method">
|
502
|
+
<div class="title" id="M000000">
|
503
|
+
|
504
|
+
<a name="M000000"></a><b>D</b>(description = caller.first, &block)
|
505
|
+
|
506
|
+
</div>
|
507
|
+
|
508
|
+
<div class="description">
|
509
|
+
|
510
|
+
<p>
|
511
|
+
Defines a new test, composed of the given description and the given block
|
512
|
+
to execute.
|
513
|
+
</p>
|
514
|
+
<p>
|
515
|
+
A test may contain nested tests.
|
516
|
+
</p>
|
517
|
+
<h4>Parameters</h4>
|
518
|
+
<dl>
|
519
|
+
<dt>description</dt><dd>A short summary of the test being defined.
|
520
|
+
|
521
|
+
</dd>
|
522
|
+
</dl>
|
523
|
+
<h4>Examples</h4>
|
524
|
+
<pre>
|
525
|
+
D "a new array" do
|
526
|
+
D .< { @array = [] }
|
527
|
+
|
528
|
+
D "must be empty" do
|
529
|
+
T { @array.empty? }
|
530
|
+
end
|
531
|
+
|
532
|
+
D "when populated" do
|
533
|
+
D .< { @array.push 55 }
|
534
|
+
|
535
|
+
D "must not be empty" do
|
536
|
+
F { @array.empty? }
|
537
|
+
end
|
538
|
+
end
|
539
|
+
end
|
540
|
+
</pre>
|
541
|
+
|
542
|
+
</div>
|
543
|
+
|
544
|
+
|
545
|
+
|
546
|
+
|
547
|
+
<div class="sourcecode">
|
548
|
+
<p class="source-link">
|
549
|
+
Source: <a href="javascript:toggleSource('M000000_source')" id="l_M000000_source">show</a>
|
550
|
+
|
551
|
+
| <a href="http://github.com/sunaku/dfect/blob/92165fb328974d547b1a9656a2ae92f9c84c96fb/lib/dfect.rb#L107" target="_blank" class="github_url">on GitHub</a>
|
552
|
+
|
553
|
+
</p>
|
554
|
+
<div id="M000000_source" class="dyn-source">
|
555
|
+
<pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 107</span>
|
556
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">D</span> <span class="ruby-identifier">description</span> = <span class="ruby-identifier">caller</span>.<span class="ruby-identifier">first</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>
|
557
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'block must be given'</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">block</span>
|
558
|
+
<span class="ruby-ivar">@curr_suite</span>.<span class="ruby-identifier">tests</span> <span class="ruby-operator"><<</span> <span class="ruby-constant">Suite</span><span class="ruby-operator">::</span><span class="ruby-constant">Test</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">description</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">block</span>)
|
559
|
+
<span class="ruby-keyword kw">end</span></pre>
|
560
|
+
</div>
|
561
|
+
</div>
|
562
|
+
|
563
|
+
</div>
|
564
|
+
|
565
|
+
<div class="method">
|
566
|
+
<div class="title" id="M000007">
|
567
|
+
|
568
|
+
<a name="M000007"></a><b>E</b>(message = nil, *kinds, &block)
|
569
|
+
|
570
|
+
</div>
|
571
|
+
|
572
|
+
<div class="description">
|
573
|
+
|
574
|
+
<p>
|
575
|
+
Asserts that one of the given kinds of exceptions is raised when the given
|
576
|
+
block is executed, and returns the exception that was raised.
|
577
|
+
</p>
|
578
|
+
<h4>Parameters</h4>
|
579
|
+
<dl>
|
580
|
+
<dt>message</dt><dd>Optional message to show in the report if this assertion fails.
|
581
|
+
|
582
|
+
</dd>
|
583
|
+
<dt>kinds</dt><dd>Exception classes that must be raised by the given block.
|
584
|
+
|
585
|
+
<p>
|
586
|
+
If none are given, then StandardError is assumed (similar to how a plain
|
587
|
+
‘rescue’ statement without any arguments catches
|
588
|
+
StandardError).
|
589
|
+
</p>
|
590
|
+
</dd>
|
591
|
+
</dl>
|
592
|
+
<h4>Examples</h4>
|
593
|
+
<pre>
|
594
|
+
# no exceptions specified:
|
595
|
+
|
596
|
+
E { } # fails
|
597
|
+
E { raise } # passes
|
598
|
+
|
599
|
+
# single exception specified:
|
600
|
+
|
601
|
+
E( ArgumentError ) { raise ArgumentError }
|
602
|
+
E( "argument must be invalid", ArgumentError ) { raise ArgumentError }
|
603
|
+
|
604
|
+
# multiple exceptions specified:
|
605
|
+
|
606
|
+
E( SyntaxError, NameError ) { eval "..." }
|
607
|
+
E( "string must compile", SyntaxError, NameError ) { eval "..." }
|
608
|
+
</pre>
|
609
|
+
|
610
|
+
</div>
|
611
|
+
|
612
|
+
|
613
|
+
|
614
|
+
|
615
|
+
<div class="sourcecode">
|
616
|
+
<p class="source-link">
|
617
|
+
Source: <a href="javascript:toggleSource('M000007_source')" id="l_M000007_source">show</a>
|
618
|
+
|
619
|
+
| <a href="http://github.com/sunaku/dfect/blob/92165fb328974d547b1a9656a2ae92f9c84c96fb/lib/dfect.rb#L285" target="_blank" class="github_url">on GitHub</a>
|
620
|
+
|
621
|
+
</p>
|
622
|
+
<div id="M000007_source" class="dyn-source">
|
623
|
+
<pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 285</span>
|
624
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">E</span> <span class="ruby-identifier">message</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">kinds</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>
|
625
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'block must be given'</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">block</span>
|
626
|
+
|
627
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">message</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Class</span>
|
628
|
+
<span class="ruby-identifier">kinds</span>.<span class="ruby-identifier">unshift</span> <span class="ruby-identifier">message</span>
|
629
|
+
<span class="ruby-identifier">message</span> = <span class="ruby-keyword kw">nil</span>
|
630
|
+
<span class="ruby-keyword kw">end</span>
|
631
|
+
|
632
|
+
<span class="ruby-identifier">kinds</span> <span class="ruby-operator"><<</span> <span class="ruby-constant">StandardError</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">kinds</span>.<span class="ruby-identifier">empty?</span>
|
633
|
+
<span class="ruby-identifier">message</span> <span class="ruby-operator">||=</span> <span class="ruby-node">"block must raise #{kinds.join ' or '}"</span>
|
634
|
+
|
635
|
+
<span class="ruby-keyword kw">begin</span>
|
636
|
+
<span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>
|
637
|
+
|
638
|
+
<span class="ruby-keyword kw">rescue</span> <span class="ruby-operator">*</span><span class="ruby-identifier">kinds</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">raised</span>
|
639
|
+
<span class="ruby-ivar">@exec_stats</span>[<span class="ruby-identifier">:passed_assertions</span>] <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
640
|
+
|
641
|
+
<span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">raised</span>
|
642
|
+
<span class="ruby-ivar">@exec_stats</span>[<span class="ruby-identifier">:failed_assertions</span>] <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
643
|
+
|
644
|
+
<span class="ruby-comment cmt"># debug the uncaught exception...</span>
|
645
|
+
<span class="ruby-identifier">debug_uncaught_exception</span> <span class="ruby-identifier">block</span>, <span class="ruby-identifier">raised</span>
|
646
|
+
|
647
|
+
<span class="ruby-comment cmt"># ...in addition to debugging this assertion</span>
|
648
|
+
<span class="ruby-identifier">debug</span> <span class="ruby-identifier">block</span>, [<span class="ruby-identifier">message</span>, {<span class="ruby-value str">'block raised'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">raised</span>}]
|
649
|
+
<span class="ruby-keyword kw">end</span>
|
650
|
+
|
651
|
+
<span class="ruby-identifier">raised</span>
|
652
|
+
<span class="ruby-keyword kw">end</span></pre>
|
653
|
+
</div>
|
654
|
+
</div>
|
655
|
+
|
656
|
+
</div>
|
657
|
+
|
658
|
+
<div class="method">
|
659
|
+
<div class="title" id="M000006">
|
660
|
+
|
661
|
+
<a name="M000006"></a><b>F</b>(message = 'block must yield false (nil || false)', &block)
|
662
|
+
|
663
|
+
</div>
|
664
|
+
|
665
|
+
<div class="description">
|
666
|
+
|
667
|
+
<p>
|
668
|
+
Asserts that the result of the given block is either nil or false and
|
669
|
+
returns that result.
|
670
|
+
</p>
|
671
|
+
<h4>Parameters</h4>
|
672
|
+
<dl>
|
673
|
+
<dt>message</dt><dd>Optional message to show in the report if this assertion fails.
|
674
|
+
|
675
|
+
</dd>
|
676
|
+
</dl>
|
677
|
+
<h4>Examples</h4>
|
678
|
+
<pre>
|
679
|
+
# no message specified:
|
680
|
+
|
681
|
+
F { true } # fails
|
682
|
+
|
683
|
+
F { false } # passes
|
684
|
+
F { nil } # passes
|
685
|
+
|
686
|
+
# message specified:
|
687
|
+
|
688
|
+
F( "computers do not doublethink" ) { 2 + 2 == 5 } # passes
|
689
|
+
</pre>
|
690
|
+
|
691
|
+
</div>
|
692
|
+
|
693
|
+
|
694
|
+
|
695
|
+
|
696
|
+
<div class="sourcecode">
|
697
|
+
<p class="source-link">
|
698
|
+
Source: <a href="javascript:toggleSource('M000006_source')" id="l_M000006_source">show</a>
|
699
|
+
|
700
|
+
| <a href="http://github.com/sunaku/dfect/blob/92165fb328974d547b1a9656a2ae92f9c84c96fb/lib/dfect.rb#L239" target="_blank" class="github_url">on GitHub</a>
|
701
|
+
|
702
|
+
</p>
|
703
|
+
<div id="M000006_source" class="dyn-source">
|
704
|
+
<pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 239</span>
|
705
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">F</span> <span class="ruby-identifier">message</span> = <span class="ruby-value str">'block must yield false (nil || false)'</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>
|
706
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'block must be given'</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">block</span>
|
707
|
+
|
708
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">result</span> = <span class="ruby-identifier">call</span>(<span class="ruby-identifier">block</span>)
|
709
|
+
<span class="ruby-ivar">@exec_stats</span>[<span class="ruby-identifier">:failed_assertions</span>] <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
710
|
+
<span class="ruby-identifier">debug</span> <span class="ruby-identifier">block</span>, <span class="ruby-identifier">message</span>
|
711
|
+
<span class="ruby-keyword kw">else</span>
|
712
|
+
<span class="ruby-ivar">@exec_stats</span>[<span class="ruby-identifier">:passed_assertions</span>] <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
713
|
+
<span class="ruby-keyword kw">end</span>
|
714
|
+
|
715
|
+
<span class="ruby-identifier">result</span>
|
716
|
+
<span class="ruby-keyword kw">end</span></pre>
|
717
|
+
</div>
|
718
|
+
</div>
|
719
|
+
|
720
|
+
</div>
|
721
|
+
|
722
|
+
<div class="method">
|
723
|
+
<div class="title" id="M000005">
|
724
|
+
|
725
|
+
<a name="M000005"></a><b>T</b>(message = 'block must yield true (!nil && !false)', &block)
|
726
|
+
|
727
|
+
</div>
|
728
|
+
|
729
|
+
<div class="description">
|
730
|
+
|
731
|
+
<p>
|
732
|
+
Asserts that the result of the given block is neither nil nor false and
|
733
|
+
returns that result.
|
734
|
+
</p>
|
735
|
+
<h4>Parameters</h4>
|
736
|
+
<dl>
|
737
|
+
<dt>message</dt><dd>Optional message to show in the report if this assertion fails.
|
738
|
+
|
739
|
+
</dd>
|
740
|
+
</dl>
|
741
|
+
<h4>Examples</h4>
|
742
|
+
<pre>
|
743
|
+
# no message specified:
|
744
|
+
|
745
|
+
T { true } # passes
|
746
|
+
|
747
|
+
T { false } # fails
|
748
|
+
T { nil } # fails
|
749
|
+
|
750
|
+
# message specified:
|
751
|
+
|
752
|
+
T( "computers do not doublethink" ) { 2 + 2 != 5 } # passes
|
753
|
+
</pre>
|
754
|
+
|
755
|
+
</div>
|
756
|
+
|
757
|
+
|
758
|
+
|
759
|
+
|
760
|
+
<div class="sourcecode">
|
761
|
+
<p class="source-link">
|
762
|
+
Source: <a href="javascript:toggleSource('M000005_source')" id="l_M000005_source">show</a>
|
763
|
+
|
764
|
+
| <a href="http://github.com/sunaku/dfect/blob/92165fb328974d547b1a9656a2ae92f9c84c96fb/lib/dfect.rb#L203" target="_blank" class="github_url">on GitHub</a>
|
765
|
+
|
766
|
+
</p>
|
767
|
+
<div id="M000005_source" class="dyn-source">
|
768
|
+
<pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 203</span>
|
769
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">T</span> <span class="ruby-identifier">message</span> = <span class="ruby-value str">'block must yield true (!nil && !false)'</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>
|
770
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'block must be given'</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">block</span>
|
771
|
+
|
772
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">result</span> = <span class="ruby-identifier">call</span>(<span class="ruby-identifier">block</span>)
|
773
|
+
<span class="ruby-ivar">@exec_stats</span>[<span class="ruby-identifier">:passed_assertions</span>] <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
774
|
+
<span class="ruby-keyword kw">else</span>
|
775
|
+
<span class="ruby-ivar">@exec_stats</span>[<span class="ruby-identifier">:failed_assertions</span>] <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
776
|
+
<span class="ruby-identifier">debug</span> <span class="ruby-identifier">block</span>, <span class="ruby-identifier">message</span>
|
777
|
+
<span class="ruby-keyword kw">end</span>
|
778
|
+
|
779
|
+
<span class="ruby-identifier">result</span>
|
780
|
+
<span class="ruby-keyword kw">end</span></pre>
|
781
|
+
</div>
|
782
|
+
</div>
|
783
|
+
|
784
|
+
</div>
|
785
|
+
|
786
|
+
<div class="method">
|
787
|
+
<div class="title" id="M000009">
|
788
|
+
|
789
|
+
<a name="M000009"></a><b>run</b>()
|
790
|
+
|
791
|
+
</div>
|
792
|
+
|
793
|
+
<div class="description">
|
794
|
+
|
795
|
+
<p>
|
796
|
+
Executes all tests defined thus far and stores the results in <a
|
797
|
+
href="Dfect.html#report">report</a>.
|
798
|
+
</p>
|
799
|
+
|
800
|
+
</div>
|
801
|
+
|
802
|
+
|
803
|
+
|
804
|
+
|
805
|
+
<div class="sourcecode">
|
806
|
+
<p class="source-link">
|
807
|
+
Source: <a href="javascript:toggleSource('M000009_source')" id="l_M000009_source">show</a>
|
808
|
+
|
809
|
+
| <a href="http://github.com/sunaku/dfect/blob/92165fb328974d547b1a9656a2ae92f9c84c96fb/lib/dfect.rb#L371" target="_blank" class="github_url">on GitHub</a>
|
810
|
+
|
811
|
+
</p>
|
812
|
+
<div id="M000009_source" class="dyn-source">
|
813
|
+
<pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 371</span>
|
814
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>
|
815
|
+
<span class="ruby-comment cmt"># clear previous results</span>
|
816
|
+
<span class="ruby-ivar">@exec_stats</span>.<span class="ruby-identifier">clear</span>
|
817
|
+
<span class="ruby-ivar">@exec_trace</span>.<span class="ruby-identifier">clear</span>
|
818
|
+
<span class="ruby-ivar">@test_stack</span>.<span class="ruby-identifier">clear</span>
|
819
|
+
|
820
|
+
<span class="ruby-comment cmt"># make new results</span>
|
821
|
+
<span class="ruby-identifier">catch</span> <span class="ruby-identifier">:stop_dfect_execution</span> <span class="ruby-keyword kw">do</span>
|
822
|
+
<span class="ruby-identifier">execute</span>
|
823
|
+
<span class="ruby-keyword kw">end</span>
|
824
|
+
|
825
|
+
<span class="ruby-comment cmt"># print new results</span>
|
826
|
+
<span class="ruby-identifier">puts</span> <span class="ruby-ivar">@report</span>.<span class="ruby-identifier">to_yaml</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:quiet</span>]
|
827
|
+
<span class="ruby-keyword kw">end</span></pre>
|
828
|
+
</div>
|
829
|
+
</div>
|
830
|
+
|
831
|
+
</div>
|
832
|
+
|
833
|
+
<div class="method">
|
834
|
+
<div class="title" id="M000010">
|
835
|
+
|
836
|
+
<a name="M000010"></a><b>stop</b>()
|
837
|
+
|
838
|
+
</div>
|
839
|
+
|
840
|
+
<div class="description">
|
841
|
+
|
842
|
+
<p>
|
843
|
+
Stops the execution of the <a href="Dfect.html#M000009">run</a> method or
|
844
|
+
raises an exception if that method is not currently executing.
|
845
|
+
</p>
|
846
|
+
|
847
|
+
</div>
|
848
|
+
|
849
|
+
|
850
|
+
|
851
|
+
|
852
|
+
<div class="sourcecode">
|
853
|
+
<p class="source-link">
|
854
|
+
Source: <a href="javascript:toggleSource('M000010_source')" id="l_M000010_source">show</a>
|
855
|
+
|
856
|
+
| <a href="http://github.com/sunaku/dfect/blob/92165fb328974d547b1a9656a2ae92f9c84c96fb/lib/dfect.rb#L390" target="_blank" class="github_url">on GitHub</a>
|
857
|
+
|
858
|
+
</p>
|
859
|
+
<div id="M000010_source" class="dyn-source">
|
860
|
+
<pre><span class="ruby-comment cmt"># File lib/dfect.rb, line 390</span>
|
861
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stop</span>
|
862
|
+
<span class="ruby-identifier">throw</span> <span class="ruby-identifier">:stop_dfect_execution</span>
|
863
|
+
<span class="ruby-keyword kw">end</span></pre>
|
864
|
+
</div>
|
865
|
+
</div>
|
866
|
+
|
867
|
+
</div>
|
868
|
+
|
869
|
+
</div>
|
870
|
+
</div>
|
871
|
+
</body>
|
872
|
+
</html>
|