oktest 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/node_test.rb CHANGED
@@ -2,237 +2,240 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  ###
5
- ### $Release: 1.4.0 $
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 './initialize'
10
+ require_relative './init'
11
11
 
12
12
 
13
- class Item_TC < TC
13
+ class Item__Test
14
+ extend NanoTest
14
15
 
15
- describe '#accept_visitor()' do
16
- it "[!b0e20] raises NotImplementedError." do
17
- assert_exc(NotImplementedError, "Oktest::Item#accept_visitor(): not implemented yet.") do
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
- describe '#unlink_parent()' do
24
- it "[!5a0i9] raises NotImplementedError." do
25
- assert_exc(NotImplementedError, "Oktest::Item#unlink_parent(): not implemented yet.") do
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
- describe '#_repr()' do
32
- it "[!qi1af] raises NotImplementedError." do
33
- assert_exc(NotImplementedError, "Oktest::Item#_repr(): not implemented yet.") do
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 Node_TC < TC
46
+ class Node__Test
47
+ extend NanoTest
43
48
 
44
- def setup()
45
- end
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
- describe '#add_child()' do
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
- assert_eq p.instance_eval('@children'), [c]
60
+ test_eq? p.instance_eval('@children'), [c]
58
61
  end
59
- it "[!w5r6l] returns self." do
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
- assert ret.equal?(p), "should be same"
66
+ test_ok? ret.equal?(p), msg: "should be same"
64
67
  end
65
68
  end
66
69
 
67
- describe '#has_child?' do
68
- it "[!xb30d] return true when no children, else false." do
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
- assert_eq p.has_child?, true
73
- assert_eq c.has_child?, false
75
+ test_eq? p.has_child?, true
76
+ test_eq? c.has_child?, false
74
77
  end
75
78
  end
76
79
 
77
- describe '#each_child()' do
78
- it "[!osoep] returns enumerator if block not given." do
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
- assert_eq node.each_child.class, Enumerator
83
+ test_eq? node.each_child.class, Enumerator
81
84
  end
82
- it "[!pve8m] yields block for each child." do
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
- assert_eq arr.length, 2
89
- assert_eq arr[0], c1
90
- assert_eq arr[1], c2
91
+ test_eq? arr.length, 2
92
+ test_eq? arr[0], c1
93
+ test_eq? arr[1], c2
91
94
  end
92
- it "[!8z6un] returns nil." do
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
- assert_eq ret, nil
100
+ test_eq? ret, nil
98
101
  end
99
102
  end
100
103
 
101
- describe '#remove_child()' do
102
- it "[!hsomo] removes child at index." do
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
- assert_eq children.length, 1
109
- assert_eq children[0], c2
111
+ test_eq? children.length, 1
112
+ test_eq? children[0], c2
110
113
  end
111
- it "[!hiz1b] returns removed child." do
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
- assert_eq ret, c1
119
+ test_eq? ret, c1
117
120
  end
118
- it "[!7fhx1] unlinks reference between parent and child." do
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
- assert_eq c2.parent, nil
124
- assert_eq c1.parent, p
126
+ test_eq? c2.parent, nil
127
+ test_eq? c1.parent, p
125
128
  end
126
129
  end
127
130
 
128
- describe '#clear_children()' do
129
- it "[!o8xfb] removes all children." do
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
- assert_eq p.has_child?, true
136
+ test_eq? p.has_child?, true
134
137
  p.clear_children()
135
- assert_eq p.has_child?, false
138
+ test_eq? p.has_child?, false
136
139
  end
137
- it "[!cvaq1] return self." do
140
+ test_subject "[!cvaq1] return self." do
138
141
  p = Oktest::Node.new(nil)
139
- assert p.clear_children().equal?(p)
142
+ test_ok? p.clear_children().equal?(p)
140
143
  end
141
144
  end
142
145
 
143
- describe '#unlink_parent()' do
144
- it "[!59m52] clears '@parent' instance variable." do
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
- assert_eq c.parent, p
150
+ test_eq? c.parent, p
148
151
  c.unlink_parent()
149
- assert_eq c.parent, nil
152
+ test_eq? c.parent, nil
150
153
  end
