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