oktest 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/helper_test.rb CHANGED
@@ -2,12 +2,12 @@
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
13
  class DummyUser
@@ -19,83 +19,85 @@ class DummyUser
19
19
  end
20
20
 
21
21
 
22
- class SpecHelper_TC < TC
23
- include Oktest::SpecHelper
22
+ class SpecHelper__Test
23
+ extend NanoTest
24
+ extend Oktest::SpecHelper
24
25
 
25
- def setup()
26
- end
27
-
28
- def teardown()
26
+ def self.test_subject(desc, &b)
27
+ super
28
+ ensure
29
29
  Oktest::AssertionObject::NOT_YET.clear()
30
+ @__at_end_blocks = nil
30
31
  end
31
32
 
32
- describe '#ok()' do
33
- it "[!3jhg6] creates new assertion object." do
33
+ test_target 'Oktest::SpecHelper#ok()' do
34
+ test_subject "[!3jhg6] creates new assertion object." do
34
35
  o = ok {"foo"}
35
- assert_eq o.class, Oktest::AssertionObject
36
- assert_eq o.actual, "foo"
37
- assert_eq o.bool, true
36
+ test_eq? o.class, Oktest::AssertionObject
37
+ test_eq? o.actual, "foo"
38
+ test_eq? o.bool, true
38
39
  end
39
- it "[!bc3l2] records invoked location." do
40
+ test_subject "[!bc3l2] records invoked location." do
40
41
  lineno = __LINE__ + 1
41
42
  o = ok {"bar"}
42
- assert o.location.to_s.start_with?("#{__FILE__}:#{lineno}:")
43
+ test_ok? o.location.to_s.start_with?("#{__FILE__}:#{lineno}:")
43
44
  end
44
- it "[!mqtdy] not record invoked location when `Config.ok_location == false`." do
45
+ test_subject "[!mqtdy] not record invoked location when `Config.ok_location == false`." do
45
46
  bkup = Oktest::Config.ok_location
46
47
  begin
47
48
  Oktest::Config.ok_location = false
48
49
  o = ok {"bar"}
49
- assert_eq o.location, nil
50
+ test_eq? o.location, nil
50
51
  ensure
51
52
  Oktest::Config.ok_location = bkup
52
53
  end
53
54
  end
54
55
  end
55
56
 
56
- describe '#not_ok()' do
57
- it "[!d332o] creates new assertion object for negative condition." do
57
+ test_target 'Oktest::SpecHelper#not_ok()' do
58
+ test_subject "[!d332o] creates new assertion object for negative condition." do
58
59
  o = not_ok {"abc"}
59
- assert_eq o.class, Oktest::AssertionObject
60
- assert_eq o.actual, "abc"
61
- assert_eq o.bool, false
60
+ test_eq? o.class, Oktest::AssertionObject
61
+ test_eq? o.actual, "abc"
62
+ test_eq? o.bool, false
62
63
  end
63
- it "[!agmx8] records invoked location." do
64
+ test_subject "[!agmx8] records invoked location." do
64
65
  lineno = __LINE__ + 1
65
66
  o = not_ok {"bar"}
66
- assert o.location.to_s.start_with?("#{__FILE__}:#{lineno}:")
67
+ test_ok? o.location.to_s.start_with?("#{__FILE__}:#{lineno}:")
67
68
  end
68
- it "[!a9508] not record invoked location when `Config.ok_location == false`." do
69
+ test_subject "[!a9508] not record invoked location when `Config.ok_location == false`." do
69
70
  bkup = Oktest::Config.ok_location
70
71
  begin
71
72
  Oktest::Config.ok_location = false
72
73
  o = not_ok {"bar"}
73
- assert_eq o.location, nil
74
+ test_eq? o.location, nil
74
75
  ensure
75
76
  Oktest::Config.ok_location = bkup
76
77
  end
77
78
  end
78
79
  end
79
80
 
80
- describe '#skip_when()' do
81
- it "[!3xqf4] raises SkipException if condition is truthy." do
82
- assert_exc(Oktest::SkipException, "..reason..") do
81
+ test_target 'Oktest::SpecHelper#skip_when()' do
82
+ test_subject "[!3xqf4] raises SkipException if condition is truthy." do
83
+ exc = test_exception? Oktest::SkipException do
83
84
  skip_when (1+1 == 2), "..reason.."
84
85
  end
86
+ test_eq? exc.message, "..reason.."
85
87
  end
86
- it "[!r7cxx] not raise nothing if condition is falsy." do
88
+ test_subject "[!r7cxx] not raise nothing if condition is falsy." do
87
89
  begin
88
90
  skip_when (1+1 == 0), "..reason.."
89
91
  rescue Exception => exc
90
- assert false, "nothing should be raised but #{exc.class} raised"
92
+ test_ok? false, "nothing should be raised but #{exc.class} raised"
91
93
  else
92
- assert true, "OK"
94
+ test_ok? true, msg: "OK"
93
95
  end
94
96
  end
95
97
  end
96
98
 
97
- describe '#fixture()' do
98
- it "[!m4ava] calls fixture block and returns result of it." do
99
+ test_target 'Oktest::SpecHelper#fixture()' do
100
+ test_subject "[!m4ava] calls fixture block and returns result of it." do
99
101
  val = nil
100
102
  Oktest.scope() do
101
103
  topic 'Example' do
@@ -105,10 +107,10 @@ class SpecHelper_TC < TC
105
107
  end
106
108
  end
107
109
  end
108
- capture { Oktest.run() }
109
- assert_eq val, "<<foo>>"
110
+ capture_output! { Oktest.run() }
111
+ test_eq? val, "<<foo>>"
110
112
  end
111
- it "[!zgfg9] finds fixture block in current or parent node." do
113
+ test_subject "[!zgfg9] finds fixture block in current or parent node." do
112
114
  val1 = val2 = val3 = nil
113
115
  Oktest.scope() do
114
116
  fixture :foo do "<<foo>>" end
@@ -124,12 +126,12 @@ class SpecHelper_TC < TC
124
126
  end
