dfect 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CREDITS +1 -0
- data/doc/api/{files/ANN_txt.html → classes/Class.html} +21 -28
- data/doc/api/classes/Dfect.html +446 -139
- data/doc/api/created.rid +1 -1
- data/doc/api/files/CREDITS.html +62 -0
- data/doc/api/files/LICENSE.html +4 -2
- data/doc/api/files/lib/dfect/auto_rb.html +4 -2
- data/doc/api/files/lib/dfect_rb.html +3 -1
- data/doc/api/js/searchdoc.js +1 -2
- data/doc/api/panel/search_index.js +1 -1
- data/doc/history.erb +31 -2
- data/doc/index.xhtml +773 -0
- data/doc/intro.erb +28 -15
- data/doc/setup.erb +4 -4
- data/doc/usage.erb +105 -46
- data/lib/dfect.rb +385 -87
- data/rakefile +4 -2
- data/test/dfect.rb +168 -15
- metadata +21 -19
data/doc/intro.erb
CHANGED
@@ -1,21 +1,32 @@
|
|
1
|
+
% api_url = './api/index.html'
|
2
|
+
% src_url = 'http://github.com/sunaku/' + $program
|
3
|
+
% git_url = 'http://git-scm.com'
|
4
|
+
|
1
5
|
%|chapter "Introduction"
|
2
|
-
%|
|
3
|
-
|
6
|
+
%|project
|
7
|
+
<%= $project %> is an assertion testing library for Ruby that emphasizes a simple assertion vocabulary, instant debuggability of failures, and flexibility in composing tests.
|
4
8
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
<%= $project %> is exciting because:
|
10
|
+
* It has only 5 methods to remember: D F E C T.
|
11
|
+
* It lets you debug assertion failures interactively.
|
12
|
+
* It keeps a detailed report of assertion failures.
|
13
|
+
* It lets you nest tests and execution hooks.
|
14
|
+
* It is implemented in a mere <%= `sloccount lib`[/^\d+/] %> lines of code.
|
11
15
|
|
12
|
-
These features distinguish
|
16
|
+
These features distinguish <%= $project %> from the competition:
|
13
17
|
* [assert{ 2.0 }](http://assert2.rubyforge.org)
|
14
18
|
* [Verify](http://www.ruby-forum.com/topic/183354)
|
15
19
|
* [Testy](http://www.ruby-forum.com/topic/182798)
|
20
|
+
* [minitest](http://blog.zenspider.com/minitest)
|
21
|
+
* [Context](http://github.com/jeremymcanally/context)
|
22
|
+
* [Shoulda](http://thoughtbot.com/projects/shoulda)
|
23
|
+
* [Bacon](http://chneukirchen.org/repos/bacon/README)
|
24
|
+
* [test-spec](http://test-spec.rubyforge.org/test-spec)
|
25
|
+
* [RSpec](http://rspec.info)
|
26
|
+
* [Test::Unit](http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/index.html)
|
16
27
|
|
17
28
|
%|paragraph "Etymology"
|
18
|
-
|
29
|
+
<%= $project %> is named after the D F E C T methods it provides.
|
19
30
|
|
20
31
|
The name is also play on the word "defect", whereby the intentional misspelling of "defect" as "dfect" is a defect in itself! <tt>;-)</tt>
|
21
32
|
|
@@ -23,14 +34,14 @@
|
|
23
34
|
|
24
35
|
%|section "Logistics"
|
25
36
|
* <%= xref "History", "Release notes" %> --- history of project releases.
|
26
|
-
* [Source code](
|
27
|
-
* [API reference](
|
37
|
+
* [Source code](<%= src_url %>) --- obtain via [Git](<%= git_url %>) or browse online.
|
38
|
+
* [API reference](<%= api_url %>) --- documentation for source code.
|
28
39
|
|
29
40
|
To get help or provide feedback, simply
|
30
41
|
<%= xref "License", "contact the author(s)" %>.
|
31
42
|
|
32
43
|
%|paragraph "Version numbers"
|
33
|
-
|
44
|
+
<%= $project %> releases are numbered in *major.minor.patch*
|
34
45
|
form according to the [RubyGems rational versioning
|
35
46
|
policy](http://www.rubygems.org/read/chapter/7), which
|
36
47
|
can be summarized thus:
|
@@ -73,6 +84,8 @@
|
|
73
84
|
%< "../LICENSE"
|
74
85
|
|
75
86
|
%|section "Credits"
|
76
|
-
|
87
|
+
<%= $project %> is made possible by
|
77
88
|
<%= xref "History", "contributions" %>
|
78
|
-
from users like you
|
89
|
+
from users like you:
|
90
|
+
|
91
|
+
%< "../CREDITS"
|
data/doc/setup.erb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
%|chapter "Setup"
|
2
2
|
%|section "Requirements"
|
3
|
-
Your system needs the following software to run
|
3
|
+
Your system needs the following software to run <%= $project %>.
|
4
4
|
|
5
5
|
| Software | Description | Notes |
|
6
6
|
| -------- | ----------- | ----- |
|
@@ -9,17 +9,17 @@
|
|
9
9
|
| [ruby-debug](http://www.datanoise.com/ruby-debug) | Interactive debugger | This is an _optional_ requirement; IRB will be used if this library is not available. |
|
10
10
|
|
11
11
|
%|section "Installation"
|
12
|
-
You can install
|
12
|
+
You can install <%= $project %> by running this command:
|
13
13
|
|
14
14
|
gem install <%= $program %>
|
15
15
|
|
16
16
|
%|section "Manifest"
|
17
|
-
You will see the following items inside
|
17
|
+
You will see the following items inside <%= $project %>'s installation
|
18
18
|
directory:
|
19
19
|
|
20
20
|
* <tt>lib/</tt>
|
21
21
|
|
22
|
-
* <tt><%= $program %>.rb</tt> --- the main
|
22
|
+
* <tt><%= $program %>.rb</tt> --- the main <%= $project %> library.
|
23
23
|
|
24
24
|
* <tt><%= $program %>/</tt>
|
25
25
|
|
data/doc/usage.erb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
% dfect_api = 'api/classes/Dfect.html'
|
2
2
|
|
3
3
|
%|chapter "Usage"
|
4
|
-
Begin by loading
|
4
|
+
Begin by loading <%= $project %> into your program:
|
5
5
|
|
6
6
|
<code>
|
7
7
|
require 'rubygems'
|
8
8
|
require 'dfect'
|
9
9
|
</code>
|
10
10
|
|
11
|
-
|
11
|
+
You now have access to the [`Dfect` module](<%= dfect_api %>), which provides mixin-able instance methods that are also directly-callable as class methods:
|
12
12
|
|
13
13
|
<code>
|
14
|
-
Dfect.D "hello" do
|
14
|
+
Dfect.D "hello" do # D() is a not-mixed-in class method
|
15
15
|
puts "world"
|
16
16
|
end
|
17
17
|
|
@@ -19,52 +19,72 @@
|
|
19
19
|
|
20
20
|
include Dfect
|
21
21
|
|
22
|
-
D "hello" do
|
22
|
+
D "hello" do # D() is a mixed-in instance method
|
23
23
|
puts "world"
|
24
24
|
end
|
25
25
|
</code>
|
26
26
|
|
27
|
-
The following sections explain these methods in detail.
|
27
|
+
The following sections explain these provided methods in detail.
|
28
28
|
|
29
29
|
%|section "Assertions"
|
30
|
-
The following methods take a block parameter and assert something about the result of executing that block.
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
The following methods take a block parameter and assert something about the result of executing that block. See the [API documentation](<%= dfect_api %>) for examples.
|
31
|
+
|
32
|
+
| Method | Description |
|
33
|
+
| ------ | ----------- |
|
34
|
+
| F | assert not true (`nil` or `false`) |
|
35
|
+
| E | assert that an execption is raised |
|
36
|
+
| C | assert that a symbol is thrown |
|
37
|
+
| T | assert true (not `nil` and not `false`) |
|
38
|
+
|
39
|
+
%|paragraph "Negation"
|
40
|
+
These methods are the *opposite* of <%= xref "Assertions", "normal assertions" %>.
|
41
|
+
|
42
|
+
| Method | Description |
|
43
|
+
| ------ | ----------- |
|
44
|
+
| F! | same as T |
|
45
|
+
| E! | assert that an execption is *not* raised |
|
46
|
+
| C! | assert that a symbol is *not* thrown |
|
47
|
+
| T! | same as F |
|
48
|
+
|
49
|
+
%|paragraph "Sampling"
|
50
|
+
These methods allow you to *check the outcome* of an <%= xref "Assertions", "assertion" %> without the penalty of pass or failure.
|
51
|
+
|
52
|
+
| Method | Description |
|
53
|
+
| ------ | ----------- |
|
54
|
+
| F? | returns `true` if F passes; `false` otherwise |
|
55
|
+
| E? | returns `true` if E passes; `false` otherwise |
|
56
|
+
| C? | returns `true` if C passes; `false` otherwise |
|
57
|
+
| T? | returns `true` if T passes; `false` otherwise |
|
36
58
|
|
37
59
|
%|section "Failures"
|
38
|
-
When an assertion fails,
|
60
|
+
When an assertion fails, details about the failure will be shown:
|
39
61
|
|
40
62
|
<pre>
|
41
|
-
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
- test/simple.rb:17
|
62
|
-
- test/simple.rb:3
|
63
|
+
- fail: block must yield true (!nil && !false)
|
64
|
+
code: |-
|
65
|
+
[12..22] in test/simple.rb
|
66
|
+
12
|
67
|
+
13 D "with more nested tests" do
|
68
|
+
14 x = 5
|
69
|
+
15
|
70
|
+
16 T { x > 2 } # passes
|
71
|
+
=> 17 F { x > 2 } # fails
|
72
|
+
18 E { x.hello } # passes
|
73
|
+
19 end
|
74
|
+
20 end
|
75
|
+
21
|
76
|
+
22 # equivalent of before(:each) or setup()
|
77
|
+
vars:
|
78
|
+
x: 5
|
79
|
+
y: 83
|
80
|
+
call:
|
81
|
+
- test/simple.rb:17
|
82
|
+
- test/simple.rb:3
|
63
83
|
</pre>
|
64
84
|
|
65
|
-
|
85
|
+
You will then be placed into a debugger to investigate the failure if the `:debug` option is enabled in [`Dfect.options`](<%= dfect_api %>).
|
66
86
|
|
67
|
-
Details about all assertion failures and a trace of all tests executed are stored by
|
87
|
+
Details about all assertion failures and a trace of all tests executed are stored by <%= $project %> and provided by the [`Dfect.report`](<%= dfect_api %>) method.
|
68
88
|
|
69
89
|
%|section "Tests"
|
70
90
|
The [`D()` method](<%= dfect_api %>) defines a new **test**, which is analagous to the `describe()` environment provided by BDD frameworks like RSpec.
|
@@ -104,11 +124,54 @@
|
|
104
124
|
D .< { puts "do something more!" }
|
105
125
|
</code>
|
106
126
|
|
127
|
+
%|section "Insulation"
|
128
|
+
Use the singleton class of a temporary object to shield your test logic from Ruby's global environment, the code being tested, and from other tests:
|
129
|
+
|
130
|
+
<code>
|
131
|
+
class << Object.new
|
132
|
+
# your test logic here
|
133
|
+
end
|
134
|
+
</code>
|
135
|
+
|
136
|
+
Inside this insulated environment, you are free to:
|
137
|
+
* mix-in any modules your test logic needs
|
138
|
+
* define your own constants, methods, and classes
|
139
|
+
|
140
|
+
For example:
|
141
|
+
|
142
|
+
<code>
|
143
|
+
class << Object.new
|
144
|
+
include SomeModule
|
145
|
+
extend AnotherModule
|
146
|
+
|
147
|
+
YOUR_CONSTANT = 123
|
148
|
+
|
149
|
+
D "your tests here" do
|
150
|
+
# your test logic here
|
151
|
+
|
152
|
+
your_helper_method
|
153
|
+
end
|
154
|
+
|
155
|
+
def self.your_helper_method
|
156
|
+
# your helper logic here
|
157
|
+
|
158
|
+
helper = YourHelperClass.new
|
159
|
+
helper.do_something_helpful
|
160
|
+
|
161
|
+
T { 2 + 2 != 5 }
|
162
|
+
end
|
163
|
+
|
164
|
+
class YourHelperClass
|
165
|
+
# your helper logic here
|
166
|
+
end
|
167
|
+
end
|
168
|
+
</code>
|
169
|
+
|
107
170
|
%|section "Execution"
|
108
171
|
You can configure test execution using:
|
109
172
|
|
110
173
|
<code>
|
111
|
-
Dfect.options =
|
174
|
+
Dfect.options = your_options_hash
|
112
175
|
</code>
|
113
176
|
|
114
177
|
You can execute all tests defined thus far using:
|
@@ -159,27 +222,23 @@
|
|
159
222
|
|
160
223
|
T { x > 2 } # passes
|
161
224
|
F { x > 2 } # fails
|
162
|
-
E { x.hello } #
|
225
|
+
E { x.hello } # passes
|
163
226
|
end
|
164
227
|
end
|
165
228
|
|
166
|
-
|
167
|
-
D.< do
|
229
|
+
D .< do
|
168
230
|
puts "this is executed before every test in this scope"
|
169
231
|
end
|
170
232
|
|
171
|
-
|
172
|
-
D.> do
|
233
|
+
D .> do
|
173
234
|
puts "this is executed after every test in this scope"
|
174
235
|
end
|
175
236
|
|
176
|
-
|
177
|
-
D.<< do
|
237
|
+
D .<< do
|
178
238
|
puts "this is executed once, before all tests in this scope"
|
179
239
|
end
|
180
240
|
|
181
|
-
|
182
|
-
D.>> do
|
241
|
+
D .>> do
|
183
242
|
puts "this is executed once, after all tests in this scope"
|
184
243
|
end
|
185
244
|
end
|