qed 1.3 → 2.0.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.
- data/CHANGELOG.txt +647 -0
- data/HISTORY +16 -0
- data/bin/qedoc +2 -51
- data/demo/error.rdoc +21 -0
- data/demo/{03_site.qed → website.rdoc} +0 -0
- data/doc/qedoc/index.html +160 -69
- data/lib/qed.rb +2 -2
- data/lib/qed/advice.rb +61 -0
- data/lib/qed/advice/events.rb +54 -0
- data/lib/qed/advice/patterns.rb +64 -0
- data/lib/qed/command.rb +76 -65
- data/lib/qed/config.rb +48 -13
- data/lib/qed/evaluator.rb +124 -0
- data/lib/qed/reporter/base.rb +93 -39
- data/lib/qed/reporter/bullet.rb +79 -0
- data/lib/qed/reporter/dotprogress.rb +9 -29
- data/lib/qed/reporter/html.rb +61 -0
- data/lib/qed/reporter/verbatim.rb +41 -47
- data/lib/qed/scope.rb +77 -0
- data/lib/qed/script.rb +66 -399
- data/lib/qed/session.rb +95 -0
- data/lib/qedoc/command.rb +76 -0
- data/lib/{qed → qedoc}/document.rb +31 -22
- data/lib/{qed → qedoc}/document/jquery.js +0 -0
- data/lib/{qed → qedoc}/document/markup.rb +0 -0
- data/lib/{qed → qedoc}/document/template.rhtml +0 -0
- data/meta/requires +2 -0
- data/meta/version +1 -1
- metadata +71 -34
- data/Syckfile +0 -70
- data/demo/01_spec.qed +0 -175
- data/demo/02_err.qed +0 -18
- data/demo/data.txt +0 -1
- data/demo/helpers/sample.rb +0 -4
- data/demo/table.yml +0 -5
- data/lib/qed/extract.rb +0 -137
- data/lib/qed/reporter/ditto.rb +0 -72
- data/lib/qed/reporter/summary.rb +0 -68
- data/lib/qed/runner.rb +0 -198
- data/lib/qed/script1.rb +0 -495
data/HISTORY
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
= RELEASE HISTORY
|
2
2
|
|
3
|
+
== 10.03.04 / 2010-03-04
|
4
|
+
|
5
|
+
This is a major new release of QED. All demonstration documents
|
6
|
+
are now converted to HTML via Tilt (http://github.com/tilt) before
|
7
|
+
being run through the test runner. So QED now supports any markup
|
8
|
+
format supported by Tilt, as well as ordinary HTML. Simply
|
9
|
+
stated, QED process <tt>pre</tt> tags as code and everything else
|
10
|
+
as comments. Nokogiri is used to parse the HTML.
|
11
|
+
|
12
|
+
Changes:
|
13
|
+
|
14
|
+
* HTML serves as a common format.
|
15
|
+
* New dependencies: Tilt and Nokogiri.
|
16
|
+
* New system of version numbers.
|
17
|
+
|
18
|
+
|
3
19
|
== 1.2 / 2009-12-07
|
4
20
|
|
5
21
|
This release adds a significant new feature, Comment Matchers.
|
data/bin/qedoc
CHANGED
@@ -1,52 +1,3 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
|
4
|
-
require 'qed/document'
|
5
|
-
|
6
|
-
options = {}
|
7
|
-
|
8
|
-
usage = OptionParser.new do |usage|
|
9
|
-
|
10
|
-
usage.banner = "Usage: qedoc [OPTIONS] <QEDFile1> [ <QEDFile2> ... ]"
|
11
|
-
|
12
|
-
usage.on("-o", "--output [DIR]", "Output directory") do |dir|
|
13
|
-
options[:output]= dir
|
14
|
-
end
|
15
|
-
|
16
|
-
usage.on("-t", "--title [TITLE]", "Title of Document") do |title|
|
17
|
-
options[:title]= title
|
18
|
-
end
|
19
|
-
|
20
|
-
usage.on("--css [URI]", "Specify a URI for a CSS file add to HTML header.") do |uri|
|
21
|
-
options[:css] = uri
|
22
|
-
end
|
23
|
-
|
24
|
-
usage.on("--dryrun", "") do
|
25
|
-
options[:dryrun] = true
|
26
|
-
end
|
27
|
-
|
28
|
-
usage.on("-q", "--quiet", "") do
|
29
|
-
options[:quiet] = true
|
30
|
-
end
|
31
|
-
|
32
|
-
usage.on_tail("-h", "--help", "display this help message") do
|
33
|
-
puts usage
|
34
|
-
exit
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
usage.parse!
|
40
|
-
|
41
|
-
options[:paths] = ARGV.dup
|
42
|
-
|
43
|
-
#opts[:output] = cli.options[:file]
|
44
|
-
#opts[:dryrun] = cli.options[:dryrun]
|
45
|
-
#opts[:quiet] = cli.options[:quiet]
|
46
|
-
#opts[:css] = cli.options[:css]
|
47
|
-
#opts[:title] = cli.options[:title]
|
48
|
-
|
49
|
-
doc = QED::Document.new(options)
|
50
|
-
|
51
|
-
doc.generate
|
52
|
-
|
2
|
+
require 'qedoc/command'
|
3
|
+
QEDoc::Command.run
|
data/demo/error.rdoc
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
= Examples of Failure
|
2
|
+
|
3
|
+
This document is here simply to demonstrate what
|
4
|
+
a failed and error raising code steps looks like.
|
5
|
+
|
6
|
+
When run with the -v (verbatim) option, for instance, +qed+
|
7
|
+
will highlight the following sections in red and give a brief
|
8
|
+
error message.
|
9
|
+
|
10
|
+
== Failure
|
11
|
+
|
12
|
+
This step demonstrates a failed assertion.
|
13
|
+
|
14
|
+
1.assert == 2
|
15
|
+
|
16
|
+
== Error
|
17
|
+
|
18
|
+
This step demonstrates a raised error.
|
19
|
+
|
20
|
+
raise "Just because"
|
21
|
+
|
File without changes
|
data/doc/qedoc/index.html
CHANGED
@@ -98,7 +98,9 @@
|
|
98
98
|
</div>
|
99
99
|
|
100
100
|
<div id="content">
|
101
|
-
<
|
101
|
+
<body>
|
102
|
+
<h1>Demonstrations</h1>
|
103
|
+
<h2>Standard Sections</h2>
|
102
104
|
<p>
|
103
105
|
QED demos are light-weight specification documents, highly suitable to
|
104
106
|
interface-driven design. The documents are divided up into clauses
|
@@ -109,7 +111,7 @@ executable code.
|
|
109
111
|
<p>
|
110
112
|
Each code section is executed in order of appearance, within a rescue
|
111
113
|
wrapper that captures any failures or errors. If neither a failure or error
|
112
|
-
occur then the code gets a
|
114
|
+
occur then the code gets a “pass”.
|
113
115
|
</p>
|
114
116
|
<p>
|
115
117
|
For example, the following passes:
|
@@ -118,7 +120,7 @@ For example, the following passes:
|
|
118
120
|
(2 + 2).assert == 4
|
119
121
|
</pre>
|
120
122
|
<p>
|
121
|
-
While the following would
|
123
|
+
While the following would “fail”, as indicated by the raising
|
122
124
|
of an Assertion error:
|
123
125
|
</p>
|
124
126
|
<pre>
|
@@ -134,13 +136,13 @@ And this would have raised a NameError:
|
|
134
136
|
nobody_knows_method
|
135
137
|
end
|
136
138
|
</pre>
|
137
|
-
<
|
139
|
+
<h2>Neutral Code Blocks</h2>
|
138
140
|
<p>
|
139
141
|
There is no means of specifying that a code clause is neutral code, i.e.
|
140
142
|
that it should be executed but not tested. Thus far, such a feature has
|
141
143
|
proven to be a YAGNI.
|
142
144
|
</p>
|
143
|
-
<
|
145
|
+
<h2>Defining Custom Assertions</h2>
|
144
146
|
<p>
|
145
147
|
The context in which the QED code is run is a self-extended module, thus
|
146
148
|
reusable macros can be created simply by defining a method.
|
@@ -157,45 +159,44 @@ Now lets try out our new macro definition.
|
|
157
159
|
assert_integer(4)
|
158
160
|
</pre>
|
159
161
|
<p>
|
160
|
-
Let
|
162
|
+
Let’s prove that it can also fail:
|
161
163
|
</p>
|
162
164
|
<pre>
|
163
165
|
expect Assertion do
|
164
|
-
assert_integer(
|
166
|
+
assert_integer("IV")
|
165
167
|
end
|
166
168
|
</pre>
|
167
|
-
|
169
|
+
</body>
|
170
|
+
<body>
|
171
|
+
<h1>Advice</h1>
|
168
172
|
<p>
|
169
|
-
|
170
|
-
|
171
|
-
that
|
172
|
-
methods. Helpers can be defined in a separate files using <tt>require</tt>
|
173
|
-
or <tt>load</tt> in the bottom section to import them. The bottom section
|
174
|
-
is run first, before any the steps.
|
173
|
+
Advice are wrapper methods that augment demonstrations. They are used to
|
174
|
+
keep demonstrations clean of extraneous, repetitive and merely
|
175
|
+
adminstrative code that the reader does not need to see over and over.
|
175
176
|
</p>
|
176
|
-
<
|
177
|
+
<h2>Before and After</h2>
|
177
178
|
<p>
|
178
179
|
QED supports <b>before</b> and <b>after</b> clauses in a specification
|
179
|
-
through the use of
|
180
|
-
|
180
|
+
through the use of Before and After code blocks. These blocks are executed
|
181
|
+
at the beginning and at the end of each indicated step.
|
181
182
|
</p>
|
182
183
|
<p>
|
183
184
|
We use a <b>before</b> clause if we want to setup some code at the start of
|
184
|
-
each step.
|
185
|
+
each code step.
|
185
186
|
</p>
|
186
187
|
<pre>
|
187
188
|
a, z = nil, nil
|
188
189
|
|
189
190
|
Before do
|
190
|
-
a =
|
191
|
+
a = "BEFORE"
|
191
192
|
end
|
192
193
|
</pre>
|
193
194
|
<p>
|
194
|
-
And an <b>after</b> clause to teardown objects after a step.
|
195
|
+
And an <b>after</b> clause to teardown objects after a code step.
|
195
196
|
</p>
|
196
197
|
<pre>
|
197
198
|
After do
|
198
|
-
z =
|
199
|
+
z = "AFTER"
|
199
200
|
end
|
200
201
|
</pre>
|
201
202
|
<p>
|
@@ -204,78 +205,113 @@ ensure their visibility in the scope later. Now, lets verify that the
|
|
204
205
|
<b>before</b> and <b>after</b> clauses work.
|
205
206
|
</p>
|
206
207
|
<pre>
|
207
|
-
a.assert ==
|
208
|
+
a.assert == "BEFORE"
|
208
209
|
|
209
|
-
a =
|
210
|
-
z =
|
210
|
+
a = "A"
|
211
|
+
z = "Z"
|
211
212
|
</pre>
|
212
213
|
<p>
|
213
214
|
And now.
|
214
215
|
</p>
|
215
216
|
<pre>
|
216
|
-
z.assert ==
|
217
|
+
z.assert == "AFTER"
|
217
218
|
</pre>
|
218
219
|
<p>
|
219
|
-
There can
|
220
|
-
new <b>before</b> or <b>after</b> clause later in the document, it will
|
221
|
-
|
220
|
+
There can be more than one before and after clause at a time. If we define
|
221
|
+
a new <b>before</b> or <b>after</b> clause later in the document, it will
|
222
|
+
be appended to the current list of clauses in use.
|
222
223
|
</p>
|
223
224
|
<p>
|
224
225
|
As a demonstration of this:
|
225
226
|
</p>
|
226
227
|
<pre>
|
228
|
+
b = nil
|
229
|
+
|
227
230
|
Before do
|
228
|
-
|
231
|
+
b = "BEFORE AGAIN"
|
229
232
|
end
|
230
233
|
</pre>
|
231
234
|
<p>
|
232
235
|
We will see it is the case.
|
233
236
|
</p>
|
234
237
|
<pre>
|
235
|
-
|
238
|
+
b.assert == "BEFORE AGAIN"
|
236
239
|
</pre>
|
237
240
|
<p>
|
238
241
|
Only use <b>before</b> and <b>after</b> clauses when necessary
|
239
|
-
|
242
|
+
—specifications are generally more readable without them. Indeed,
|
240
243
|
some developers make a policy of avoiding them altogether. YMMV.
|
241
244
|
</p>
|
242
|
-
<
|
245
|
+
<h2>Caveats of Before and After</h2>
|
243
246
|
<p>
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
+
Instead of using Before and After clauses, it is wiser to define a reusable
|
248
|
+
setup method. For example, in the helper if we define a method such as
|
249
|
+
#prepare_example.
|
247
250
|
</p>
|
248
251
|
<pre>
|
249
|
-
|
252
|
+
def prepare_example
|
253
|
+
"Hello, World!"
|
254
|
+
end
|
250
255
|
</pre>
|
251
256
|
<p>
|
252
|
-
|
257
|
+
Then we can reuse it in later code blocks.
|
253
258
|
</p>
|
254
|
-
<
|
259
|
+
<pre>
|
260
|
+
example = prepare_example
|
261
|
+
example.assert == "Hello, World!"
|
262
|
+
</pre>
|
255
263
|
<p>
|
256
|
-
The
|
257
|
-
|
258
|
-
|
264
|
+
The advantage to this is that it gives the reader an indication of what is
|
265
|
+
going on behind the scenes, rather the having an object just magically
|
266
|
+
appear.
|
259
267
|
</p>
|
268
|
+
<h2>Event Targets</h2>
|
260
269
|
<p>
|
261
|
-
|
262
|
-
|
263
|
-
|
270
|
+
There is a small set of advice targets that do not come before or after an
|
271
|
+
event, rather they occur <b>upon</b> a particular event. These include
|
272
|
+
<tt>:load</tt> and <tt>:unload</tt>, for when a new helper is loaded;
|
273
|
+
<tt>:pass</tt>, <tt>:fail</tt> and <tt>:error</tt> for when a code block
|
274
|
+
passes, fails or raises an error; and <tt>:tag</tt> which is a low-level
|
275
|
+
target triggered upon parsing each element in the HTML conversion of the
|
276
|
+
demonstration.
|
264
277
|
</p>
|
265
278
|
<p>
|
266
|
-
|
267
|
-
|
279
|
+
These event targets can be advised by calling the <tt>When</tt> method with
|
280
|
+
the target type as an argument along with the code block to be run when the
|
281
|
+
event is triggered.
|
268
282
|
</p>
|
269
283
|
<pre>
|
270
|
-
|
271
|
-
|
272
|
-
|
284
|
+
x = []
|
285
|
+
|
286
|
+
When(:tag) do |element|
|
287
|
+
x << element.text.strip if element.name == 'li'
|
288
|
+
end
|
273
289
|
</pre>
|
274
|
-
<
|
290
|
+
<p>
|
291
|
+
Not let see it is worked:
|
292
|
+
</p>
|
293
|
+
<ul>
|
294
|
+
<li>SampleA
|
295
|
+
|
296
|
+
</li>
|
297
|
+
<li>SampleB
|
298
|
+
|
299
|
+
</li>
|
300
|
+
<li>SampleC
|
301
|
+
|
302
|
+
</li>
|
303
|
+
</ul>
|
304
|
+
<p>
|
305
|
+
So <tt>x</tt> should now contain these three list samples.
|
306
|
+
</p>
|
307
|
+
<pre>
|
308
|
+
x.assert == [ 'SampleA', 'SampleB', 'SampleC' ]
|
309
|
+
</pre>
|
310
|
+
<h2>Pattern Matchers</h2>
|
275
311
|
<p>
|
276
312
|
QED also supports comment match triggers. With the <tt>When</tt> method one
|
277
|
-
can define
|
278
|
-
|
313
|
+
can define procedures to run when a given pattern matches comment text. For
|
314
|
+
example:
|
279
315
|
</p>
|
280
316
|
<pre>
|
281
317
|
When 'given a setting @a equal to (((\d+)))' do |n|
|
@@ -284,7 +320,7 @@ For example:
|
|
284
320
|
</pre>
|
285
321
|
<p>
|
286
322
|
Now, @a will be set to 1 whenever a comment like this one contains,
|
287
|
-
|
323
|
+
“given a setting @a equal to 1”.
|
288
324
|
</p>
|
289
325
|
<pre>
|
290
326
|
@a.assert == 1
|
@@ -295,8 +331,8 @@ use a regular expression if you need more control over the match. When
|
|
295
331
|
using a string all spaces are converted to <tt>\s+</tt> and anything within
|
296
332
|
double-parenthesis is treated as raw regular expression. Since the above
|
297
333
|
example has (((\d+))), the actual regular expression contains
|
298
|
-
<tt>(\d+)</tt>, so any number can be used. For example,
|
299
|
-
setting @a equal to 2
|
334
|
+
<tt>(\d+)</tt>, so any number can be used. For example, “given a
|
335
|
+
setting @a equal to 2”.
|
300
336
|
</p>
|
301
337
|
<pre>
|
302
338
|
@a.assert == 2
|
@@ -306,34 +342,89 @@ Typically you will want to put triggers is helper files, rather then place
|
|
306
342
|
them directly in the demonstration document.
|
307
343
|
</p>
|
308
344
|
<p>
|
309
|
-
This concludes the basic overview of QED
|
345
|
+
This concludes the basic overview of QED’s specification system,
|
310
346
|
which is itself a QED document. Yes, we eat our own dog food.
|
311
347
|
</p>
|
312
|
-
|
313
|
-
<
|
348
|
+
</body>
|
349
|
+
<body>
|
350
|
+
<h1>Helpers</h1>
|
351
|
+
<p>
|
352
|
+
There are two ways to load advice scripts. Either per demonstration or
|
353
|
+
globally. Per demonstration helpers apply only to the current
|
354
|
+
demonstration. Global helpers apply to all demonstrations.
|
355
|
+
</p>
|
356
|
+
<h2>Global Helpers</h2>
|
357
|
+
<p>
|
358
|
+
Global helpers are loaded at the start of a session and apply equally to
|
359
|
+
all demonstrations in a suite.
|
314
360
|
</p>
|
315
|
-
|
316
|
-
<h1>Examples of Failure</h1>
|
361
|
+
<h2>Local Helpers</h2>
|
317
362
|
<p>
|
318
|
-
|
363
|
+
Helper scripts can be written just a demonstration scripts, or they can be
|
364
|
+
defined as pure Ruby scripts. Either way they are loaded per-demonstration
|
365
|
+
by using specially marked links.
|
366
|
+
</p>
|
367
|
+
<p>
|
368
|
+
For example, because this link, <a href="qed://helpers/advice.rb">Advice</a>, begins with <tt>require:</tt>,
|
369
|
+
it will be used to load a global helper. We can see this with the
|
370
|
+
following:
|
319
371
|
</p>
|
320
372
|
<pre>
|
321
|
-
|
373
|
+
pudding.assert.include?('load advice.rb')
|
322
374
|
</pre>
|
323
375
|
<p>
|
324
|
-
|
376
|
+
No where in the demonstration have we defined <tt>pudding</tt>, but it has
|
377
|
+
been defined for us in the advice.rb helper script.
|
378
|
+
</p>
|
379
|
+
<p>
|
380
|
+
We can also see that the generic When clause in our advice helper is
|
381
|
+
keeping count of descriptions. Since the helper script was loaded three
|
382
|
+
paragraphs back, the count will be 3.
|
325
383
|
</p>
|
326
384
|
<pre>
|
327
|
-
|
385
|
+
count.assert == 3
|
328
386
|
</pre>
|
329
387
|
<p>
|
330
|
-
|
331
|
-
|
388
|
+
Helpers are vital to building test-demonstration suites for applications.
|
389
|
+
But here again, only use them as necessary. The more helpers you use the
|
390
|
+
more difficult your demos will be to follow.
|
332
391
|
</p>
|
333
|
-
|
334
|
-
<
|
392
|
+
</body>
|
393
|
+
<body>
|
394
|
+
<h1>Fixtures</h1>
|
395
|
+
<h2>Flat-file Data</h2>
|
396
|
+
<p>
|
397
|
+
When creating testable demonstrations, there are times when sizable chunks
|
398
|
+
of data are needed. It is convenient to store such data in separate files.
|
399
|
+
The <tt>Data</tt> method makes is easy to load such files.
|
335
400
|
</p>
|
336
|
-
|
401
|
+
<pre>
|
402
|
+
Data('fixtures/data.txt').assert =~ /dolor/
|
403
|
+
</pre>
|
404
|
+
<p>
|
405
|
+
All files are found relative to the location of current document.
|
406
|
+
</p>
|
407
|
+
<h2>Tabular Data</h2>
|
408
|
+
<p>
|
409
|
+
The <tt>Table</tt> method is similar to the <tt>Data</tt> method except
|
410
|
+
that it expects a YAML file, and it can take a block to iterate the data
|
411
|
+
over. This makes it easy to test tables of examples.
|
412
|
+
</p>
|
413
|
+
<p>
|
414
|
+
The arity of the table block corresponds to the number of columns in each
|
415
|
+
row of the table. Each row is assigned in turn and run through the coded
|
416
|
+
step. Consider the following example:
|
417
|
+
</p>
|
418
|
+
<p>
|
419
|
+
Every row in the <a href="http://table.yml">table.yml table</a> will be
|
420
|
+
assigned to the block parameters and run through the subsequent assertion.
|
421
|
+
</p>
|
422
|
+
<pre>
|
423
|
+
Table 'fixtures/table.yml' do |x, y|
|
424
|
+
x.upcase.assert == y
|
425
|
+
end
|
426
|
+
</pre>
|
427
|
+
</body>
|
337
428
|
|
338
429
|
</div>
|
339
430
|
</div>
|