125
127
  end
126
128
  end
127
- capture { Oktest.run() }
128
- assert_eq val1, "<<baz>>"
129
- assert_eq val2, "<<bar>>"
130
- assert_eq val3, "<<foo>>"
129
+ capture_output! { Oktest.run() }
130
+ test_eq? val1, "<<baz>>"
131
+ test_eq? val2, "<<bar>>"
132
+ test_eq? val3, "<<foo>>"
131
133
  end
132
- it "[!l2mcx] accepts block arguments." do
134
+ test_subject "[!l2mcx] accepts block arguments." do
133
135
  val = nil
134
136
  Oktest.scope() do
135
137
  fixture :foo do |x, y, z: 0|
@@ -141,10 +143,10 @@ class SpecHelper_TC < TC
141
143
  end
142
144
  end
143
145
  end
144
- capture { Oktest.run() }
145
- assert_eq val, {x: 10, y: 20, z: 30}
146
+ capture_output! { Oktest.run() }
147
+ test_eq? val, {x: 10, y: 20, z: 30}
146
148
  end
147
- it "[!wxcsp] raises error when fixture not found." do
149
+ test_subject "[!wxcsp] raises error when fixture not found." do
148
150
  exc = nil
149
151
  Oktest.scope() do
150
152
  fixture :foo do "<<foo>>" end
@@ -157,14 +159,14 @@ class SpecHelper_TC < TC
157
159
  end
158
160
  end
159
161
  end
160
- capture { Oktest.run() }
161
- assert_eq exc.class, Oktest::FixtureNotFoundError
162
- assert_eq exc.message, "`:bar`: fixture not found."
162
+ capture_output! { Oktest.run() }
163
+ test_eq? exc.class, Oktest::FixtureNotFoundError
164
+ test_eq? exc.message, "`:bar`: fixture not found."
163
165
  end
164
166
  end
165
167
 
166
- describe '#at_end()' do
167
- it "[!x58eo] records clean-up block." do
168
+ test_target 'Oktest::SpecHelper#at_end()' do
169
+ test_subject "[!x58eo] records clean-up block." do
168
170
  Oktest.scope() do
169
171
  topic 'Example' do
170
172
  spec 'sample #1' do
@@ -174,342 +176,346 @@ class SpecHelper_TC < TC
174
176
  end
175
177
  end
176
178
  end
177
- sout, serr = capture { Oktest.run() }
179
+ sout, serr = capture_output! { Oktest.run() }
178
180
  expected = <<'END'
179
181
  before at_end()
180
182
  after at_end()
181
183
  in at_end()
182
184
  END
183
- assert sout.include?(expected), "not matched"
185
+ test_ok? sout.include?(expected), msg: "not matched"
184
186
  end
185
187
  end
186
188
 
187
- describe '#capture_stdio()' do
188
- it "[!1kbnj] captures $stdio and $stderr." do
189
+ test_target 'Oktest::SpecHelper#capture_stdio()' do
190
+ test_subject "[!1kbnj] captures $stdio and $stderr." do
189
191
  sout, serr = capture_stdio() do
190
192
  puts "fooo"
191
193
  $stderr.puts "baaa"
192
194
  end
193
- assert_eq sout, "fooo\n"
194
- assert_eq serr, "baaa\n"
195
+ test_eq? sout, "fooo\n"
196
+ test_eq? serr, "baaa\n"
195
197
  end
196
- it "[!53mai] takes $stdin data." do
198
+ test_subject "[!53mai] takes $stdin data." do
197
199
  data = nil
198
200
  sout, serr = capture_stdio("blabla") do
199
201
  data = $stdin.read()
200
202
  end
201
203
  data = "blabla"
202
204
  end
203
- it "[!wq8a9] recovers stdio even when exception raised." do
205
+ test_subject "[!wq8a9] recovers stdio even when exception raised." do
204
206
  stdin_, stdout_, stderr_ = $stdin, $stdout, $stderr
205
207
  exception = nil
206
208
  begin
207
209
  sout, serr = capture_stdio() do
208
210
  puts "fooo"
209
211
  $stderr.puts "baaa"
210
- assert stdin_ != $stdin , "stdin should be replaced"
211
- assert stdout_ != $stdout, "stdout should be replaced"
212
- assert stderr_ != $stderr, "stderr should be replaced"
212
+ test_ok? stdin_ != $stdin , msg: "stdin should be replaced"
213
+ test_ok? stdout_ != $stdout, msg: "stdout should be replaced"
214
+ test_ok? stderr_ != $stderr, msg: "stderr should be replaced"
213
215
  1/0 # ZeroDivisionError
214
216
  end
215
217
  rescue ZeroDivisionError => exc
216
218
  exception = exc
217
219
  end
218
- assert exception != nil, "exception should be raised."
219
- assert exception.is_a?(ZeroDivisionError), "ZeroDivisionError should be raised."
220
- assert stdin_ == $stdin , "stdin should be recovered"
221
- assert stdout_ == $stdout, "stdout should be recovered"
222
- assert stderr_ == $stderr, "stderr should be recovered"
220
+ test_ok? exception != nil, msg: "exception should be raised."
221
+ test_ok? exception.is_a?(ZeroDivisionError), msg: "ZeroDivisionError should be raised."
222
+ test_ok? stdin_ == $stdin , msg: "stdin should be recovered"
223
+ test_ok? stdout_ == $stdout, msg: "stdout should be recovered"
224
+ test_ok? stderr_ == $stderr, msg: "stderr should be recovered"
223
225
  end
224
- it "[!4j494] returns outpouts of stdout and stderr." do
226
+ test_subject "[!4j494] returns outpouts of stdout and stderr." do
225
227
  sout, serr = capture_stdio() do
226
228
  puts "foo"
227
229
  $stderr.puts "bar"
228
230
  end
229
- assert_eq sout, "foo\n"
230
- assert_eq serr, "bar\n"
231
+ test_eq? sout, "foo\n"
232
+ test_eq? serr, "bar\n"
231
233
  end
