oktest 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +42 -5
- data/Rakefile.rb +1 -1
- data/lib/oktest.rb +32 -9
- data/oktest.gemspec +3 -3
- data/test/assertion_test.rb +229 -227
- data/test/filter_test.rb +122 -120
- data/test/fixture_test.rb +33 -32
- data/test/generator_test.rb +20 -19
- data/test/helper_test.rb +280 -274
- data/test/init.rb +44 -0
- data/test/mainapp_test.rb +194 -190
- data/test/matcher_test.rb +156 -126
- data/test/misc_test.rb +31 -30
- data/test/nanot.rb +307 -0
- data/test/node_test.rb +296 -252
- data/test/reporter_test.rb +249 -208
- data/test/runner_test.rb +101 -100
- data/test/util_test.rb +196 -193
- data/test/utilhelper_test.rb +35 -38
- data/test/visitor_test.rb +54 -50
- metadata +10 -10
- data/test/initialize.rb +0 -22
- data/test/tc.rb +0 -128
- /data/test/{run_all.rb → all.rb} +0 -0
data/test/node_test.rb
CHANGED
@@ -2,237 +2,240 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
###
|
5
|
-
### $Release: 1.
|
5
|
+
### $Release: 1.5.0 $
|
6
6
|
### $Copyright: copyright(c) 2011-2024 kuwata-lab.com all rights reserved $
|
7
7
|
### $License: MIT License $
|
8
8
|
###
|
9
9
|
|
10
|
-
require_relative './
|
10
|
+
require_relative './init'
|
11
11
|
|
12
12
|
|
13
|
-
class
|
13
|
+
class Item__Test
|
14
|
+
extend NanoTest
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
test_target 'Oktest::Item#accept_visitor()' do
|
17
|
+
test_subject "[!b0e20] raises NotImplementedError." do
|
18
|
+
exc = test_exception? NotImplementedError do
|
18
19
|
Oktest::Item.new().accept_visitor(nil)
|
19
20
|
end
|
21
|
+
test_eq? exc.message, "Oktest::Item#accept_visitor(): not implemented yet."
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
test_target 'Oktest::Item#unlink_parent()' do
|
26
|
+
test_subject "[!5a0i9] raises NotImplementedError." do
|
27
|
+
exc = test_exception? NotImplementedError do
|
26
28
|
Oktest::Item.new().unlink_parent()
|
27
29
|
end
|
30
|
+
test_eq? exc.message, "Oktest::Item#unlink_parent(): not implemented yet."
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
test_target 'Oktest::Item#_repr()' do
|
35
|
+
test_subject "[!qi1af] raises NotImplementedError." do
|
36
|
+
exc = test_exception? NotImplementedError do
|
34
37
|
Oktest::Item.new()._repr(0)
|
35
38
|
end
|
39
|
+
test_eq? exc.message, "Oktest::Item#_repr(): not implemented yet."
|
36
40
|
end
|
37
41
|
end
|
38
42
|
|
39
43
|
end
|
40
44
|
|
41
45
|
|
42
|
-
class
|
46
|
+
class Node__Test
|
47
|
+
extend NanoTest
|
43
48
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
def teardown()
|
49
|
+
def self.test_scope(desc, &b)
|
50
|
+
NanoTest.test_scope(desc, &b)
|
51
|
+
ensure
|
48
52
|
Oktest::THE_GLOBAL_SCOPE.clear_children()
|
49
53
|
end
|
50
54
|
|
51
|
-
|
52
|
-
|
53
|
-
it "[!1fyk9] keeps children." do
|
55
|
+
test_target 'Oktest::Node#add_child()' do
|
56
|
+
test_subject "[!1fyk9] keeps children." do
|
54
57
|
p = Oktest::Node.new(nil)
|
55
58
|
c = Oktest::Node.new(nil)
|
56
59
|
p.add_child(c)
|
57
|
-
|
60
|
+
test_eq? p.instance_eval('@children'), [c]
|
58
61
|
end
|
59
|
-
|
62
|
+
test_subject "[!w5r6l] returns self." do
|
60
63
|
p = Oktest::Node.new(nil)
|
61
64
|
c = Oktest::Node.new(nil)
|
62
65
|
ret = p.add_child(c)
|
63
|
-
|
66
|
+
test_ok? ret.equal?(p), msg: "should be same"
|
64
67
|
end
|
65
68
|
end
|
66
69
|
|
67
|
-
|
68
|
-
|
70
|
+
test_target 'Oktest::Node#has_child?' do
|
71
|
+
test_subject "[!xb30d] return true when no children, else false." do
|
69
72
|
p = Oktest::Node.new(nil)
|
70
73
|
c = Oktest::Node.new(nil)
|
71
74
|
p.add_child(c)
|
72
|
-
|
73
|
-
|
75
|
+
test_eq? p.has_child?, true
|
76
|
+
test_eq? c.has_child?, false
|
74
77
|
end
|
75
78
|
end
|
76
79
|
|
77
|
-
|
78
|
-
|
80
|
+
test_target 'Oktest::Node#each_child()' do
|
81
|
+
test_subject "[!osoep] returns enumerator if block not given." do
|
79
82
|
node = Oktest::Node.new(nil)
|
80
|
-
|
83
|
+
test_eq? node.each_child.class, Enumerator
|
81
84
|
end
|
82
|
-
|
85
|
+
test_subject "[!pve8m] yields block for each child." do
|
83
86
|
p = Oktest::Node.new(nil)
|
84
87
|
c1 = Oktest::Node.new(p)
|
85
88
|
c2 = Oktest::Node.new(p)
|
86
89
|
arr = []
|
87
90
|
p.each_child {|x| arr << x }
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
+
test_eq? arr.length, 2
|
92
|
+
test_eq? arr[0], c1
|
93
|
+
test_eq? arr[1], c2
|
91
94
|
end
|
92
|
-
|
95
|
+
test_subject "[!8z6un] returns nil." do
|
93
96
|
p = Oktest::Node.new(nil)
|
94
97
|
c1 = Oktest::Node.new(p)
|
95
98
|
c2 = Oktest::Node.new(p)
|
96
99
|
ret = p.each_child {|c| 123 }
|
97
|
-
|
100
|
+
test_eq? ret, nil
|
98
101
|
end
|
99
102
|
end
|
100
103
|
|
101
|
-
|
102
|
-
|
104
|
+
test_target 'Oktest::Node#remove_child()' do
|
105
|
+
test_subject "[!hsomo] removes child at index." do
|
103
106
|
p = Oktest::Node.new(nil)
|
104
107
|
c1 = Oktest::Node.new(p)
|
105
108
|
c2 = Oktest::Node.new(p)
|
106
109
|
p.remove_child_at(0)
|
107
110
|
children = p.each_child.to_a
|
108
|
-
|
109
|
-
|
111
|
+
test_eq? children.length, 1
|
112
|
+
test_eq? children[0], c2
|
110
113
|
end
|
111
|
-
|
114
|
+
test_subject "[!hiz1b] returns removed child." do
|
112
115
|
p = Oktest::Node.new(nil)
|
113
116
|
c1 = Oktest::Node.new(p)
|
114
117
|
c2 = Oktest::Node.new(p)
|
115
118
|
ret = p.remove_child_at(0)
|
116
|
-
|
119
|
+
test_eq? ret, c1
|
117
120
|
end
|
118
|
-
|
121
|
+
test_subject "[!7fhx1] unlinks reference between parent and child." do
|
119
122
|
p = Oktest::Node.new(nil)
|
120
123
|
c1 = Oktest::Node.new(p)
|
121
124
|
c2 = Oktest::Node.new(p)
|
122
125
|
p.remove_child_at(1)
|
123
|
-
|
124
|
-
|
126
|
+
test_eq? c2.parent, nil
|
127
|
+
test_eq? c1.parent, p
|
125
128
|
end
|
126
129
|
end
|
127
130
|
|
128
|
-
|
129
|
-
|
131
|
+
test_target 'Oktest::Node#clear_children()' do
|
132
|
+
test_subject "[!o8xfb] removes all children." do
|
130
133
|
p = Oktest::Node.new(nil)
|
131
134
|
p.add_child(Oktest::Node.new(nil))
|
132
135
|
p.add_child(Oktest::Node.new(nil))
|
133
|
-
|
136
|
+
test_eq? p.has_child?, true
|
134
137
|
p.clear_children()
|
135
|
-
|
138
|
+
test_eq? p.has_child?, false
|
136
139
|
end
|
137
|
-
|
140
|
+
test_subject "[!cvaq1] return self." do
|
138
141
|
p = Oktest::Node.new(nil)
|
139
|
-
|
142
|
+
test_ok? p.clear_children().equal?(p)
|
140
143
|
end
|
141
144
|
end
|
142
145
|
|
143
|
-
|
144
|
-
|
146
|
+
test_target 'Oktest::Node#unlink_parent()' do
|
147
|
+
test_subject "[!59m52] clears '@parent' instance variable." do
|
145
148
|
p = Oktest::Node.new(nil)
|
146
149
|
c = Oktest::Node.new(p)
|
147
|
-
|
150
|
+
test_eq? c.parent, p
|
148
151
|
c.unlink_parent()
|
149
|
-
|
152
|
+
test_eq? c.parent, nil
|
150
153
|
end
|
151
|
-
|
154
|
+
test_subject "[!qksxv] returns parent object." do
|
152
155
|
p = Oktest::Node.new(nil)
|
153
156
|
c = Oktest::Node.new(p)
|
154
157
|
ret = c.unlink_parent()
|
155
|
-
|
158
|
+
test_eq? ret, p
|
156
159
|
end
|
157
160
|
end
|
158
161
|
|
159
|
-
|
160
|
-
|
162
|
+
test_target 'Oktest::Node#run_block_in_context_class()' do
|
163
|
+
test_subject "[!j9qdh] run block in context class." do
|
161
164
|
x = Oktest::Node.new(nil)
|
162
165
|
x.run_block_in_context_class { @_tmpvar = "<<00807>>" }
|
163
166
|
val = x.context_class.instance_variable_get('@_tmpvar')
|
164
|
-
|
167
|
+
test_eq? val, "<<00807>>"
|
165
168
|
end
|
166
169
|
end
|
167
170
|
|
168
|
-
|
169
|
-
|
171
|
+
test_target 'Oktest::Node#new_context_object()' do
|
172
|
+
test_subject "[!p271z] creates new context object." do
|
170
173
|
x = Oktest::Node.new(nil)
|
171
174
|
ctx = x.new_context_object()
|
172
|
-
|
173
|
-
|
175
|
+
test_eq? ctx.class, x.context_class
|
176
|
+
test_ok? ctx.is_a?(Oktest::Context)
|
174
177
|
end
|
175
|
-
|
178
|
+
test_subject "[!9hbxn] context object has 'ok()' method." do
|
176
179
|
x = Oktest::Node.new(nil)
|
177
180
|
ctx = x.new_context_object()
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
181
|
+
test_ok? ctx.respond_to?(:ok)
|
182
|
+
test_ok? ctx.respond_to?(:not_ok)
|
183
|
+
test_ok? ctx.respond_to?(:skip_when)
|
184
|
+
test_ok? ctx.respond_to?(:at_end)
|
182
185
|
end
|
183
186
|
end
|
184
187
|
|
185
|
-
|
186
|
-
|
188
|
+
test_target 'Oktest::Node#register_fixture_block()' do
|
189
|
+
test_subject "[!5ctsn] registers fixture name, block, and location." do
|
187
190
|
x = Oktest::Node.new(nil)
|
188
191
|
x.register_fixture_block(:foo, "file:123") {|a, b| "foobar" }
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
192
|
+
test_ok? x.fixtures[:foo][0].is_a?(Proc), msg: "proc object expected"
|
193
|
+
test_eq? x.fixtures[:foo][0].call(1, 2), "foobar"
|
194
|
+
test_eq? x.fixtures[:foo][1], [:a, :b]
|
195
|
+
test_eq? x.fixtures[:foo][2], "file:123"
|
193
196
|
#
|
194
197
|
x.register_fixture_block(:bar, "file:345") { "barbar" }
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
+
test_eq? x.fixtures[:bar][0].call(), "barbar"
|
199
|
+
test_eq? x.fixtures[:bar][1], nil
|
200
|
+
test_eq? x.fixtures[:bar][2], "file:345"
|
198
201
|
end
|
199
|
-
|
202
|
+
test_subject "[!hfcvo] returns self." do
|
200
203
|
x = Oktest::Node.new(nil)
|
201
204
|
ret = x.register_fixture_block(:foo, "file:123") { "foobar" }
|
202
|
-
|
205
|
+
test_ok? ret.equal?(x)
|
203
206
|
end
|
204
207
|
end
|
205
208
|
|
206
|
-
|
207
|
-
|
209
|
+
test_target 'Oktest::Node#get_fixture_block()' do
|
210
|
+
test_subject "[!f0105] returns fixture info." do
|
208
211
|
x = Oktest::Node.new(nil)
|
209
212
|
x.fixtures[:foo] = ["block", [:a, :b], "file:123"]
|
210
|
-
|
213
|
+
test_eq? x.get_fixture_block(:foo), ["block", [:a, :b], "file:123"]
|
211
214
|
end
|
212
215
|
end
|
213
216
|
|
214
|
-
|
215
|
-
|
217
|
+
test_target 'Oktest::Node#register_hook_block()' do
|
218
|
+
test_subject "[!zb66o] registers block with key." do
|
216
219
|
x = Oktest::Node.new(nil)
|
217
220
|
x.register_hook_block(:before) { "<<42533>>" }
|
218
221
|
x.register_hook_block(:after) { "<<46675>>" }
|
219
|
-
|
220
|
-
|
222
|
+
test_eq? x.hooks[:before].call(), "<<42533>>"
|
223
|
+
test_eq? x.hooks[:after].call(), "<<46675>>"
|
221
224
|
end
|
222
225
|
end
|
223
226
|
|
224
|
-
|
225
|
-
|
227
|
+
test_target 'Oktest::Node#get_hook_block()' do
|
228
|
+
test_subject "[!u3fc6] returns block corresponding to key." do
|
226
229
|
x = Oktest::Node.new(nil)
|
227
230
|
x.register_hook_block(:before) { "<<42533>>" }
|
228
231
|
x.register_hook_block(:after) { "<<46675>>" }
|
229
|
-
|
230
|
-
|
232
|
+
test_eq? x.get_hook_block(:before).call(), "<<42533>>"
|
233
|
+
test_eq? x.get_hook_block(:after).call(), "<<46675>>"
|
231
234
|
end
|
232
235
|
end
|
233
236
|
|
234
|
-
|
235
|
-
|
237
|
+
test_target 'Oktest::Node#_repr()' do
|
238
|
+
test_subject "[!bt5j8] builds debug string." do
|
236
239
|
p = Oktest::Node.new(nil)
|
237
240
|
c = Oktest::Node.new(p)
|
238
241
|
p.add_child(c)
|
@@ -244,17 +247,18 @@ class Node_TC < TC
|
|
244
247
|
@parent: #<Oktest::Node:0x[0-9a-f]+>
|
245
248
|
END
|
246
249
|
result = p._repr()
|
247
|
-
#
|
248
|
-
|
250
|
+
#test_eq? result, expected
|
251
|
+
test_match? result, Regexp.compile('\A'+expected), msg: "not matched"
|
249
252
|
end
|
250
253
|
end
|
251
254
|
|
252
255
|
end
|
253
256
|
|
254
257
|
|
255
|
-
class
|
258
|
+
class ScopeNode__Test
|
259
|
+
extend NanoTest
|
256
260
|
|
257
|
-
|
261
|
+
test_target 'Oktest::ScopeNode#accept_visitor()' do
|
258
262
|
class DummyVisitor
|
259
263
|
def visit_scope(*args)
|
260
264
|
@_args = args
|
@@ -262,25 +266,45 @@ class ScopeNode_TC < TC
|
|
262
266
|
end
|
263
267
|
attr_reader :_args
|
264
268
|
end
|
265
|
-
|
269
|
+
test_subject "[!vr6ko] invokes 'visit_spec()' method of visitor and returns result of it." do
|
266
270
|
dummy = DummyVisitor.new()
|
267
271
|
sc = Oktest::ScopeNode.new(nil, __FILE__)
|
268
272
|
ret = sc.accept_visitor(dummy, 1, 2, 3)
|
269
|
-
|
270
|
-
|
273
|
+
test_eq? dummy._args, [sc, 1, 2, 3]
|
274
|
+
test_eq? ret, "<<43746>>"
|
271
275
|
end
|
272
276
|
end
|
273
277
|
|
274
278
|
end
|
275
279
|
|
276
280
|
|
277
|
-
class
|
281
|
+
class TopicNode__Test
|
282
|
+
extend NanoTest
|
278
283
|
|
279
|
-
def new_topic(target, tag: nil)
|
284
|
+
def self.new_topic(target, tag: nil)
|
280
285
|
return Oktest::TopicNode.new(nil, target, tag: tag)
|
281
286
|
end
|
282
287
|
|
283
|
-
|
288
|
+
test_target 'Oktest::TopicNode#run_block_in_context_class()' do
|
289
|
+
test_subject "[!i2kvj] run block in context class." do
|
290
|
+
topicobj = new_topic("foobar1")
|
291
|
+
self_ = nil
|
292
|
+
topicobj.run_block_in_context_class do
|
293
|
+
self_ = self
|
294
|
+
end
|
295
|
+
test_ok? self_ < Oktest::Context
|
296
|
+
end
|
297
|
+
test_subject "[!pr3vj] run block with topic target as an argument." do
|
298
|
+
topicobj = new_topic("foobar2")
|
299
|
+
arg_ = nil
|
300
|
+
topicobj.run_block_in_context_class do |arg|
|
301
|
+
arg_ = arg
|
302
|
+
end
|
303
|
+
test_eq? arg_, "foobar2"
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
test_target 'Oktest::TopicNode#accept_visitor()' do
|
284
308
|
class DummyVisitor2
|
285
309
|
def visit_topic(*args)
|
286
310
|
@_args = args
|
@@ -288,31 +312,31 @@ class TopicNode_TC < TC
|
|
288
312
|
end
|
289
313
|
attr_reader :_args
|
290
314
|
end
|
291
|
-
|
315
|
+
test_subject "[!c1b33] invokes 'visit_topic()' method of visitor and returns result of it." do
|
292
316
|
dummy = DummyVisitor2.new
|
293
317
|
to = Oktest::TopicNode.new(nil, Array)
|
294
318
|
ret = to.accept_visitor(dummy, 4, 5)
|
295
|
-
|
296
|
-
|
319
|
+
test_eq? dummy._args, [to, 4, 5]
|
320
|
+
test_eq? ret, "<<55977>>"
|
297
321
|
end
|
298
322
|
end
|
299
323
|
|
300
|
-
|
301
|
-
|
324
|
+
test_target 'Oktest::TopicNode#@+' do
|
325
|
+
test_subject "[!tzorv] returns self." do
|
302
326
|
to = new_topic('#foobar()')
|
303
|
-
|
327
|
+
test_ok? (+ to).equal?(to), msg: "should be same"
|
304
328
|
end
|
305
329
|
end
|
306
330
|
|
307
331
|
end
|
308
332
|
|
309
333
|
|
310
|
-
class
|
334
|
+
class OktestFuncs__Test
|
335
|
+
extend NanoTest
|
311
336
|
|
312
|
-
def
|
313
|
-
|
314
|
-
|
315
|
-
def teardown
|
337
|
+
def self.test_subject(desc, &b)
|
338
|
+
super
|
339
|
+
ensure
|
316
340
|
Oktest::THE_GLOBAL_SCOPE.clear_children()
|
317
341
|
end
|
318
342
|
|
@@ -325,7 +349,7 @@ class ScopeFunctions_TC < TC
|
|
325
349
|
attr_reader :path, :lineno
|
326
350
|
end
|
327
351
|
|
328
|
-
def with_dummy_location(location)
|
352
|
+
def self.with_dummy_location(location)
|
329
353
|
$_dummy_location = location
|
330
354
|
Oktest.module_eval do
|
331
355
|
class << self
|
@@ -348,112 +372,130 @@ class ScopeFunctions_TC < TC
|
|
348
372
|
$_dummy_location = nil
|
349
373
|
end
|
350
374
|
|
351
|
-
|
352
|
-
|
375
|
+
test_target 'Oktest.scope()' do
|
376
|
+
test_subject "[!vxoy1] creates new scope object." do
|
353
377
|
x = Oktest.scope() { nil }
|
354
|
-
|
378
|
+
test_eq? x.class, Oktest::ScopeNode
|
355
379
|
end
|
356
|
-
|
380
|
+
test_subject "[!jmc4q] raises error when nested called." do
|
357
381
|
begin ; x = 0
|
358
|
-
|
382
|
+
exc = test_exception? Oktest::OktestError do
|
359
383
|
; x = 1
|
360
384
|
Oktest.scope do ; x = 2
|
361
385
|
Oktest.scope do ; x = 3
|
362
386
|
end
|
363
387
|
end
|
364
388
|
end
|
365
|
-
|
389
|
+
test_eq? exc.message, "scope() and global_scope() are not nestable."
|
390
|
+
test_eq? x, 2
|
366
391
|
ensure
|
367
392
|
Oktest.module_eval { @_in_scope = false }
|
368
393
|
end
|
369
394
|
end
|
370
|
-
|
371
|
-
|
395
|
+
test_subject "[!rsimc] adds scope object as child of THE_GLOBAL_SCOPE." do
|
396
|
+
test_eq? Oktest::THE_GLOBAL_SCOPE.has_child?, false
|
372
397
|
so = Oktest.scope do
|
373
398
|
end
|
374
|
-
|
375
|
-
|
399
|
+
test_eq? Oktest::THE_GLOBAL_SCOPE.has_child?, true
|
400
|
+
test_eq? Oktest::THE_GLOBAL_SCOPE.each_child.to_a, [so]
|
376
401
|
end
|
377
|
-
|
402
|
+
test_subject "[!kem4y] detects test script filename." do
|
378
403
|
sc = Oktest.scope() { nil }
|
379
|
-
|
404
|
+
test_eq? sc.filename, "test/node_test.rb"
|
380
405
|
end
|
381
|
-
|
406
|
+
test_subject "[!6ullm] changes test script filename from absolute path to relative path." do
|
382
407
|
with_dummy_location(Dir.pwd + "/tests/foo_test.rb:123") do
|
383
408
|
sc = Oktest.scope() { nil }
|
384
|
-
|
409
|
+
test_eq? sc.filename, "tests/foo_test.rb"
|
385
410
|
end
|
386
411
|
with_dummy_location("./t/bar_test.rb:456") do
|
387
412
|
sc = Oktest.scope() { nil }
|
388
|
-
|
413
|
+
test_eq? sc.filename, "t/bar_test.rb"
|
389
414
|
end
|
390
415
|
end
|
391
416
|
end
|
392
417
|
|
393
|
-
|
394
|
-
|
418
|
+
test_target 'Oktest.global_scope()' do
|
419
|
+
test_subject "[!fcmt2] not create new scope object." do
|
395
420
|
go1 = Oktest.global_scope() { nil }
|
396
|
-
|
421
|
+
test_eq? go1.class, Oktest::ScopeNode
|
397
422
|
go2 = Oktest.global_scope() { nil }
|
398
|
-
|
399
|
-
|
423
|
+
test_eq? go2, go1
|
424
|
+
test_eq? go2, Oktest::THE_GLOBAL_SCOPE
|
400
425
|
end
|
401
|
-
|
426
|
+
test_subject "[!flnpc] run block in the THE_GLOBAL_SCOPE object." do
|
402
427
|
Oktest.global_scope do
|
403
428
|
fixture :tmp_37531 do
|
404
429
|
{id: 37531}
|
405
430
|
end
|
406
431
|
end
|
407
|
-
|
432
|
+
test_ok? Oktest::THE_GLOBAL_SCOPE.fixtures.key?(:tmp_37531)
|
408
433
|
v = Oktest::THE_GLOBAL_SCOPE.fixtures[:tmp_37531][0].call
|
409
|
-
|
434
|
+
test_eq? v, {id: 37531}
|
410
435
|
end
|
411
|
-
|
412
|
-
|
436
|
+
test_subject "[!pe0g2] raises error when nested called." do
|
437
|
+
expected_errmsg = "scope() and global_scope() are not nestable."
|
413
438
|
begin ; x = 0
|
414
|
-
|
439
|
+
exc = test_exception? Oktest::OktestError do
|
440
|
+
; x = 1
|
415
441
|
Oktest.global_scope do ; x = 2
|
416
442
|
Oktest.global_scope do ; x = 3
|
417
443
|
end
|
418
444
|
end
|
419
445
|
end
|
420
|
-
|
446
|
+
test_eq? exc.message, expected_errmsg
|
447
|
+
test_eq? x, 2
|
421
448
|
ensure
|
422
449
|
Oktest.module_eval { @_in_scope = false }
|
423
450
|
end
|
424
451
|
#
|
425
452
|
begin ; x = 0
|
426
|
-
|
453
|
+
exc = test_exception? Oktest::OktestError do
|
454
|
+
; x = 1
|
427
455
|
Oktest.scope do ; x = 2
|
428
456
|
Oktest.global_scope do ; x = 3
|
429
457
|
end
|
430
458
|
end
|
431
459
|
end
|
432
|
-
|
460
|
+
test_eq? exc.message, expected_errmsg
|
461
|
+
|
462
|
+
test_eq? x, 2
|
433
463
|
ensure
|
434
464
|
Oktest.module_eval { @_in_scope = false }
|
435
465
|
end
|
436
466
|
#
|
437
467
|
begin ; x = 0
|
438
|
-
|
468
|
+
exc = test_exception? Oktest::OktestError do ; x = 1
|
439
469
|
Oktest.global_scope do ; x = 2
|
440
470
|
Oktest.scope do ; x = 3
|
441
471
|
end
|
442
472
|
end
|
443
473
|
end
|
444
|
-
|
474
|
+
test_eq? exc.message, expected_errmsg
|
475
|
+
test_eq? x, 2
|
445
476
|
ensure
|
446
477
|
Oktest.module_eval { @_in_scope = false }
|
447
478
|
end
|
448
479
|
end
|
449
480
|
end
|
450
481
|
|
482
|
+
test_target 'Oktest.topic()' do
|
483
|
+
test_subject "[!c5j3f] same as `Oktest.scope do topic target do ... end end`." do
|
484
|
+
arg_ = nil
|
485
|
+
Oktest.topic "FooBar" do |arg|
|
486
|
+
arg_ = arg
|
487
|
+
end
|
488
|
+
test_eq? arg_, "FooBar"
|
489
|
+
end
|
490
|
+
end
|
491
|
+
|
451
492
|
end
|
452
493
|
|
453
494
|
|
454
|
-
class
|
495
|
+
class Context__Test
|
496
|
+
extend NanoTest
|
455
497
|
|
456
|
-
def new_node_with(&b)
|
498
|
+
def self.new_node_with(&b)
|
457
499
|
node = Oktest::Node.new(nil)
|
458
500
|
cls = Class.new(Oktest::Context)
|
459
501
|
cls.__node = node
|
@@ -461,239 +503,241 @@ class Context_TC < TC
|
|
461
503
|
return node
|
462
504
|
end
|
463
505
|
|
464
|
-
|
465
|
-
|
506
|
+
test_target 'Oktest::Context#topic()' do
|
507
|
+
test_subject "[!0gfvq] creates new topic node." do
|
466
508
|
node = new_node_with() do
|
467
509
|
topic Dir, tag: "exp" do
|
468
510
|
end
|
469
511
|
end
|
470
|
-
|
512
|
+
test_eq? node.each_child.to_a.length, 1
|
471
513
|
to = node.each_child.first
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
514
|
+
test_eq? to.class, Oktest::TopicNode
|
515
|
+
test_eq? to.target, Dir
|
516
|
+
test_eq? to.tag, "exp"
|
517
|
+
test_eq? to._prefix, "*"
|
476
518
|
end
|
477
519
|
end
|
478
520
|
|
479
|
-
|
480
|
-
|
521
|
+
test_target 'Oktest::Context#case_when()' do
|
522
|
+
test_subject "[!g3cvh] returns topic object." do
|
481
523
|
node = new_node_with() do
|
482
524
|
case_when "condition..." do
|
483
525
|
end
|
484
526
|
end
|
485
|
-
|
527
|
+
test_eq? node.each_child.to_a.length, 1
|
486
528
|
to = node.each_child.first
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
529
|
+
test_eq? to.class, Oktest::TopicNode
|
530
|
+
test_eq? to.target, "When condition..."
|
531
|
+
test_eq? to.tag, nil
|
532
|
+
test_eq? to._prefix, "-"
|
491
533
|
end
|
492
|
-
|
534
|
+
test_subject "[!ofw1i] target is a description starting with 'When '." do
|
493
535
|
node = new_node_with() do
|
494
536
|
case_when "condition..." do
|
495
537
|
end
|
496
538
|
end
|
497
539
|
to = node.each_child.first
|
498
|
-
|
540
|
+
test_eq? to.target, "When condition..."
|
499
541
|
end
|
500
|
-
|
542
|
+
test_subject "[!53qxv] not add 'When ' if description starts with it." do
|
501
543
|
node = new_node_with() do
|
502
544
|
case_when "when condition..." do
|
503
545
|
end
|
504
546
|
end
|
505
547
|
to = node.each_child.first
|
506
|
-
|
548
|
+
test_eq? to.target, "when condition..."
|
507
549
|
#
|
508
550
|
node = new_node_with() do
|
509
551
|
case_when "[""!abc] when..." do
|
510
552
|
end
|
511
553
|
end
|
512
554
|
to = node.each_child.first
|
513
|
-
|
555
|
+
test_eq? to.target, "[""!abc] when..."
|
514
556
|
end
|
515
557
|
end
|
516
558
|
|
517
|
-
|
518
|
-
|
559
|
+
test_target 'Oktest::Context#case_else()' do
|
560
|
+
test_subject "[!oww4b] returns topic object." do
|
519
561
|
node = new_node_with() do
|
520
562
|
case_else tag: "dev" do
|
521
563
|
end
|
522
564
|
end
|
523
|
-
|
565
|
+
test_eq? node.each_child.to_a.length, 1
|
524
566
|
to = node.each_child.first
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
567
|
+
test_eq? to.class, Oktest::TopicNode
|
568
|
+
test_eq? to.target, "Else"
|
569
|
+
test_eq? to.tag, "dev"
|
570
|
+
test_eq? to._prefix, "-"
|
529
571
|
end
|
530
|
-
|
572
|
+
test_subject "[!j5gnp] target is a description which is 'Else'." do
|
531
573
|
node = new_node_with() do
|
532
574
|
case_else do
|
533
575
|
end
|
534
576
|
end
|
535
|
-
|
577
|
+
test_eq? node.each_child.to_a.length, 1
|
536
578
|
to = node.each_child.first
|
537
|
-
|
538
|
-
|
579
|
+
test_eq? to.class, Oktest::TopicNode
|
580
|
+
test_eq? to.target, "Else"
|
539
581
|
end
|
540
|
-
|
582
|
+
test_subject "[!3nn8d] not add 'Else ' if description starts with it." do
|
541
583
|
node = new_node_with() do
|
542
584
|
case_else "else (x < 0)" do
|
543
585
|
end
|
544
586
|
end
|
545
|
-
|
587
|
+
test_eq? node.each_child.to_a.length, 1
|
546
588
|
to = node.each_child.first
|
547
|
-
|
548
|
-
|
589
|
+
test_eq? to.class, Oktest::TopicNode
|
590
|
+
test_eq? to.target, "else (x < 0)"
|
549
591
|
#
|
550
592
|
node = new_node_with() do
|
551
593
|
case_else "[""!abc] else..." do
|
552
594
|
end
|
553
595
|
end
|
554
|
-
|
596
|
+
test_eq? node.each_child.to_a.length, 1
|
555
597
|
to = node.each_child.first
|
556
|
-
|
557
|
-
|
598
|
+
test_eq? to.class, Oktest::TopicNode
|
599
|
+
test_eq? to.target, "[""!abc] else..."
|
558
600
|
end
|
559
|
-
|
601
|
+
test_subject "[!hs1to] 1st parameter is optional." do
|
560
602
|
node = new_node_with() do
|
561
603
|
case_else "(x < 0)" do
|
562
604
|
end
|
563
605
|
end
|
564
|
-
|
606
|
+
test_eq? node.each_child.to_a.length, 1
|
565
607
|
to = node.each_child.first
|
566
|
-
|
567
|
-
|
608
|
+
test_eq? to.class, Oktest::TopicNode
|
609
|
+
test_eq? to.target, "Else (x < 0)"
|
568
610
|
end
|
569
611
|
end
|
570
612
|
|
571
|
-
|
572
|
-
|
613
|
+
test_target 'Oktest::Context#scope()' do
|
614
|
+
test_subject "[!c8c8o] creates new spec object." do
|
573
615
|
node = new_node_with() do
|
574
616
|
spec "example #1", tag: "exp" do
|
575
617
|
end
|
576
618
|
end
|
577
|
-
|
619
|
+
test_eq? node.each_child.to_a.length, 1
|
578
620
|
sp = node.each_child.first
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
621
|
+
test_eq? sp.class, Oktest::SpecLeaf
|
622
|
+
test_eq? sp.desc, "example #1"
|
623
|
+
test_eq? sp.tag, "exp"
|
624
|
+
test_eq? sp._prefix, "-"
|
583
625
|
end
|
584
|
-
|
626
|
+
test_subject "[!4vkbl] error when `fixture:` keyword arg is not a Hash object." do
|
585
627
|
new_node_with() do
|
586
628
|
spec "example #2", fixture: {x: 1} do end # not raise anything
|
587
629
|
end
|
588
|
-
|
630
|
+
exc = test_exception? ArgumentError do
|
589
631
|
new_node_with() do
|
590
632
|
spec "example #2", fixture: "x: 1" do end
|
591
633
|
end
|
592
634
|
end
|
635
|
+
test_eq? exc.message, 'spec(fixture: "x: 1"): fixture argument should be a Hash object, but got String object.'
|
593
636
|
end
|
594
|
-
|
637
|
+
test_subject "[!ala78] provides raising TodoException block if block not given." do
|
595
638
|
node = new_node_with() do
|
596
639
|
spec "example #3"
|
597
640
|
end
|
598
|
-
|
641
|
+
test_eq? node.each_child.to_a.length, 1
|
599
642
|
sp = node.each_child.first
|
600
|
-
|
643
|
+
exc = test_exception? Oktest::TodoException do
|
601
644
|
sp.block.call
|
602
645
|
end
|
646
|
+
test_eq? exc.message, "not implemented yet"
|
603
647
|
end
|
604
|
-
|
648
|
+
test_subject "[!x48db] keeps called location only when block has parameters." do
|
605
649
|
lineno = __LINE__ + 3
|
606
650
|
node = new_node_with() do
|
607
651
|
spec "example #4" do nil end
|
608
652
|
spec "example #5" do |x| nil end
|
609
653
|
end
|
610
654
|
sp1, sp2 = node.each_child.to_a
|
611
|
-
|
612
|
-
|
613
|
-
|
655
|
+
test_eq? sp1.location, nil
|
656
|
+
test_ok? sp2.location != nil, msg: "not nil"
|
657
|
+
test_ok? sp2.location.to_s.start_with?("#{__FILE__}:#{lineno}:in")
|
614
658
|
end
|
615
659
|
end
|
616
660
|
|
617
|
-
|
618
|
-
|
661
|
+
test_target 'Oktest::Context#fixture()' do
|
662
|
+
test_subject "[!8wfrq] registers fixture factory block." do
|
619
663
|
lineno = __LINE__ + 2
|
620
664
|
node = new_node_with() do
|
621
665
|
fixture :alice do
|
622
666
|
{name: "alice"}
|
623
667
|
end
|
624
668
|
end
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
669
|
+
test_eq? node.fixtures.length, 1
|
670
|
+
test_ok? node.fixtures.key?(:alice), msg: "key not registerd"
|
671
|
+
test_ok? node.fixtures[:alice][0].is_a?(Proc), msg: "block expected"
|
672
|
+
test_eq? node.fixtures[:alice][1], nil
|
673
|
+
test_ok? node.fixtures[:alice][2].to_s.start_with?("#{__FILE__}:#{lineno}:in ")
|
630
674
|
end
|
631
|
-
|
675
|
+
test_subject "[!y3ks3] retrieves block parameter names." do
|
632
676
|
node = new_node_with() do
|
633
677
|
fixture :bob do |x, y|
|
634
678
|
{name: "bob"}
|
635
679
|
end
|
636
680
|
end
|
637
|
-
|
681
|
+
test_eq? node.fixtures[:bob][1], [:x, :y]
|
638
682
|
#
|
639
683
|
node = new_node_with() do
|
640
684
|
fixture :charlie do
|
641
685
|
{name: "charlie"}
|
642
686
|
end
|
643
687
|
end
|
644
|
-
|
688
|
+
test_eq? node.fixtures[:charlie][1], nil
|
645
689
|
end
|
646
690
|
end
|
647
691
|
|
648
|
-
|
649
|
-
|
692
|
+
test_target 'Oktest::Context#before() ' do
|
693
|
+
test_subject "[!275zr] registers 'before' hook block." do
|
650
694
|
x = new_node_with() do
|
651
695
|
before { "<<78059>>" }
|
652
696
|
end
|
653
|
-
|
697
|
+
test_eq? x.get_hook_block(:before).call(), "<<78059>>"
|
654
698
|
end
|
655
699
|
end
|
656
700
|
|
657
|
-
|
658
|
-
|
701
|
+
test_target 'Oktest::Context#after() ' do
|
702
|
+
test_subject "[!ngkvz] registers 'after' hook block." do
|
659
703
|
x = new_node_with() do
|
660
704
|
after { "<<52091>>" }
|
661
705
|
end
|
662
|
-
|
706
|
+
test_eq? x.get_hook_block(:after).call(), "<<52091>>"
|
663
707
|
end
|
664
708
|
end
|
665
709
|
|
666
|
-
|
667
|
-
|
710
|
+
test_target 'Oktest::Context#before_all() ' do
|
711
|
+
test_subject "[!8v1y4] registers 'before_all' hook block." do
|
668
712
|
x = new_node_with() do
|
669
713
|
before_all { "<<42577>>" }
|
670
714
|
end
|
671
|
-
|
715
|
+
test_eq? x.get_hook_block(:before_all).call(), "<<42577>>"
|
672
716
|
end
|
673
717
|
end
|
674
718
|
|
675
|
-
|
676
|
-
|
719
|
+
test_target 'Oktest::Context#after_all() ' do
|
720
|
+
test_subject "[!0w5ik] registers 'after_all' hook block." do
|
677
721
|
x = new_node_with() do
|
678
722
|
after_all { "<<33326>>" }
|
679
723
|
end
|
680
|
-
|
724
|
+
test_eq? x.get_hook_block(:after_all).call(), "<<33326>>"
|
681
725
|
end
|
682
726
|
end
|
683
727
|
|
684
728
|
end
|
685
729
|
|
686
730
|
|
687
|
-
class
|
731
|
+
class SpecLeaf__Test
|
732
|
+
extend NanoTest
|
688
733
|
|
689
|
-
def
|
690
|
-
|
691
|
-
|
692
|
-
def teardown
|
734
|
+
def self.test_subject(desc, &b)
|
735
|
+
super
|
736
|
+
ensure
|
693
737
|
Oktest::THE_GLOBAL_SCOPE.clear_children()
|
694
738
|
end
|
695
739
|
|
696
|
-
def new_spec_object(desc="sample #1", tag: nil)
|
740
|
+
def self.new_spec_object(desc="sample #1", tag: nil)
|
697
741
|
sp = nil
|
698
742
|
Oktest.scope do
|
699
743
|
topic 'Example' do
|
@@ -703,18 +747,18 @@ class SpecLeafTC < TC
|
|
703
747
|
return sp
|
704
748
|
end
|
705
749
|
|
706
|
-
|
707
|
-
|
750
|
+
test_target 'Oktest::SpecLeaf#run_block_in_context_object()' do
|
751
|
+
test_subject "[!tssim] run spec block in text object." do
|
708
752
|
to = Oktest::TopicNode.new(nil, 'Example')
|
709
753
|
sp = Oktest::SpecLeaf.new(to, "#sample 2") { @called = "<<29193>>" }
|
710
754
|
ctx = to.new_context_object()
|
711
|
-
|
755
|
+
test_eq? ctx.instance_variable_get('@called'), nil
|
712
756
|
sp.run_block_in_context_object(ctx)
|
713
|
-
|
757
|
+
test_eq? ctx.instance_variable_get('@called'), "<<29193>>"
|
714
758
|
end
|
715
759
|
end
|
716
760
|
|
717
|
-
|
761
|
+
test_target 'Oktest::SpecLeaf#accept_visitor()' do
|
718
762
|
class DummyVisitor3
|
719
763
|
def visit_spec(*args)
|
720
764
|
@_args = args
|
@@ -722,38 +766,38 @@ class SpecLeafTC < TC
|
|
722
766
|
end
|
723
767
|
attr_reader :_args
|
724
768
|
end
|
725
|
-
|
769
|
+
test_subject "[!ya32z] invokes 'visit_spec()' method of visitor and returns result of it." do
|
726
770
|
dummy = DummyVisitor3.new
|
727
771
|
sc = Oktest::SpecLeaf.new(nil, "sample")
|
728
772
|
ret = sc.accept_visitor(dummy, 7, 8)
|
729
|
-
|
730
|
-
|
773
|
+
test_eq? dummy._args, [sc, 7, 8]
|
774
|
+
test_eq? ret, "<<82980>>"
|
731
775
|
end
|
732
776
|
end
|
733
777
|
|
734
|
-
|
735
|
-
|
778
|
+
test_target 'Oktest::SpecLeaf#unlink_parent()' do
|
779
|
+
test_subject "[!e9sv9] do nothing." do
|
736
780
|
to = Oktest::TopicNode.new(nil, "sample")
|
737
781
|
sp = Oktest::SpecLeaf.new(to, "sample")
|
738
782
|
ret = sp.unlink_parent()
|
739
|
-
|
783
|
+
test_eq? ret, nil
|
740
784
|
end
|
741
785
|
end
|
742
786
|
|
743
|
-
|
744
|
-
|
787
|
+
test_target 'Oktest::SpecLeaf#_repr()' do
|
788
|
+
test_subject "[!6nsgy] builds debug string." do
|
745
789
|
sp1 = new_spec_object("sample #1")
|
746
|
-
|
790
|
+
test_eq? sp1._repr(), "- sample #1\n"
|
747
791
|
sp2 = new_spec_object("sample #2", tag: "exp")
|
748
|
-
|
749
|
-
|
792
|
+
test_eq? sp2._repr(), "- sample #2 (tag: \"exp\")\n"
|
793
|
+
test_eq? sp2._repr(2), " - sample #2 (tag: \"exp\")\n"
|
750
794
|
end
|
751
795
|
end
|
752
796
|
|
753
|
-
|
754
|
-
|
797
|
+
test_target 'Oktest::SpecLeaf#@-' do
|
798
|
+
test_subject "[!bua80] returns self." do
|
755
799
|
sp = new_spec_object("sample #1")
|
756
|
-
|
800
|
+
test_ok? (- sp).equal?(sp), msg: "should be same"
|
757
801
|
end
|
758
802
|
end
|
759
803
|
|