151
- it "[!qksxv] returns parent object." do
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
- assert_eq ret, p
158
+ test_eq? ret, p
156
159
  end
157
160
  end
158
161
 
159
- describe '#run_block_in_context_class()' do
160
- it "[!j9qdh] run block in context class." do
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
- assert_eq val, "<<00807>>"
167
+ test_eq? val, "<<00807>>"
165
168
  end
166
169
  end
167
170
 
168
- describe '#new_context_object()' do
169
- it "[!p271z] creates new context object." do
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
- assert_eq ctx.class, x.context_class
173
- assert ctx.is_a?(Oktest::Context)
175
+ test_eq? ctx.class, x.context_class
176
+ test_ok? ctx.is_a?(Oktest::Context)
174
177
  end
175
- it "[!9hbxn] context object has 'ok()' method." do
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
- assert ctx.respond_to?(:ok)
179
- assert ctx.respond_to?(:not_ok)
180
- assert ctx.respond_to?(:skip_when)
181
- assert ctx.respond_to?(:at_end)
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
- describe '#register_fixture_block()' do
186
- it "[!5ctsn] registers fixture name, block, and location." do
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
- assert x.fixtures[:foo][0].is_a?(Proc), "proc object expected"
190
- assert_eq x.fixtures[:foo][0].call(1, 2), "foobar"
191
- assert_eq x.fixtures[:foo][1], [:a, :b]
192
- assert_eq x.fixtures[:foo][2], "file:123"
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
- assert_eq x.fixtures[:bar][0].call(), "barbar"
196
- assert_eq x.fixtures[:bar][1], nil
197
- assert_eq x.fixtures[:bar][2], "file:345"
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
- it "[!hfcvo] returns self." do
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
- assert ret.equal?(x)
205
+ test_ok? ret.equal?(x)
203
206
  end
204
207
  end
205
208
 
206
- describe '#get_fixture_block()' do
207
- it "[!f0105] returns fixture info." do
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
- assert_eq x.get_fixture_block(:foo), ["block", [:a, :b], "file:123"]
213
+ test_eq? x.get_fixture_block(:foo), ["block", [:a, :b], "file:123"]
211
214
  end
212
215
  end
213
216
 
214
- describe '#register_hook_block()' do
215
- it "[!zb66o] registers block with key." do
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
- assert_eq x.hooks[:before].call(), "<<42533>>"
220
- assert_eq x.hooks[:after].call(), "<<46675>>"
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
- describe '#get_hook_block()' do
225
- it "[!u3fc6] returns block corresponding to key." do
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
- assert_eq x.get_hook_block(:before).call(), "<<42533>>"
230
- assert_eq x.get_hook_block(:after).call(), "<<46675>>"
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
- describe '#_repr()' do
235
- it "[!bt5j8] builds debug string." do
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
- #assert_eq result, expected
248
- assert result =~ Regexp.compile('\A'+expected), "not matched"
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 ScopeNode_TC < TC
258
+ class ScopeNode__Test
259
+ extend NanoTest
256
260
 
257
- describe '#accept_visitor()' do
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
- it "[!vr6ko] invokes 'visit_spec()' method of visitor and returns result of it." do
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
- assert_eq dummy._args, [sc, 1, 2, 3]
270
- assert_eq ret, "<<43746>>"
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 TopicNode_TC < TC
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
- describe '#accept_visitor()' do
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
- it "[!c1b33] invokes 'visit_topic()' method of visitor and returns result of it." do
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
- assert_eq dummy._args, [to, 4, 5]
296
- assert_eq ret, "<<55977>>"
319
+ test_eq? dummy._args, [to, 4, 5]
320
+ test_eq? ret, "<<55977>>"
297
321
  end
298
322
  end
299
323
 
300
- describe '#@+' do
301
- it "[!tzorv] returns self." do
324
+ test_target 'Oktest::TopicNode#@+' do
325
+ test_subject "[!tzorv] returns self." do
302
326
  to = new_topic('#foobar()')
303
- assert (+ to).equal?(to), "should be same"
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 ScopeFunctions_TC < TC
334
+ class OktestFuncs__Test
335
+ extend NanoTest
311
336
 