232
- it "[!6ik8b] can simulate tty." do
234
+ test_subject "[!6ik8b] can simulate tty." do
233
235
  sout, serr = capture_stdio() do
234
- assert_eq $stdin.tty?, false
235
- assert_eq $stdout.tty?, false
236
- assert_eq $stderr.tty?, false
236
+ test_eq? $stdin.tty?, false
237
+ test_eq? $stdout.tty?, false
238
+ test_eq? $stderr.tty?, false
237
239
  end
238
240
  #
239
241
  sout, serr = capture_stdio(tty: true) do
240
- assert_eq $stdin.tty?, true
241
- assert_eq $stdout.tty?, true
242
- assert_eq $stderr.tty?, true
242
+ test_eq? $stdin.tty?, true
243
+ test_eq? $stdout.tty?, true
244
+ test_eq? $stderr.tty?, true
243
245
  end
244
246
  end
245
247
  end
246
248
 
247
- describe '#capture_sio()' do
248
- it "[!qjmaa] 'capture_sio()' is an alias of 'capture_stdio()'." do
249
+ test_target 'Oktest::SpecHelper#capture_sio()' do
250
+ test_subject "[!qjmaa] 'capture_sio()' is an alias of 'capture_stdio()'." do
249
251
  sin = nil
250
252
  sout, serr = capture_sio("INPUT", tty: true) do
251
253
  sin = $stdin.read()
252
254
  puts "OUTPUT"
253
255
  $stderr.puts "ERROR"
254
- assert_eq $stdin.tty?, true
255
- assert_eq $stdout.tty?, true
256
- assert_eq $stdout.tty?, true
256
+ test_eq? $stdin.tty?, true
257
+ test_eq? $stdout.tty?, true
258
+ test_eq? $stdout.tty?, true
257
259
  end
258
- assert_eq sin, "INPUT"
259
- assert_eq sout, "OUTPUT\n"
260
- assert_eq serr, "ERROR\n"
260
+ test_eq? sin, "INPUT"
261
+ test_eq? sout, "OUTPUT\n"
262
+ test_eq? serr, "ERROR\n"
261
263
  end
262
264
  end
263
265
 
264
- describe '#capture_stdout()' do
265
- it "[!4agii] same as `sout, serr = capture_stdio(); ok {serr} == ''`." do
266
+ test_target 'Oktest::SpecHelper#capture_stdout()' do
267
+ test_subject "[!4agii] same as `sout, serr = capture_stdio(); ok {serr} == ''`." do
266
268
  sin = nil
267
269
  sout = capture_stdout("INPUT", tty: true) do
268
270
  sin = $stdin.read()
269
271
  puts "OUTPUT"
270
- assert_eq $stdin.tty?, true
271
- assert_eq $stdout.tty?, true
272
- assert_eq $stderr.tty?, true
272
+ test_eq? $stdin.tty?, true
273
+ test_eq? $stdout.tty?, true
274
+ test_eq? $stderr.tty?, true
273
275
  end
274
- assert_eq sin, "INPUT"
275
- assert_eq sout, "OUTPUT\n"
276
+ test_eq? sin, "INPUT"
277
+ test_eq? sout, "OUTPUT\n"
276
278
  end
277
- it "[!may84] fails when stderr is not empty." do
278
- assert_exc(Oktest::AssertionFailed, "Output of $stderr expected to be empty, but got: \"ERROR\"") do
279
+ test_subject "[!may84] fails when stderr is not empty." do
280
+ exc = test_exception? Oktest::AssertionFailed do
279
281
  capture_stdout() do
280
282
  $stderr.print "ERROR"
281
283
  end
282
284
  end
285
+ test_eq? exc.message, "Output of $stderr expected to be empty, but got: \"ERROR\""
283
286
  end
284
- it "[!5n04e] returns output of stdout." do
287
+ test_subject "[!5n04e] returns output of stdout." do
285
288
  sout = capture_stdout() do
286
289
  print "OUTPUT"
287
290
  end
288
- assert_eq sout, "OUTPUT"
291
+ test_eq? sout, "OUTPUT"
289
292
  end
290
293
  end
291
294
 
292
- describe '#capture_stderr()' do
293
- it "[!46tj4] same as `sout, serr = capture_stdio(); ok {sout} == ''`." do
295
+ test_target 'Oktest::SpecHelper#capture_stderr()' do
296
+ test_subject "[!46tj4] same as `sout, serr = capture_stdio(); ok {sout} == ''`." do
294
297
  sin = nil
295
298
  serr = capture_stderr("INPUT", tty: true) do
296
299
  sin = $stdin.read()
297
300
  $stderr.puts "ERROR"
298
- assert_eq $stdin.tty?, true
299
- assert_eq $stdout.tty?, true
300
- assert_eq $stderr.tty?, true
301
+ test_eq? $stdin.tty?, true
302
+ test_eq? $stdout.tty?, true
303
+ test_eq? $stderr.tty?, true
301
304
  end
302
- assert_eq sin, "INPUT"
303
- assert_eq serr, "ERROR\n"
305
+ test_eq? sin, "INPUT"
306
+ test_eq? serr, "ERROR\n"
304
307
  end
305
- it "[!3zh32] fails when stdout is not empty." do
306
- assert_exc(Oktest::AssertionFailed, "Output of $stdout expected to be empty, but got: \"OUTPUT\"") do
308
+ test_subject "[!3zh32] fails when stdout is not empty." do
309
+ exc = test_exception? Oktest::AssertionFailed do
307
310
  capture_stderr() do
308
311
  print "OUTPUT"
309
312
  end
310
313
  end
314
+ test_eq? exc.message, "Output of $stdout expected to be empty, but got: \"OUTPUT\""
311
315
  end
312
- it "[!5vs64] returns output of stderr." do
316
+ test_subject "[!5vs64] returns output of stderr." do
313
317
  serr = capture_stderr() do
314
318
  $stderr.print "ERROR"
315
319
  end
316
- assert_eq serr, "ERROR"
320
+ test_eq? serr, "ERROR"
317
321
  end
318
322
  end
