dfect 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +25 -4
- data/MANUAL +23 -0
- data/USAGE +303 -290
- data/bin/dfect +57 -0
- data/doc/api/Dfect.html +835 -544
- data/doc/api/Object.html +9 -5
- data/doc/api/_index.html +5 -5
- data/doc/api/class_list.html +1 -1
- data/doc/api/css/style.css +6 -1
- data/doc/api/file.LICENSE.html +4 -4
- data/doc/api/file_list.html +1 -1
- data/doc/api/frames.html +1 -1
- data/doc/api/index.html +4 -4
- data/doc/api/js/app.js +12 -0
- data/doc/api/js/full_list.js +11 -0
- data/doc/api/method_list.html +13 -5
- data/doc/api/top-level-namespace.html +5 -3
- data/doc/index.html +233 -137
- data/inochi.opts +31 -0
- data/lib/dfect.rb +2 -7
- data/lib/dfect/inochi.rb +83 -29
- data/test/dfect_test.rb +2 -0
- metadata +22 -11
- data/doc/index.erb +0 -18
- data/lib/dfect/inochi.yaml +0 -75
- data/test/dfect/inochi_test.rb +0 -17
data/HISTORY
CHANGED
@@ -3,6 +3,27 @@
|
|
3
3
|
%# opening ./doc/index.html in your favorite Web browser. #%
|
4
4
|
%# #%
|
5
5
|
|
6
|
+
%#----------------------------------------------------------------------------
|
7
|
+
%| section "Version 2.1.0 (2010-03-31)"
|
8
|
+
%#----------------------------------------------------------------------------
|
9
|
+
|
10
|
+
This release adds a <%= xref "Shell command", "command-line test runner" %>
|
11
|
+
and performs some minor housekeeping.
|
12
|
+
|
13
|
+
%#--------------------------------------------------------------------------
|
14
|
+
%| paragraph "New features"
|
15
|
+
%#--------------------------------------------------------------------------
|
16
|
+
|
17
|
+
* Add `bin/dfect` executable as command-line interface to this library.
|
18
|
+
|
19
|
+
%#--------------------------------------------------------------------------
|
20
|
+
%| paragraph "Housekeeping"
|
21
|
+
%#--------------------------------------------------------------------------
|
22
|
+
|
23
|
+
* Do not `require 'rubygems'` before loading the "ruby-debug" library.
|
24
|
+
|
25
|
+
* Upgrade to Inochi 2.0.0-rc2 for managing this project.
|
26
|
+
|
6
27
|
%#----------------------------------------------------------------------------
|
7
28
|
%| section "Version 2.0.0 (2010-03-21)"
|
8
29
|
%#----------------------------------------------------------------------------
|
@@ -96,7 +117,7 @@
|
|
96
117
|
%| paragraph "Housekeeping"
|
97
118
|
%#--------------------------------------------------------------------------
|
98
119
|
|
99
|
-
* Upgrade to Inochi 2.0.0 for managing this project.
|
120
|
+
* Upgrade to Inochi 2.0.0-rc1 for managing this project.
|
100
121
|
|
101
122
|
* Make emulation libraries modify Dfect module instead of Kernel.
|
102
123
|
|
@@ -237,9 +258,9 @@
|
|
237
258
|
%| paragraph "New features"
|
238
259
|
%#--------------------------------------------------------------------------
|
239
260
|
|
240
|
-
|
241
|
-
|
242
|
-
|
261
|
+
* Added <%= xref "Negation", "negation (m!)" %> and <%=
|
262
|
+
xref "Sampling", "sampling (m?)" %> variations to <%=
|
263
|
+
xref "Assertions", "assertion methods" %>.
|
243
264
|
|
244
265
|
These new methods implement assertion functionality missing so far
|
245
266
|
(previously we could not assert that a given exception was NOT thrown)
|
data/MANUAL
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
%# #%
|
2
|
+
%# You can read this document in its full glory by #%
|
3
|
+
%# opening ./doc/index.html in your favorite Web browser. #%
|
4
|
+
%# #%
|
5
|
+
|
6
|
+
% api_reference_url = 'api/index.html'
|
7
|
+
% api_reference = "[API reference](#{api_reference_url})"
|
8
|
+
% source_code_tool = '[Git](http://git-scm.com)'
|
9
|
+
% source_code_url = 'http://github.com/sunaku/dfect'
|
10
|
+
% issue_tracker_url = 'http://github.com/sunaku/dfect/issues'
|
11
|
+
|
12
|
+
%|part "Welcome"
|
13
|
+
%+ "README"
|
14
|
+
|
15
|
+
%|part "Setup"
|
16
|
+
%+ "INSTALL"
|
17
|
+
|
18
|
+
%|part "Usage"
|
19
|
+
%+ "USAGE"
|
20
|
+
|
21
|
+
%|part "History"
|
22
|
+
%|project_history
|
23
|
+
%+ "HISTORY"
|
data/USAGE
CHANGED
@@ -3,134 +3,74 @@
|
|
3
3
|
%# opening ./doc/index.html in your favorite Web browser. #%
|
4
4
|
%# #%
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
%#----------------------------------------------------------------------------
|
7
|
+
%| section "Shell command"
|
8
|
+
%#----------------------------------------------------------------------------
|
9
9
|
|
10
|
-
%|
|
11
|
-
|
10
|
+
%|command! "dfect --help" do |node|
|
11
|
+
%|text
|
12
|
+
%= verbatim `ruby bin/#{node.title}`
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
%#----------------------------------------------------------------------------
|
15
|
+
%| section "Ruby library"
|
16
|
+
%#----------------------------------------------------------------------------
|
17
|
+
|
18
|
+
% def example_dfect_test *example_node_args, &block_containing_code_to_run
|
19
|
+
% code_to_run = __block_content__(&block_containing_code_to_run).join
|
20
|
+
% code_to_run.insert 0, "require 'dfect/auto'\n\n"
|
18
21
|
|
19
|
-
|
22
|
+
%|example! *example_node_args
|
23
|
+
When the following test is run:
|
20
24
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
ruby.write code_to_run
|
25
|
-
ruby.close_write
|
26
|
-
ruby.read
|
25
|
+
<%
|
26
|
+
code :ruby do
|
27
|
+
code_to_run
|
27
28
|
end
|
28
|
-
|
29
|
-
%>
|
29
|
+
%>
|
30
30
|
|
31
|
-
|
31
|
+
Dfect will output the following:
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
<%
|
34
|
+
text do
|
35
|
+
IO.popen('ruby -Ilib 2>&1', 'w+') do |ruby|
|
36
|
+
ruby.write code_to_run
|
37
|
+
ruby.close_write
|
38
|
+
ruby.read
|
39
|
+
end
|
40
|
+
end
|
41
|
+
%>
|
36
42
|
|
37
|
-
|
38
|
-
either mixed-in or called directly, according to your preference:
|
43
|
+
Begin by loading Dfect into your program:
|
39
44
|
|
40
|
-
%|code :ruby
|
41
|
-
|
42
|
-
|
43
|
-
end
|
45
|
+
%|code :ruby
|
46
|
+
require 'rubygems' # only necessary if you are using Ruby 1.8
|
47
|
+
require 'dfect'
|
44
48
|
|
45
|
-
|
49
|
+
You now have access to the `Dfect` module, which provides methods that can
|
50
|
+
be either mixed-in or called directly, according to your preference:
|
46
51
|
|
47
|
-
|
52
|
+
%|code :ruby
|
53
|
+
Dfect.D "hello" do # D() is a class method
|
54
|
+
puts "world"
|
55
|
+
end
|
48
56
|
|
49
|
-
|
50
|
-
puts "world"
|
51
|
-
end
|
57
|
+
# the above is same as:
|
52
58
|
|
53
|
-
|
54
|
-
%| section "Assertions"
|
55
|
-
%#----------------------------------------------------------------------------
|
59
|
+
include Dfect # mix-in the Dfect API
|
56
60
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
See the <%= api_reference %> for more details and examples.
|
62
|
-
|
63
|
-
%|table
|
64
|
-
%|thead
|
65
|
-
%|tr
|
66
|
-
%|th
|
67
|
-
Method
|
68
|
-
%|th
|
69
|
-
Description
|
70
|
-
%|tbody
|
71
|
-
%|tr
|
72
|
-
%|td
|
73
|
-
T
|
74
|
-
%|td
|
75
|
-
assert true (not `nil` and not `false`)
|
76
|
-
%|tr
|
77
|
-
%|td
|
78
|
-
F
|
79
|
-
%|td
|
80
|
-
assert not true (`nil` or `false`)
|
81
|
-
%|tr
|
82
|
-
%|td
|
83
|
-
E
|
84
|
-
%|td
|
85
|
-
assert that an execption is raised
|
86
|
-
%|tr
|
87
|
-
%|td
|
88
|
-
C
|
89
|
-
%|td
|
90
|
-
assert that a symbol is thrown
|
61
|
+
D "hello" do # D() is an instance method
|
62
|
+
puts "world"
|
63
|
+
end
|
91
64
|
|
92
65
|
%#--------------------------------------------------------------------------
|
93
|
-
%| section "
|
66
|
+
%| section "Assertions"
|
94
67
|
%#--------------------------------------------------------------------------
|
95
68
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
%|table
|
100
|
-
%|thead
|
101
|
-
%|tr
|
102
|
-
%|th
|
103
|
-
Method
|
104
|
-
%|th
|
105
|
-
Description
|
106
|
-
%|tbody
|
107
|
-
%|tr
|
108
|
-
%|td
|
109
|
-
T!
|
110
|
-
%|td
|
111
|
-
same as F
|
112
|
-
%|tr
|
113
|
-
%|td
|
114
|
-
F!
|
115
|
-
%|td
|
116
|
-
same as T
|
117
|
-
%|tr
|
118
|
-
%|td
|
119
|
-
E!
|
120
|
-
%|td
|
121
|
-
assert that an exception is *not* raised
|
122
|
-
%|tr
|
123
|
-
%|td
|
124
|
-
C!
|
125
|
-
%|td
|
126
|
-
assert that a symbol is *not* thrown
|
127
|
-
|
128
|
-
%#--------------------------------------------------------------------------
|
129
|
-
%| section "Sampling"
|
130
|
-
%#--------------------------------------------------------------------------
|
69
|
+
The following methods accept a block parameter and assert something about
|
70
|
+
the result of executing that block. They also accept an optional message,
|
71
|
+
which is shown in <%= xref "Failures", "failure reports" %> if they fail.
|
131
72
|
|
132
|
-
|
133
|
-
recording a success or failure for that assertion in the execution report.
|
73
|
+
See the <%= api_reference %> for more details and examples.
|
134
74
|
|
135
75
|
%|table
|
136
76
|
%|thead
|
@@ -142,252 +82,325 @@ either mixed-in or called directly, according to your preference:
|
|
142
82
|
%|tbody
|
143
83
|
%|tr
|
144
84
|
%|td
|
145
|
-
T
|
85
|
+
T
|
146
86
|
%|td
|
147
|
-
|
87
|
+
assert true (not `nil` and not `false`)
|
148
88
|
%|tr
|
149
89
|
%|td
|
150
|
-
F
|
90
|
+
F
|
151
91
|
%|td
|
152
|
-
|
92
|
+
assert not true (`nil` or `false`)
|
153
93
|
%|tr
|
154
94
|
%|td
|
155
|
-
E
|
95
|
+
E
|
156
96
|
%|td
|
157
|
-
|
97
|
+
assert that an execption is raised
|
158
98
|
%|tr
|
159
99
|
%|td
|
160
|
-
C
|
100
|
+
C
|
161
101
|
%|td
|
162
|
-
|
102
|
+
assert that a symbol is thrown
|
163
103
|
|
164
|
-
|
165
|
-
|
166
|
-
|
104
|
+
%#------------------------------------------------------------------------
|
105
|
+
%| section "Negation"
|
106
|
+
%#------------------------------------------------------------------------
|
167
107
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
108
|
+
These methods are the *opposite* of
|
109
|
+
<%= xref "Assertions", "normal assertions" %>.
|
110
|
+
|
111
|
+
%|table
|
112
|
+
%|thead
|
113
|
+
%|tr
|
114
|
+
%|th
|
115
|
+
Method
|
116
|
+
%|th
|
117
|
+
Description
|
118
|
+
%|tbody
|
119
|
+
%|tr
|
120
|
+
%|td
|
121
|
+
T!
|
122
|
+
%|td
|
123
|
+
same as F
|
124
|
+
%|tr
|
125
|
+
%|td
|
126
|
+
F!
|
127
|
+
%|td
|
128
|
+
same as T
|
129
|
+
%|tr
|
130
|
+
%|td
|
131
|
+
E!
|
132
|
+
%|td
|
133
|
+
assert that an exception is *not* raised
|
134
|
+
%|tr
|
135
|
+
%|td
|
136
|
+
C!
|
137
|
+
%|td
|
138
|
+
assert that a symbol is *not* thrown
|
196
139
|
|
197
|
-
|
198
|
-
|
199
|
-
|
140
|
+
%#------------------------------------------------------------------------
|
141
|
+
%| section "Sampling"
|
142
|
+
%#------------------------------------------------------------------------
|
200
143
|
|
201
|
-
|
144
|
+
These methods allow you to *check the outcome* of an assertion without
|
145
|
+
recording a success or failure for that assertion in the execution
|
146
|
+
report.
|
147
|
+
|
148
|
+
%|table
|
149
|
+
%|thead
|
150
|
+
%|tr
|
151
|
+
%|th
|
152
|
+
Method
|
153
|
+
%|th
|
154
|
+
Description
|
155
|
+
%|tbody
|
156
|
+
%|tr
|
157
|
+
%|td
|
158
|
+
T?
|
159
|
+
%|td
|
160
|
+
returns `true` if T passes; `false` otherwise
|
161
|
+
%|tr
|
162
|
+
%|td
|
163
|
+
F?
|
164
|
+
%|td
|
165
|
+
returns `true` if F passes; `false` otherwise
|
166
|
+
%|tr
|
167
|
+
%|td
|
168
|
+
E?
|
169
|
+
%|td
|
170
|
+
returns `true` if E passes; `false` otherwise
|
171
|
+
%|tr
|
172
|
+
%|td
|
173
|
+
C?
|
174
|
+
%|td
|
175
|
+
returns `true` if C passes; `false` otherwise
|
202
176
|
|
203
|
-
|
204
|
-
|
205
|
-
|
177
|
+
%#------------------------------------------------------------------------
|
178
|
+
%| section "Failures"
|
179
|
+
%#------------------------------------------------------------------------
|
206
180
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
181
|
+
When an assertion fails, details about the failure will be shown:
|
182
|
+
|
183
|
+
- fail: block must yield true (!nil && !false)
|
184
|
+
code: |-
|
185
|
+
[12..22] in test/simple.rb
|
186
|
+
12
|
187
|
+
13 D "with more nested tests" do
|
188
|
+
14 x = 5
|
189
|
+
15
|
190
|
+
16 T { x > 2 } # passes
|
191
|
+
=> 17 F { x > 2 } # fails
|
192
|
+
18 E { x.hello } # passes
|
193
|
+
19 end
|
194
|
+
20 end
|
195
|
+
21
|
196
|
+
22 # equivalent of before(:each) or setup()
|
197
|
+
vars:
|
198
|
+
x: 5
|
199
|
+
y: 83
|
200
|
+
call:
|
201
|
+
- test/simple.rb:17
|
202
|
+
- test/simple.rb:3
|
203
|
+
|
204
|
+
You will then be placed into a debugger to investigate the failure if
|
205
|
+
the `:debug` option is enabled in the `Dfect.options` hash.
|
206
|
+
|
207
|
+
Details about all assertion failures and a trace of all tests executed
|
208
|
+
are stored by Dfect and provided by the `Dfect.report()` method.
|
211
209
|
|
212
|
-
|
213
|
-
%| section "
|
214
|
-
|
210
|
+
%#------------------------------------------------------------------------
|
211
|
+
%| section "Emulation"
|
212
|
+
%#------------------------------------------------------------------------
|
215
213
|
|
216
|
-
|
217
|
-
concept of **test case** in xUnit or **describe** in rSpec. A test may
|
218
|
-
contain nested tests.
|
214
|
+
Dfect provides emulation layers for several popular testing libraries:
|
219
215
|
|
220
|
-
|
221
|
-
|
222
|
-
|
216
|
+
* <tt>dfect/unit</tt> --- Test::Unit
|
217
|
+
* <tt>dfect/mini</tt> --- Minitest
|
218
|
+
* <tt>dfect/spec</tt> --- RSpec
|
223
219
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
220
|
+
Simply `require()` one of these emulation layers into your test suite
|
221
|
+
and you can write your tests using the familiar syntax of that testing
|
222
|
+
library. See [their source code](<%= source_code_url
|
223
|
+
%>/tree/master/lib/dfect/) for more details.
|
228
224
|
|
229
225
|
%#--------------------------------------------------------------------------
|
230
|
-
%| section "
|
226
|
+
%| section "Tests"
|
231
227
|
%#--------------------------------------------------------------------------
|
232
228
|
|
233
|
-
|
234
|
-
|
235
|
-
|
229
|
+
The `D()` method defines a new Dfect **test**, which is analagous to the
|
230
|
+
concept of **test case** in xUnit or **describe** in rSpec. A test may
|
231
|
+
contain nested tests.
|
236
232
|
|
237
233
|
%|code :ruby
|
238
|
-
|
234
|
+
D "outer test" do
|
235
|
+
# assertions and logic here
|
236
|
+
|
237
|
+
D "inner test" do
|
238
|
+
# more assertions and logic here
|
239
|
+
end
|
240
|
+
end
|
239
241
|
|
240
|
-
|
242
|
+
%#------------------------------------------------------------------------
|
243
|
+
%| section "Execution"
|
244
|
+
%#------------------------------------------------------------------------
|
241
245
|
|
242
|
-
|
243
|
-
Dfect.run
|
246
|
+
Tests are executed in depth-first order.
|
244
247
|
|
245
|
-
|
248
|
+
You can configure the test execution process using:
|
246
249
|
|
247
|
-
|
248
|
-
|
250
|
+
%|code :ruby
|
251
|
+
Dfect.options = your_options_hash
|
249
252
|
|
250
|
-
|
253
|
+
You can execute all tests defined thus far using:
|
251
254
|
|
252
|
-
|
253
|
-
|
255
|
+
%|code :ruby
|
256
|
+
Dfect.run
|
254
257
|
|
255
|
-
|
258
|
+
You can stop the execution at any time using:
|
256
259
|
|
257
|
-
|
258
|
-
|
259
|
-
%#------------------------------------------------------------------------
|
260
|
+
%|code :ruby
|
261
|
+
Dfect.stop
|
260
262
|
|
261
|
-
|
262
|
-
defined by your program before it terminates, simply add the following
|
263
|
-
line at the top of your program:
|
263
|
+
You can view the results of execution using:
|
264
264
|
|
265
265
|
%|code :ruby
|
266
|
-
|
266
|
+
puts Dfect.report.to_yaml
|
267
267
|
|
268
|
-
|
269
|
-
%| section "Hooks"
|
270
|
-
%#------------------------------------------------------------------------
|
268
|
+
See the <%= api_reference %> for details and examples.
|
271
269
|
|
272
|
-
|
273
|
-
execution
|
270
|
+
%#----------------------------------------------------------------------
|
271
|
+
%| paragraph "Automatic test execution"
|
272
|
+
%#----------------------------------------------------------------------
|
274
273
|
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
D .> { puts "after each nested test" }
|
279
|
-
D .<< { puts "before all nested tests" }
|
280
|
-
D .>> { puts "after all nested tests" }
|
281
|
-
|
282
|
-
D "inner test" do
|
283
|
-
# assertions and logic here
|
284
|
-
end
|
285
|
-
end
|
274
|
+
To mix-in the `Dfect` module into your program and execute all tests
|
275
|
+
defined by your program before it terminates, simply add the following
|
276
|
+
line at the top of your program:
|
286
277
|
|
287
|
-
|
288
|
-
|
278
|
+
%|code :ruby
|
279
|
+
require 'dfect/auto'
|
289
280
|
|
290
|
-
|
291
|
-
|
292
|
-
|
281
|
+
%#----------------------------------------------------------------------
|
282
|
+
%| section "Hooks"
|
283
|
+
%#----------------------------------------------------------------------
|
293
284
|
|
294
|
-
|
295
|
-
|
296
|
-
%#------------------------------------------------------------------------
|
285
|
+
The `D()` method provides several entry points (hooks) into the test
|
286
|
+
execution process:
|
297
287
|
|
298
|
-
|
299
|
-
|
288
|
+
%|code :ruby
|
289
|
+
D "outer test" do
|
290
|
+
D .< { puts "before each nested test" }
|
291
|
+
D .> { puts "after each nested test" }
|
292
|
+
D .<< { puts "before all nested tests" }
|
293
|
+
D .>> { puts "after all nested tests" }
|
300
294
|
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
295
|
+
D "inner test" do
|
296
|
+
# assertions and logic here
|
297
|
+
end
|
298
|
+
end
|
305
299
|
|
306
|
-
|
307
|
-
|
308
|
-
end
|
300
|
+
A hook method may be called multiple times. Each call registers
|
301
|
+
additional logic to execute during the hook:
|
309
302
|
|
310
|
-
|
311
|
-
|
312
|
-
|
303
|
+
%|code :ruby
|
304
|
+
D .< { puts "do something" }
|
305
|
+
D .< { puts "do something more!" }
|
313
306
|
|
314
|
-
|
315
|
-
|
316
|
-
|
307
|
+
%#----------------------------------------------------------------------
|
308
|
+
%| section "Logging"
|
309
|
+
%#----------------------------------------------------------------------
|
310
|
+
|
311
|
+
The `L()` method lets you insert log messages, composed of arbitrary
|
312
|
+
Ruby objects, into the test execution report.
|
313
|
+
|
314
|
+
%|example_dfect_test "Logging information in the execution report"
|
315
|
+
D 'Wizard' do
|
316
|
+
L 'Preparing spell to defeat mortal foes...'
|
317
|
+
end
|
318
|
+
|
319
|
+
D 'Magician' do
|
320
|
+
L 'Preparing rabbits to pull from hat...', rand(15)
|
321
|
+
end
|
317
322
|
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
shared block (under a given identifier) into the environment where it is
|
322
|
-
called.
|
323
|
+
D 'Calculator' do
|
324
|
+
L Math::PI, [1, 2, 3, ['a', 'b', 'c']], {:foo => 'bar!'}
|
325
|
+
end
|
323
326
|
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
+
%#------------------------------------------------------------------------
|
328
|
+
%| section "Sharing"
|
329
|
+
%#------------------------------------------------------------------------
|
327
330
|
|
328
|
-
|
329
|
-
|
331
|
+
The `S()` method is a mechanism for sharing code. When called with a
|
332
|
+
block, it shares the given block (under a given identifier) for
|
333
|
+
injection into other tests. When called without a block, it injects a
|
334
|
+
previously shared block (under a given identifier) into the environment
|
335
|
+
where it is called.
|
330
336
|
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
end
|
337
|
+
The `S!()` method is a combination of the two uses of the `S()` method:
|
338
|
+
it lets you simultaneously share a block of code while injecting it into
|
339
|
+
the environment where that method is called.
|
335
340
|
|
336
|
-
|
337
|
-
|
338
|
-
end
|
341
|
+
The `S?()` method simply checks whether any code has been shared under a
|
342
|
+
given identifier.
|
339
343
|
|
340
|
-
|
341
|
-
S
|
342
|
-
L '
|
344
|
+
%|example_dfect_test "Sharing code between tests"
|
345
|
+
S :knowledge do
|
346
|
+
L 'Knowledge is power!'
|
343
347
|
end
|
344
|
-
end
|
345
348
|
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
end
|
349
|
+
D 'Healer' do
|
350
|
+
S :knowledge
|
351
|
+
end
|
350
352
|
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
end
|
353
|
+
D 'Warrior' do
|
354
|
+
S! :strength do
|
355
|
+
L 'Strength is power!'
|
356
|
+
end
|
357
|
+
end
|
357
358
|
|
358
|
-
|
359
|
-
|
360
|
-
|
359
|
+
D 'Wizard' do
|
360
|
+
S :knowledge
|
361
|
+
S :strength
|
362
|
+
end
|
361
363
|
|
362
|
-
|
363
|
-
|
364
|
-
|
364
|
+
D 'King' do
|
365
|
+
T { S? :knowledge }
|
366
|
+
T { S? :strength }
|
367
|
+
F { S? :power }
|
368
|
+
L 'Power is power!'
|
369
|
+
end
|
370
|
+
|
371
|
+
%#------------------------------------------------------------------------
|
372
|
+
%| section "Insulation"
|
373
|
+
%#------------------------------------------------------------------------
|
365
374
|
|
366
|
-
|
367
|
-
|
368
|
-
|
375
|
+
The `D!()` method defines a new test that is explicitly insulated from
|
376
|
+
the tests that contain it and also from the top-level Ruby environment.
|
377
|
+
Root-level calls to the `D()` method are insulated by default.
|
369
378
|
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
T { defined? @outside }
|
374
|
-
T { @outside == 1 }
|
379
|
+
Inside an insulated test, you are free to:
|
380
|
+
* mix-in any modules your test logic needs
|
381
|
+
* define your own constants, methods, and classes
|
375
382
|
|
376
|
-
|
383
|
+
%|example_dfect_test "Insulated and uninsulated tests"
|
384
|
+
D "a root-level test" do
|
385
|
+
@outside = 1
|
377
386
|
T { defined? @outside }
|
378
387
|
T { @outside == 1 }
|
379
|
-
end
|
380
388
|
|
381
|
-
|
382
|
-
|
383
|
-
|
389
|
+
D "an inner, non-insulated test" do
|
390
|
+
T { defined? @outside }
|
391
|
+
T { @outside == 1 }
|
392
|
+
end
|
384
393
|
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
end
|
394
|
+
D! "an inner, insulated test" do
|
395
|
+
F { defined? @outside }
|
396
|
+
F { @outside == 1 }
|
389
397
|
|
390
|
-
|
391
|
-
|
392
|
-
|
398
|
+
@inside = 2
|
399
|
+
T { defined? @inside }
|
400
|
+
T { @inside == 2 }
|
401
|
+
end
|
402
|
+
|
403
|
+
F { defined? @inside }
|
404
|
+
F { @inside == 2 }
|
405
|
+
end
|
393
406
|
|