312
- def startup
313
- end
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
- describe 'Oktest.scope()' do
352
- it "[!vxoy1] creates new scope object." do
375
+ test_target 'Oktest.scope()' do
376
+ test_subject "[!vxoy1] creates new scope object." do
353
377
  x = Oktest.scope() { nil }
354
- assert_eq x.class, Oktest::ScopeNode
378
+ test_eq? x.class, Oktest::ScopeNode
355
379
  end
356
- it "[!jmc4q] raises error when nested called." do
380
+ test_subject "[!jmc4q] raises error when nested called." do
357
381
  begin ; x = 0
358
- assert_exc(Oktest::OktestError, "scope() and global_scope() are not nestable.") do
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
- assert_eq x, 2
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
- it "[!rsimc] adds scope object as child of THE_GLOBAL_SCOPE." do
371
- assert_eq Oktest::THE_GLOBAL_SCOPE.has_child?, false
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
- assert_eq Oktest::THE_GLOBAL_SCOPE.has_child?, true
375
- assert_eq Oktest::THE_GLOBAL_SCOPE.each_child.to_a, [so]
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
- it "[!kem4y] detects test script filename." do
402
+ test_subject "[!kem4y] detects test script filename." do
378
403
  sc = Oktest.scope() { nil }
379
- assert_eq sc.filename, "test/node_test.rb"
404
+ test_eq? sc.filename, "test/node_test.rb"
380
405
  end
381
- it "[!6ullm] changes test script filename from absolute path to relative path." do
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
- assert_eq sc.filename, "tests/foo_test.rb"
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
- assert_eq sc.filename, "t/bar_test.rb"
413
+ test_eq? sc.filename, "t/bar_test.rb"
389
414
  end
390
415
  end
391
416
  end
392
417
 
393
- describe '#global_scope()' do
394
- it "[!fcmt2] not create new scope object." do
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
- assert_eq go1.class, Oktest::ScopeNode
421
+ test_eq? go1.class, Oktest::ScopeNode
397
422
  go2 = Oktest.global_scope() { nil }
398
- assert_eq go2, go1
399
- assert_eq go2, Oktest::THE_GLOBAL_SCOPE
423
+ test_eq? go2, go1
424
+ test_eq? go2, Oktest::THE_GLOBAL_SCOPE
400
425
  end
401
- it "[!flnpc] run block in the THE_GLOBAL_SCOPE object." do
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
- assert Oktest::THE_GLOBAL_SCOPE.fixtures.key?(:tmp_37531)
432
+ test_ok? Oktest::THE_GLOBAL_SCOPE.fixtures.key?(:tmp_37531)
408
433
  v = Oktest::THE_GLOBAL_SCOPE.fixtures[:tmp_37531][0].call
409
- assert_eq v, {id: 37531}
434
+ test_eq? v, {id: 37531}
410
435
  end
411
- it "[!pe0g2] raises error when nested called." do
412
- args = [Oktest::OktestError, "scope() and global_scope() are not nestable."]
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
- assert_exc(*args) do ; x = 1
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
- assert_eq x, 2
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
- assert_exc(*args) do ; x = 1
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
- assert_eq x, 2
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
- assert_exc(*args) do ; x = 1
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
- assert_eq x, 2
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 Context_TC < TC
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
- describe '#topic()' do
465
- it "[!0gfvq] creates new topic node." do
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
- assert_eq node.each_child.to_a.length, 1
512
+ test_eq? node.each_child.to_a.length, 1
471
513
  to = node.each_child.first
472
- assert_eq to.class, Oktest::TopicNode
473
- assert_eq to.target, Dir
474
- assert_eq to.tag, "exp"
475
- assert_eq to._prefix, "*"
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
- describe '#case_when()' do
480
- it "[!g3cvh] returns topic object." do
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
- assert_eq node.each_child.to_a.length, 1
527
+ test_eq? node.each_child.to_a.length, 1
486
528
  to = node.each_child.first