319
323
 
320
- describe '#capture_command()' do
321
- it "[!wyp17] executes command with stdin data." do
324
+ test_target 'Oktest::SpecHelper#capture_command()' do
325
+ test_subject "[!wyp17] executes command with stdin data." do
322
326
  sout, serr = capture_command("cat -n", "AAA\nBBB\n")
323
- assert_eq sout, " 1\tAAA\n 2\tBBB\n"
324
- assert_eq serr, ""
327
+ test_eq? sout, " 1\tAAA\n 2\tBBB\n"
328
+ test_eq? serr, ""
325
329
  end
326
- it "[!jd63p] raises error if command failed." do
330
+ test_subject "[!jd63p] raises error if command failed." do
327
331
  begin
328
332
  capture_command("ls *not*exist*")
329
333
  rescue => exc
330
- assert_eq exc.class, RuntimeError
331
- assert_eq exc.message, "Command failed with status (1): `ls *not*exist*`"
334
+ test_eq? exc.class, RuntimeError
335
+ test_eq? exc.message, "Command failed with status (1): `ls *not*exist*`"
332
336
  else
333
- assert false, "Exception should be raised but not."
337
+ test_ok? false, msg: "Exception should be raised but not."
334
338
  end
335
339
  end
336
- it "[!lsmgq] calls error handler block if command failed." do
340
+ test_subject "[!lsmgq] calls error handler block if command failed." do
337
341
  called = nil
338
342
  sout, serr = capture_command("ls *not*exist*") do |pstat|
339
343
  called = pstat
340
344
  end
341
- assert called.is_a?(Process::Status)
342
- assert called.exitstatus == 1
343
- assert_eq sout, ""
344
- assert_eq serr, "ls: *not*exist*: No such file or directory\n"
345
+ test_ok? called.is_a?(Process::Status)
346
+ test_ok? called.exitstatus == 1
347
+ test_eq? sout, ""
348
+ test_eq? serr, "ls: *not*exist*: No such file or directory\n"
345
349
  end
346
- it "[!vivq3] doesn't call error handler block if command finished successfully." do
350
+ test_subject "[!vivq3] doesn't call error handler block if command finished successfully." do
347
351
  called = false
348
352
  sout, serr = capture_command("cat -n", "AAA\nBBB\n") do
349
353
  called = true
350
354
  end
351
- assert_eq called, false
352
- assert_eq sout, " 1\tAAA\n 2\tBBB\n"
353
- assert_eq serr, ""
355
+ test_eq? called, false
356
+ test_eq? sout, " 1\tAAA\n 2\tBBB\n"
357
+ test_eq? serr, ""
354
358
  end
355
- it "[!nxw59] not raise error if command failed and error handler specified." do
359
+ test_subject "[!nxw59] not raise error if command failed and error handler specified." do
356
360
  begin
357
361
  sout, serr = capture_command("ls *not*exist*") do end
358
362
  rescue => exc
359
- assert false, "Exception should not raised, but raised #{exc.inspect}"
363
+ test_ok? false, msg: "Exception should not raised, but raised #{exc.inspect}"
360
364
  end
361
- assert_eq sout, ""
362
- assert_eq serr, "ls: *not*exist*: No such file or directory\n"
365
+ test_eq? sout, ""
366
+ test_eq? serr, "ls: *not*exist*: No such file or directory\n"
363
367
  end
364
- it "[!h5994] returns output of stdin and stderr." do
368
+ test_subject "[!h5994] returns output of stdin and stderr." do
365
369
  sout, serr = capture_command("cat -n", "AAA\nBBB\n")
366
- assert_eq sout, " 1\tAAA\n 2\tBBB\n"
367
- assert_eq serr, ""
370
+ test_eq? sout, " 1\tAAA\n 2\tBBB\n"
371
+ test_eq? serr, ""
368
372
  #
369
373
  sout, serr = capture_command("echo ERR >&2")
370
- assert_eq sout, ""
371
- assert_eq serr, "ERR\n"
374
+ test_eq? sout, ""
375
+ test_eq? serr, "ERR\n"
372
376
  end
373
377
  end
374
378
 
375
- describe '#capture_command!()' do
376
- it "[!vlbpo] executes command with stdin data." do
379
+ test_target 'Oktest::SpecHelper#capture_command!()' do
380
+ test_subject "[!vlbpo] executes command with stdin data." do
377
381
  sout, serr = capture_command!("cat -n", "AAA\nBBB\n")
378
- assert_eq sout, " 1\tAAA\n 2\tBBB\n"
379
- assert_eq serr, ""
382
+ test_eq? sout, " 1\tAAA\n 2\tBBB\n"
383
+ test_eq? serr, ""
380
384
  end
381
- it "[!yfohb] not raise error even if command failed." do
385
+ test_subject "[!yfohb] not raise error even if command failed." do
382
386
  sout, serr = capture_command!("ls *not*exist*")
383
- assert_eq sout, ""
384
- assert_eq serr, "ls: *not*exist*: No such file or directory\n"
387
+ test_eq? sout, ""
388
+ test_eq? serr, "ls: *not*exist*: No such file or directory\n"
385
389
  end
386
- it "[!andyj] calls error handler block if command failed." do
390
+ test_subject "[!andyj] calls error handler block if command failed." do
387
391
  called = nil
388
392
  sout, serr = capture_command!("ls *not*exist*") do |pstat|
389
393
  called = pstat
390
394
  end
391
- assert called.is_a?(Process::Status)
392
- assert called.exitstatus == 1
393
- assert_eq sout, ""
394
- assert_eq serr, "ls: *not*exist*: No such file or directory\n"
395
+ test_ok? called.is_a?(Process::Status)
396
+ test_ok? called.exitstatus == 1
397
+ test_eq? sout, ""
398
+ test_eq? serr, "ls: *not*exist*: No such file or directory\n"
395
399
  end
396
- it "[!xnkqc] doesn't call error handler block if command finished successfully." do
400
+ test_subject "[!xnkqc] doesn't call error handler block if command finished successfully." do
397
401
  called = false
398
402
  sout, serr = capture_command!("cat -n", "AAA\nBBB\n") do
399
403
  called = true
400
404
  end
401
- assert_eq called, false
402
- assert_eq sout, " 1\tAAA\n 2\tBBB\n"
403
- assert_eq serr, ""
405
+ test_eq? called, false
406
+ test_eq? sout, " 1\tAAA\n 2\tBBB\n"
407
+ test_eq? serr, ""
404
408
  end
405
- it "[!3xdgo] returns output of stdin and stderr." do
409
+ test_subject "[!3xdgo] returns output of stdin and stderr." do
406
410
  sout, serr = capture_command!("cat -n", "AAA\nBBB\n")
407
- assert_eq sout, " 1\tAAA\n 2\tBBB\n"
408
- assert_eq serr, ""
411
+ test_eq? sout, " 1\tAAA\n 2\tBBB\n"
412
+ test_eq? serr, ""
409
413
  #
410
414
  sout, serr = capture_command!("echo ERR >&2")
411
- assert_eq sout, ""
412
- assert_eq serr, "ERR\n"
415
+ test_eq? sout, ""
416
+ test_eq? serr, "ERR\n"
413
417
  end
414
418
  end
415
419
 
416
- describe '#dummy_file()' do
417
- it "[!7e0bo] creates dummy file." do
420
+ test_target 'Oktest::SpecHelper#dummy_file()' do
421
+ test_subject "[!7e0bo] creates dummy file." do
418
422
  tmpfile = "_tmp_3511.txt"
419
423
  File.unlink(tmpfile) if File.exist?(tmpfile)
420
424
  begin
421
425
  dummy_file(tmpfile, "foobar")
422
- assert File.exist?(tmpfile), "tmpfile should be created."
423
- assert_eq @__at_end_blocks.length, 1
426
+ test_ok? File.exist?(tmpfile), msg: "tmpfile should be created."
427
+ test_eq? @__at_end_blocks.length, 1
424
428
  pr = @__at_end_blocks.pop()
425
429
  pr.call()
426
- assert !File.exist?(tmpfile), "tmpfile should be removed."
430
+ test_ok? !File.exist?(tmpfile), msg: "tmpfile should be removed."
427
431
  ensure
428
432
  File.unlink(tmpfile) if File.exist?(tmpfile)
429
433
  end
430
434
  end
431
- it "[!yvfxq] raises error when dummy file already exists." do
435
+ test_subject "[!yvfxq] raises error when dummy file already exists." do
432
436
  tmp = "_tmp_4883.txt"
433
437
  [true, false].each do |flag|
434
438
  begin
435
439
  flag ? File.write(tmp, "") : Dir.mkdir(tmp)
436
- assert_exc(ArgumentError, "dummy_file('#{tmp}'): temporary file already exists.") do
440
+ exc = test_exception? ArgumentError do
437
441
  dummy_file(tmp, "foobar")
438
442
  end
443
+ test_eq? exc.message, "dummy_file('#{tmp}'): temporary file already exists."
439
444
  ensure
440
445
  File.unlink(tmp) if File.file?(tmp)
441
446
  Dir.rmdir(tmp) if File.directory?(tmp)
442
447
  end
443
448
  end
444
449
  end
445
- it "[!nvlkq] returns filename." do
450
+ test_subject "[!nvlkq] returns filename." do
446
451
  tmpfile = "_tmp_4947.txt"
447
452
  begin
448
453
  ret = dummy_file(tmpfile, "foobar")
449
- assert_eq ret, tmpfile
454
+ test_eq? ret, tmpfile
450
455
  ensure
451
456
  File.unlink(tmpfile) if File.exist?(tmpfile)
452
457
  end
453
458
  end
454
- it "[!3mg26] generates temporary filename if 1st arg is nil." do
459
+ test_subject "[!3mg26] generates temporary filename if 1st arg is nil." do
455
460
  begin
456
461
  tmpfile1 = dummy_file(nil, "foobar")
457
462
  tmpfile2 = dummy_file(nil, "foobar")
458
- assert tmpfile1 =~ /^_tmpfile_\d{6}/, "tempoary filename should be generated."
459
- assert tmpfile2 =~ /^_tmpfile_\d{6}/, "tempoary filename should be generated."
460
- assert tmpfile1 != tmpfile2, "tempoary filename should contain random number."
463
+ test_ok? tmpfile1 =~ /^_tmpfile_\d{6}/, msg: "tempoary filename should be generated."
464
+ test_ok? tmpfile2 =~ /^_tmpfile_\d{6}/, msg: "tempoary filename should be generated."
465
+ test_ok? tmpfile1 != tmpfile2, msg: "tempoary filename should contain random number."
461
466
  ensure
462
467
  File.unlink(tmpfile1) if File.exist?(tmpfile1)
463
468
  File.unlink(tmpfile2) if File.exist?(tmpfile2)
464
469
  end
465
470
  end
466
- it "[!ky7nh] can take block argument." do
471
+ test_subject "[!ky7nh] can take block argument." do
467
472
  tmpfile = "_tmp_9080"
468
473
  begin
469
474
  ret = dummy_file(tmpfile) do |filename|
470
- assert_eq filename, tmpfile
471
- assert File.file?(tmpfile), "tmpfile should be created."
475
+ test_eq? filename, tmpfile
476
+ test_ok? File.file?(tmpfile), msg: "tmpfile should be created."
472
477
  1234
473
478
  end
474
- assert !File.file?(tmpfile), "tmpfile should be removed."
475
- assert_eq ret, 1234
476
- assert_eq @__at_end_blocks, nil
479
+ test_ok? !File.file?(tmpfile), msg: "tmpfile should be removed."
480
+ test_eq? ret, 1234
481
+ test_eq? @__at_end_blocks, nil
477
482
  ensure
478
483
  File.unlink(tmpfile) if File.exist?(tmpfile)
479
484
  end
480
485
  end
481
486
  end
482
487
 