487
- assert_eq to.class, Oktest::TopicNode
488
- assert_eq to.target, "When condition..."
489
- assert_eq to.tag, nil
490
- assert_eq to._prefix, "-"
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
- it "[!ofw1i] target is a description starting with 'When '." do
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
- assert_eq to.target, "When condition..."
540
+ test_eq? to.target, "When condition..."
499
541
  end
500
- it "[!53qxv] not add 'When ' if description starts with it." do
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
- assert_eq to.target, "when condition..."
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
- assert_eq to.target, "[""!abc] when..."
555
+ test_eq? to.target, "[""!abc] when..."
514
556
  end
515
557
  end
516
558
 
517
- describe '#case_else()' do
518
- it "[!oww4b] returns topic object." do
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
- assert_eq node.each_child.to_a.length, 1
565
+ test_eq? node.each_child.to_a.length, 1
524
566
  to = node.each_child.first
525
- assert_eq to.class, Oktest::TopicNode
526
- assert_eq to.target, "Else"
527
- assert_eq to.tag, "dev"
528
- assert_eq to._prefix, "-"
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
- it "[!j5gnp] target is a description which is 'Else'." do
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
- assert_eq node.each_child.to_a.length, 1
577
+ test_eq? node.each_child.to_a.length, 1
536
578
  to = node.each_child.first
537
- assert_eq to.class, Oktest::TopicNode
538
- assert_eq to.target, "Else"
579
+ test_eq? to.class, Oktest::TopicNode
580
+ test_eq? to.target, "Else"
539
581
  end
540
- it "[!3nn8d] not add 'Else ' if description starts with it." do
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
- assert_eq node.each_child.to_a.length, 1
587
+ test_eq? node.each_child.to_a.length, 1
546
588
  to = node.each_child.first
547
- assert_eq to.class, Oktest::TopicNode
548
- assert_eq to.target, "else (x < 0)"
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
- assert_eq node.each_child.to_a.length, 1
596
+ test_eq? node.each_child.to_a.length, 1
555
597
  to = node.each_child.first
556
- assert_eq to.class, Oktest::TopicNode
557
- assert_eq to.target, "[""!abc] else..."
598
+ test_eq? to.class, Oktest::TopicNode
599
+ test_eq? to.target, "[""!abc] else..."
558
600
  end
559
- it "[!hs1to] 1st parameter is optional." do
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
- assert_eq node.each_child.to_a.length, 1
606
+ test_eq? node.each_child.to_a.length, 1
565
607
  to = node.each_child.first
566
- assert_eq to.class, Oktest::TopicNode
567
- assert_eq to.target, "Else (x < 0)"
608
+ test_eq? to.class, Oktest::TopicNode
609
+ test_eq? to.target, "Else (x < 0)"
568
610
  end
569
611
  end
570
612
 
571
- describe '#scope()' do
572
- it "[!c8c8o] creates new spec object." do
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
- assert_eq node.each_child.to_a.length, 1
619
+ test_eq? node.each_child.to_a.length, 1
578
620
  sp = node.each_child.first
579
- assert_eq sp.class, Oktest::SpecLeaf
580
- assert_eq sp.desc, "example #1"
581
- assert_eq sp.tag, "exp"
582
- assert_eq sp._prefix, "-"
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
- it "[!4vkbl] error when `fixture:` keyword arg is not a Hash object." do
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
- assert_exc(ArgumentError, 'spec(fixture: "x: 1"): fixture argument should be a Hash object, but got String object.') do
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
- it "[!ala78] provides raising TodoException block if block not given." do
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
- assert_eq node.each_child.to_a.length, 1
641
+ test_eq? node.each_child.to_a.length, 1
599
642
  sp = node.each_child.first