483
- describe '#dummy_dir()' do
484
- it "[!l34d5] creates dummy directory." do
488
+ test_target 'Oktest::SpecHelper#dummy_dir()' do
489
+ test_subject "[!l34d5] creates dummy directory." do
485
490
  tmpdir = "_tmpdir_7903"
486
491
  Dir.rmdir(tmpdir) if File.exist?(tmpdir)
487
492
  begin
488
493
  dummy_dir(tmpdir)
489
- assert File.exist?(tmpdir), "tmpdir should be created."
490
- assert_eq @__at_end_blocks.length, 1
494
+ test_ok? File.exist?(tmpdir), msg: "tmpdir should be created."
495
+ test_eq? @__at_end_blocks.length, 1
491
496
  pr = @__at_end_blocks.pop()
492
497
  pr.call()
493
- assert !File.exist?(tmpdir), "tmpdir should be removed."
498
+ test_ok? !File.exist?(tmpdir), msg: "tmpdir should be removed."
494
499
  ensure
495
500
  Dir.rmdir(tmpdir) if File.exist?(tmpdir)
496
501
  end
497
502
  end
498
- it "[!zypj6] raises error when dummy dir already exists." do
503
+ test_subject "[!zypj6] raises error when dummy dir already exists." do
499
504
  tmp = "_tmpdir_1062"
500
505
  [true, false].each do |flag|
501
506
  begin
502
507
  flag ? Dir.mkdir(tmp) : File.write(tmp, "")
503
- assert_exc(ArgumentError, "dummy_dir('#{tmp}'): temporary directory already exists.") do
508
+ exc = test_exception? ArgumentError do
504
509
  dummy_dir(tmp)
505
510
  end
511
+ test_eq? exc.message, "dummy_dir('#{tmp}'): temporary directory already exists."
506
512
  ensure
507
513
  Dir.rmdir(tmp) if File.directory?(tmp)
508
514
  File.unlink(tmp) if File.file?(tmp)
509
515
  end
510
516
  end
511
517
  end
512
- it "[!01gt7] removes dummy directory even if it contains other files." do
518
+ test_subject "[!01gt7] removes dummy directory even if test_subject contains other files." do
513
519
  tmpdir = "_tmpdir_3869"
514
520
  begin
515
521
  dummy_dir(tmpdir)
@@ -517,197 +523,197 @@ END
517
523
  Dir.mkdir("#{tmpdir}/d1")
518
524
  Dir.mkdir("#{tmpdir}/d1/d2")
519
525
  File.write("#{tmpdir}/d1/d2/bar.txt", "barbar", encoding: 'utf-8')
520
- assert File.exist?("#{tmpdir}/foo.txt"), "should exists."
521
- assert File.exist?("#{tmpdir}/d1/d2/bar.txt"), "should exists."
526
+ test_ok? File.exist?("#{tmpdir}/foo.txt"), msg: "should exists."
527
+ test_ok? File.exist?("#{tmpdir}/d1/d2/bar.txt"), msg: "should exists."
522
528
  #
523
529
  pr = @__at_end_blocks.pop()
524
530
  pr.call()
525
- assert !File.exist?(tmpdir), "tmpdir should be removed."
531
+ test_ok? !File.exist?(tmpdir), msg: "tmpdir should be removed."
526
532
  ensure
527
533
  FileUtils.rm_rf(tmpdir) if File.exist?(tmpdir)
528
534
  end
529
535
  end
530
- it "[!jxh30] returns directory name." do
536
+ test_subject "[!jxh30] returns directory name." do
531
537
  tmpdir = "_tmpdir_2546"
532
538
  begin
533
539
  ret = dummy_dir(tmpdir)
534
- assert_eq ret, tmpdir
540
+ test_eq? ret, tmpdir
535
541
  ensure
536
542
  Dir.rmdir(tmpdir) if File.exist?(tmpdir)
537
543
  end
538
544
  end
539
- it "[!r14uy] generates temporary directory name if 1st arg is nil." do
545
+ test_subject "[!r14uy] generates temporary directory name if 1st arg is nil." do
540
546
  begin
541
547
  tmpdir1 = dummy_dir(nil)
542
548
  tmpdir2 = dummy_dir()
543
- assert tmpdir1 =~ /^_tmpdir_\d{6}/, "tempoary directory name should be generated."
544
- assert tmpdir2 =~ /^_tmpdir_\d{6}/, "tempoary directory name should be generated."
545
- assert tmpdir1 != tmpdir2, "tempoary directory name should contain random number."
549
+ test_ok? tmpdir1 =~ /^_tmpdir_\d{6}/, msg: "tempoary directory name should be generated."
550
+ test_ok? tmpdir2 =~ /^_tmpdir_\d{6}/, msg: "tempoary directory name should be generated."
551
+ test_ok? tmpdir1 != tmpdir2, msg: "tempoary directory name should contain random number."
546
552
  ensure
547
553
  Dir.rmdir(tmpdir1) if File.exist?(tmpdir1)
548
554
  Dir.rmdir(tmpdir2) if File.exist?(tmpdir2)
549
555
  end
550
556
  end
551
- it "[!tfsqo] can take block argument." do
557
+ test_subject "[!tfsqo] can take block argument." do
552
558
  tmpdir = "_tmp_5799"
553
559
  begin
554
560
  ret = dummy_dir(tmpdir) do |dirname|
555
- assert_eq dirname, tmpdir
556
- assert File.directory?(tmpdir), "tmpdir should be created."
561
+ test_eq? dirname, tmpdir
562
+ test_ok? File.directory?(tmpdir), msg: "tmpdir should be created."
557
563
  2345
558
564
  end
559
- assert !File.directory?(tmpdir), "tmpdir should be removed."
560
- assert_eq ret, 2345
561
- assert_eq @__at_end_blocks, nil
565
+ test_ok? !File.directory?(tmpdir), msg: "tmpdir should be removed."
566
+ test_eq? ret, 2345
567
+ test_eq? @__at_end_blocks, nil
562
568
  ensure
563
569
  Dir.rmdir(tmpdir) if File.exist?(tmpdir)
564
570
  end
565
571
  end
566
572
  end
567
573
 
568
- describe '#dummy_values()' do
569
- it "[!hgwg2] changes hash value temporarily." do
574
+ test_target 'Oktest::SpecHelper#dummy_values()' do
575
+ test_subject "[!hgwg2] changes hash value temporarily." do
570
576
  hashobj = {:a=>10, 'b'=>20, :c=>30}
571
577
  dummy_values(hashobj, :a=>1000, 'b'=>2000, :x=>9000)
572
- assert_eq hashobj[:a], 1000
573
- assert_eq hashobj['b'], 2000
574
- assert_eq hashobj[:c], 30
575
- assert_eq hashobj[:x], 9000
578
+ test_eq? hashobj[:a], 1000
579
+ test_eq? hashobj['b'], 2000
580
+ test_eq? hashobj[:c], 30
581
+ test_eq? hashobj[:x], 9000
576
582
  end
577
- it "[!jw2kx] recovers hash values." do
583
+ test_subject "[!jw2kx] recovers hash values." do
578
584
  hashobj = {:a=>10, 'b'=>20, :c=>30}
579
585
  dummy_values(hashobj, :a=>1000, 'b'=>2000, :x=>9000)
580
- assert_eq hashobj[:a], 1000
581
- assert_eq hashobj['b'], 2000
582
- assert_eq hashobj[:c], 30
583
- assert_eq hashobj[:x], 9000
584
- assert_eq @__at_end_blocks.length, 1
586
+ test_eq? hashobj[:a], 1000
587
+ test_eq? hashobj['b'], 2000
588
+ test_eq? hashobj[:c], 30
589
+ test_eq? hashobj[:x], 9000
590
+ test_eq? @__at_end_blocks.length, 1
585
591
  pr = @__at_end_blocks.pop()
586
592
  pr.call()
587
- assert_eq hashobj[:a], 10
588
- assert_eq hashobj['b'], 20
589
- assert_eq hashobj[:c], 30
590
- assert !hashobj.key?(:x), "key :x should not exist."
593
+ test_eq? hashobj[:a], 10
594
+ test_eq? hashobj['b'], 20
595
+ test_eq? hashobj[:c], 30
596
+ test_ok? !hashobj.key?(:x), msg: "key :x should not exist."
591
597
  end
592
- it "[!w3r0p] returns keyvals." do
598
+ test_subject "[!w3r0p] returns keyvals." do
593
599
  hashobj = {:a=>10, 'b'=>20, :c=>30}
594
600
  ret = dummy_values(hashobj, :a=>1000, 'b'=>2000, :x=>9000)
595
- assert_eq ret, {:a=>1000, 'b'=>2000, :x=>9000}
601
+ test_eq? ret, {:a=>1000, 'b'=>2000, :x=>9000}
596
602
  end
597
- it "[!pwq6v] can take block argument." do
603
+ test_subject "[!pwq6v] can take block argument." do
598
604
  hashobj = {:a=>10, 'b'=>20, :c=>30}
599
605
  ret = dummy_values(hashobj, :a=>1000, 'b'=>2000, :x=>9000) do |kvs|
600
- assert_eq hashobj[:a], 1000
601
- assert_eq hashobj['b'], 2000
602
- assert_eq hashobj[:c], 30
603
- assert_eq hashobj[:x], 9000
604
- assert_eq kvs, {:a=>1000, 'b'=>2000, :x=>9000}
606
+ test_eq? hashobj[:a], 1000
607
+ test_eq? hashobj['b'], 2000
608
+ test_eq? hashobj[:c], 30
609
+ test_eq? hashobj[:x], 9000
610
+ test_eq? kvs, {:a=>1000, 'b'=>2000, :x=>9000}
605
611
  5678
606
612
  end
607
- assert_eq ret, 5678
608
- assert_eq hashobj[:a], 10
609
- assert_eq hashobj['b'], 20
610
- assert_eq hashobj[:c], 30
611
- assert !hashobj.key?(:x), "key :x should not exist."
612
- assert_eq @__at_end_blocks, nil
613
+ test_eq? ret, 5678
614
+ test_eq? hashobj[:a], 10
615
+ test_eq? hashobj['b'], 20
616
+ test_eq? hashobj[:c], 30
617
+ test_ok? !hashobj.key?(:x), msg: "key :x should not exist."
618
+ test_eq? @__at_end_blocks, nil
613
619
  end
614
620
  end
615
621
 
616
- describe '#dummy_attrs()' do
617
- it "[!4vd73] changes object attributes temporarily." do
622
+ test_target 'Oktest::SpecHelper#dummy_attrs()' do
623
+ test_subject "[!4vd73] changes object attributes temporarily." do
618
624
  obj = DummyUser.new(123, "alice")
619
625
  dummy_attrs(obj, :id=>999, :name=>"bob")
620
- assert_eq obj.id, 999
621
- assert_eq obj.name, "bob"
626
+ test_eq? obj.id, 999
627
+ test_eq? obj.name, "bob"
622
628
  end
623
- it "[!fi0t3] recovers attribute values." do
629
+ test_subject "[!fi0t3] recovers attribute values." do
624
630
  obj = DummyUser.new(123, "alice")
625
631
  dummy_attrs(obj, :id=>999, :name=>"bob")
626
- assert_eq obj.id, 999
627
- assert_eq obj.name, "bob"
632
+ test_eq? obj.id, 999
633
+ test_eq? obj.name, "bob"
628
634
  #
629
- assert_eq @__at_end_blocks.length, 1
635
+ test_eq? @__at_end_blocks.length, 1
630
636
  pr = @__at_end_blocks.pop()
631
637
  pr.call()
632
- assert_eq obj.id, 123
633
- assert_eq obj.name, "alice"
638
+ test_eq? obj.id, 123
639
+ test_eq? obj.name, "alice"
634
640
  end
635
- it "[!27yeh] returns keyvals." do
641
+ test_subject "[!27yeh] returns keyvals." do
636
642
  obj = DummyUser.new(123, "alice")