600
- assert_exc(Oktest::TodoException, "not implemented yet") do
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
- it "[!x48db] keeps called location only when block has parameters." do
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
- assert_eq sp1.location, nil
612
- assert sp2.location != nil, "not nil"
613
- assert sp2.location.to_s.start_with?("#{__FILE__}:#{lineno}:in")
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
- describe '#fixture()' do
618
- it "[!8wfrq] registers fixture factory block." do
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
- assert_eq node.fixtures.length, 1
626
- assert node.fixtures.key?(:alice), "key not registerd"
627
- assert node.fixtures[:alice][0].is_a?(Proc), "block expected"
628
- assert_eq node.fixtures[:alice][1], nil
629
- assert node.fixtures[:alice][2].to_s.start_with?("#{__FILE__}:#{lineno}:in ")
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
- it "[!y3ks3] retrieves block parameter names." do
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
- assert_eq node.fixtures[:bob][1], [:x, :y]
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
- assert_eq node.fixtures[:charlie][1], nil
688
+ test_eq? node.fixtures[:charlie][1], nil
645
689
  end
646
690
  end
647
691
 
648
- describe '#before() ' do
649
- it "[!275zr] registers 'before' hook block." do
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
- assert_eq x.get_hook_block(:before).call(), "<<78059>>"
697
+ test_eq? x.get_hook_block(:before).call(), "<<78059>>"
654
698
  end
655
699
  end
656
700
 
657
- describe '#after() ' do
658
- it "[!ngkvz] registers 'after' hook block." do
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
- assert_eq x.get_hook_block(:after).call(), "<<52091>>"
706
+ test_eq? x.get_hook_block(:after).call(), "<<52091>>"
663
707
  end
664
708
  end
665
709
 
666
- describe '#before_all() ' do
667
- it "[!8v1y4] registers 'before_all' hook block." do
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
- assert_eq x.get_hook_block(:before_all).call(), "<<42577>>"
715
+ test_eq? x.get_hook_block(:before_all).call(), "<<42577>>"
672
716
  end
673
717
  end
674
718
 
675
- describe '#after_all() ' do
676
- it "[!0w5ik] registers 'after_all' hook block." do
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
- assert_eq x.get_hook_block(:after_all).call(), "<<33326>>"
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 SpecLeafTC < TC
731
+ class SpecLeaf__Test
732
+ extend NanoTest
688
733
 
689
- def startup
690
- end
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
- describe '#run_block_in_context_object()' do
707
- it "[!tssim] run spec block in text object." do
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
- assert_eq ctx.instance_variable_get('@called'), nil
755
+ test_eq? ctx.instance_variable_get('@called'), nil
712
756
  sp.run_block_in_context_object(ctx)
713
- assert_eq ctx.instance_variable_get('@called'), "<<29193>>"
757
+ test_eq? ctx.instance_variable_get('@called'), "<<29193>>"
714
758
  end
715
759
  end
716
760
 
717
- describe '#accept_visitor()' do
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
- it "[!ya32z] invokes 'visit_spec()' method of visitor and returns result of it." do
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
- assert_eq dummy._args, [sc, 7, 8]
730
- assert_eq ret, "<<82980>>"
773
+ test_eq? dummy._args, [sc, 7, 8]
774
+ test_eq? ret, "<<82980>>"
731
775
  end
732
776
  end
733
777
 
734
- describe '#unlink_parent()' do
735
- it "[!e9sv9] do nothing." do
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
- assert_eq ret, nil
783
+ test_eq? ret, nil
740
784
  end
741
785
  end
742
786
 
743
- describe '#_repr()' do
744
- it "[!6nsgy] builds debug string." do
787
+ test_target 'Oktest::SpecLeaf#_repr()' do
788
+ test_subject "[!6nsgy] builds debug string." do
745
789
  sp1 = new_spec_object("sample #1")
746
- assert_eq sp1._repr(), "- sample #1\n"
790
+ test_eq? sp1._repr(), "- sample #1\n"
747
791
  sp2 = new_spec_object("sample #2", tag: "exp")
748
- assert_eq sp2._repr(), "- sample #2 (tag: \"exp\")\n"
749
- assert_eq sp2._repr(2), " - sample #2 (tag: \"exp\")\n"
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
- describe '#@-' do
754
- it "[!bua80] returns self." do
797
+ test_target 'Oktest::SpecLeaf#@-' do
798
+ test_subject "[!bua80] returns self." do
755
799
  sp = new_spec_object("sample #1")
756
- assert (- sp).equal?(sp), "should be same"
800
+ test_ok? (- sp).equal?(sp), msg: "should be same"
757
801
  end
758
802
  end
759
803