637
643
  ret = dummy_attrs(obj, :id=>789, :name=>"charlie")
638
- assert_eq ret, {:id=>789, :name=>"charlie"}
644
+ test_eq? ret, {:id=>789, :name=>"charlie"}
639
645
  end
640
- it "[!j7tvp] can take block argument." do
646
+ test_subject "[!j7tvp] can take block argument." do
641
647
  obj = DummyUser.new(123, "alice")
642
648
  ret = dummy_attrs(obj, :id=>888, :name=>"dave") do |kvs|
643
- assert_eq obj.id, 888
644
- assert_eq obj.name, "dave"
645
- assert_eq kvs, {:id=>888, :name=>"dave"}
649
+ test_eq? obj.id, 888
650
+ test_eq? obj.name, "dave"
651
+ test_eq? kvs, {:id=>888, :name=>"dave"}
646
652
  4567
647
653
  end
648
- assert_eq ret, 4567
649
- assert_eq obj.id, 123
650
- assert_eq obj.name, "alice"
651
- assert_eq @__at_end_blocks, nil
654
+ test_eq? ret, 4567
655
+ test_eq? obj.id, 123
656
+ test_eq? obj.name, "alice"
657
+ test_eq? @__at_end_blocks, nil
652
658
  end
653
659
  end
654
660
 
655
- describe '#dummy_ivars()' do
656
- it "[!rnqiv] changes instance variables temporarily." do
661
+ test_target 'Oktest::SpecHelper#dummy_ivars()' do
662
+ test_subject "[!rnqiv] changes instance variables temporarily." do
657
663
  obj = DummyUser.new(123, "alice")
658
664
  dummy_ivars(obj, :id=>999, :name=>"bob")
659
- assert_eq obj.instance_variable_get('@id'), 999
660
- assert_eq obj.instance_variable_get('@name'), "bob"
665
+ test_eq? obj.instance_variable_get('@id'), 999
666
+ test_eq? obj.instance_variable_get('@name'), "bob"
661
667
  end
662
- it "[!8oirn] recovers instance variables." do
668
+ test_subject "[!8oirn] recovers instance variables." do
663
669
  obj = DummyUser.new(123, "alice")
664
670
  dummy_ivars(obj, :id=>999, :name=>"bob")
665
- assert_eq obj.instance_variable_get('@id'), 999
666
- assert_eq obj.instance_variable_get('@name'), "bob"
671
+ test_eq? obj.instance_variable_get('@id'), 999
672
+ test_eq? obj.instance_variable_get('@name'), "bob"
667
673
  #
668
- assert_eq @__at_end_blocks.length, 1
674
+ test_eq? @__at_end_blocks.length, 1
669
675
  pr = @__at_end_blocks.pop()
670
676
  pr.call()
671
- assert_eq obj.instance_variable_get('@id'), 123
672
- assert_eq obj.instance_variable_get('@name'), "alice"
677
+ test_eq? obj.instance_variable_get('@id'), 123
678
+ test_eq? obj.instance_variable_get('@name'), "alice"
673
679
  end
674
- it "[!01dc8] returns keyvals." do
680
+ test_subject "[!01dc8] returns keyvals." do
675
681
  obj = DummyUser.new(123, "alice")
676
682
  ret = dummy_ivars(obj, :id=>789, :name=>"charlie")
677
- assert_eq ret, {:id=>789, :name=>"charlie"}
683
+ test_eq? ret, {:id=>789, :name=>"charlie"}
678
684
  end
679
- it "[!myzk4] can take block argument." do
685
+ test_subject "[!myzk4] can take block argument." do
680
686
  obj = DummyUser.new(123, "alice")
681
687
  ret = dummy_attrs(obj, :id=>888, :name=>"dave") do |kvs|
682
- assert_eq obj.instance_variable_get('@id'), 888
683
- assert_eq obj.instance_variable_get('@name'), "dave"
684
- assert_eq kvs, {:id=>888, :name=>"dave"}
688
+ test_eq? obj.instance_variable_get('@id'), 888
689
+ test_eq? obj.instance_variable_get('@name'), "dave"
690
+ test_eq? kvs, {:id=>888, :name=>"dave"}
685
691
  4567
686
692
  end
687
- assert_eq ret, 4567
688
- assert_eq obj.id, 123
689
- assert_eq obj.name, "alice"
690
- assert_eq @__at_end_blocks, nil
693
+ test_eq? ret, 4567
694
+ test_eq? obj.id, 123
695
+ test_eq? obj.name, "alice"
696
+ test_eq? @__at_end_blocks, nil
691
697
  end
692
698
  end
693
699
 
694
- describe '#recorder()' do
695
- it "[!qwrr8] loads 'benry/recorder' automatically." do
700
+ test_target 'Oktest::SpecHelper#recorder()' do
701
+ test_subject "[!qwrr8] loads 'benry/recorder' automatically." do
696
702
  if defined?(Benry::Recorder)
697
703
  $stderr.puts "** skip because 'benry/recorder' already loaded."
698
704
  else
699
- assert !defined? Benry::Recorder, "should not be loaded."
705
+ test_ok? !defined? Benry::Recorder, msg: "should not be loaded."
700
706
  recorder()
701
- assert defined? Benry::Recorder, "should be loaded."
707
+ test_ok? !!defined? Benry::Recorder, msg: "should be loaded."
702
708
  end
703
709
  end
704
- it "[!glfvx] creates Benry::Recorder object." do
710
+ test_subject "[!glfvx] creates Benry::Recorder object." do
705
711
  rec = recorder()
706
- assert rec.is_a?(Benry::Recorder)
712
+ test_ok? rec.is_a?(Benry::Recorder)
707
713
  o = rec.fake_object(:foo=>123)
708
- assert_eq o.foo(), 123
709
- assert_eq rec[0].name, :foo
710
- assert_eq rec[0].obj, o
714
+ test_eq? o.foo(), 123
715
+ test_eq? rec[0].name, :foo
716
+ test_eq? rec[0].obj, o
711
717
  end
712
718
  end
713
719