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.
- checksums.yaml +4 -4
- data/README.md +42 -5
- data/Rakefile.rb +1 -1
- data/lib/oktest.rb +32 -9
- data/oktest.gemspec +3 -3
- data/test/assertion_test.rb +229 -227
- data/test/filter_test.rb +122 -120
- data/test/fixture_test.rb +33 -32
- data/test/generator_test.rb +20 -19
- data/test/helper_test.rb +280 -274
- data/test/init.rb +44 -0
- data/test/mainapp_test.rb +194 -190
- data/test/matcher_test.rb +156 -126
- data/test/misc_test.rb +31 -30
- data/test/nanot.rb +307 -0
- data/test/node_test.rb +296 -252
- data/test/reporter_test.rb +249 -208
- data/test/runner_test.rb +101 -100
- data/test/util_test.rb +196 -193
- data/test/utilhelper_test.rb +35 -38
- data/test/visitor_test.rb +54 -50
- metadata +10 -10
- data/test/initialize.rb +0 -22
- data/test/tc.rb +0 -128
- /data/test/{run_all.rb → all.rb} +0 -0
data/test/helper_test.rb
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
###
|
5
|
-
### $Release: 1.
|
5
|
+
### $Release: 1.5.0 $
|
6
6
|
### $Copyright: copyright(c) 2011-2024 kuwata-lab.com all rights reserved $
|
7
7
|
### $License: MIT License $
|
8
8
|
###
|
9
9
|
|
10
|
-
require_relative './
|
10
|
+
require_relative './init'
|
11
11
|
|
12
12
|
|
13
13
|
class DummyUser
|
@@ -19,83 +19,85 @@ class DummyUser
|
|
19
19
|
end
|
20
20
|
|
21
21
|
|
22
|
-
class
|
23
|
-
|
22
|
+
class SpecHelper__Test
|
23
|
+
extend NanoTest
|
24
|
+
extend Oktest::SpecHelper
|
24
25
|
|
25
|
-
def
|
26
|
-
|
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
|
-
|
33
|
-
|
33
|
+
test_target 'Oktest::SpecHelper#ok()' do
|
34
|
+
test_subject "[!3jhg6] creates new assertion object." do
|
34
35
|
o = ok {"foo"}
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
test_eq? o.class, Oktest::AssertionObject
|
37
|
+
test_eq? o.actual, "foo"
|
38
|
+
test_eq? o.bool, true
|
38
39
|
end
|
39
|
-
|
40
|
+
test_subject "[!bc3l2] records invoked location." do
|
40
41
|
lineno = __LINE__ + 1
|
41
42
|
o = ok {"bar"}
|
42
|
-
|
43
|
+
test_ok? o.location.to_s.start_with?("#{__FILE__}:#{lineno}:")
|
43
44
|
end
|
44
|
-
|
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
|
-
|
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
|
-
|
57
|
-
|
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
|
-
|
60
|
-
|
61
|
-
|
60
|
+
test_eq? o.class, Oktest::AssertionObject
|
61
|
+
test_eq? o.actual, "abc"
|
62
|
+
test_eq? o.bool, false
|
62
63
|
end
|
63
|
-
|
64
|
+
test_subject "[!agmx8] records invoked location." do
|
64
65
|
lineno = __LINE__ + 1
|
65
66
|
o = not_ok {"bar"}
|
66
|
-
|
67
|
+
test_ok? o.location.to_s.start_with?("#{__FILE__}:#{lineno}:")
|
67
68
|
end
|
68
|
-
|
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
|
-
|
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
|
-
|
81
|
-
|
82
|
-
|
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
|
-
|
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
|
-
|
92
|
+
test_ok? false, "nothing should be raised but #{exc.class} raised"
|
91
93
|
else
|
92
|
-
|
94
|
+
test_ok? true, msg: "OK"
|
93
95
|
end
|
94
96
|
end
|
95
97
|
end
|
96
98
|
|
97
|
-
|
98
|
-
|
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
|
-
|
109
|
-
|
110
|
+
capture_output! { Oktest.run() }
|
111
|
+
test_eq? val, "<<foo>>"
|
110
112
|
end
|
111
|
-
|
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
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
129
|
+
capture_output! { Oktest.run() }
|
130
|
+
test_eq? val1, "<<baz>>"
|
131
|
+
test_eq? val2, "<<bar>>"
|
132
|
+
test_eq? val3, "<<foo>>"
|
131
133
|
end
|
132
|
-
|
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
|
-
|
145
|
-
|
146
|
+
capture_output! { Oktest.run() }
|
147
|
+
test_eq? val, {x: 10, y: 20, z: 30}
|
146
148
|
end
|
147
|
-
|
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
|
-
|
161
|
-
|
162
|
-
|
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
|
-
|
167
|
-
|
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 =
|
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
|
-
|
185
|
+
test_ok? sout.include?(expected), msg: "not matched"
|
184
186
|
end
|
185
187
|
end
|
186
188
|
|
187
|
-
|
188
|
-
|
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
|
-
|
194
|
-
|
195
|
+
test_eq? sout, "fooo\n"
|
196
|
+
test_eq? serr, "baaa\n"
|
195
197
|
end
|
196
|
-
|
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
|
-
|
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
|
-
|
211
|
-
|
212
|
-
|
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
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
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
|
-
|
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
|
-
|
230
|
-
|
231
|
+
test_eq? sout, "foo\n"
|
232
|
+
test_eq? serr, "bar\n"
|
231
233
|
end
|
232
|
-
|
234
|
+
test_subject "[!6ik8b] can simulate tty." do
|
233
235
|
sout, serr = capture_stdio() do
|
234
|
-
|
235
|
-
|
236
|
-
|
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
|
-
|
241
|
-
|
242
|
-
|
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
|
-
|
248
|
-
|
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
|
-
|
255
|
-
|
256
|
-
|
256
|
+
test_eq? $stdin.tty?, true
|
257
|
+
test_eq? $stdout.tty?, true
|
258
|
+
test_eq? $stdout.tty?, true
|
257
259
|
end
|
258
|
-
|
259
|
-
|
260
|
-
|
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
|
-
|
265
|
-
|
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
|
-
|
271
|
-
|
272
|
-
|
272
|
+
test_eq? $stdin.tty?, true
|
273
|
+
test_eq? $stdout.tty?, true
|
274
|
+
test_eq? $stderr.tty?, true
|
273
275
|
end
|
274
|
-
|
275
|
-
|
276
|
+
test_eq? sin, "INPUT"
|
277
|
+
test_eq? sout, "OUTPUT\n"
|
276
278
|
end
|
277
|
-
|
278
|
-
|
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
|
-
|
287
|
+
test_subject "[!5n04e] returns output of stdout." do
|
285
288
|
sout = capture_stdout() do
|
286
289
|
print "OUTPUT"
|
287
290
|
end
|
288
|
-
|
291
|
+
test_eq? sout, "OUTPUT"
|
289
292
|
end
|
290
293
|
end
|
291
294
|
|
292
|
-
|
293
|
-
|
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
|
-
|
299
|
-
|
300
|
-
|
301
|
+
test_eq? $stdin.tty?, true
|
302
|
+
test_eq? $stdout.tty?, true
|
303
|
+
test_eq? $stderr.tty?, true
|
301
304
|
end
|
302
|
-
|
303
|
-
|
305
|
+
test_eq? sin, "INPUT"
|
306
|
+
test_eq? serr, "ERROR\n"
|
304
307
|
end
|
305
|
-
|
306
|
-
|
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
|
-
|
316
|
+
test_subject "[!5vs64] returns output of stderr." do
|
313
317
|
serr = capture_stderr() do
|
314
318
|
$stderr.print "ERROR"
|
315
319
|
end
|
316
|
-
|
320
|
+
test_eq? serr, "ERROR"
|
317
321
|
end
|
318
322
|
end
|
319
323
|
|
320
|
-
|
321
|
-
|
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
|
-
|
324
|
-
|
327
|
+
test_eq? sout, " 1\tAAA\n 2\tBBB\n"
|
328
|
+
test_eq? serr, ""
|
325
329
|
end
|
326
|
-
|
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
|
-
|
331
|
-
|
334
|
+
test_eq? exc.class, RuntimeError
|
335
|
+
test_eq? exc.message, "Command failed with status (1): `ls *not*exist*`"
|
332
336
|
else
|
333
|
-
|
337
|
+
test_ok? false, msg: "Exception should be raised but not."
|
334
338
|
end
|
335
339
|
end
|
336
|
-
|
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
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
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
|
-
|
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
|
-
|
352
|
-
|
353
|
-
|
355
|
+
test_eq? called, false
|
356
|
+
test_eq? sout, " 1\tAAA\n 2\tBBB\n"
|
357
|
+
test_eq? serr, ""
|
354
358
|
end
|
355
|
-
|
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
|
-
|
363
|
+
test_ok? false, msg: "Exception should not raised, but raised #{exc.inspect}"
|
360
364
|
end
|
361
|
-
|
362
|
-
|
365
|
+
test_eq? sout, ""
|
366
|
+
test_eq? serr, "ls: *not*exist*: No such file or directory\n"
|
363
367
|
end
|
364
|
-
|
368
|
+
test_subject "[!h5994] returns output of stdin and stderr." do
|
365
369
|
sout, serr = capture_command("cat -n", "AAA\nBBB\n")
|
366
|
-
|
367
|
-
|
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
|
-
|
371
|
-
|
374
|
+
test_eq? sout, ""
|
375
|
+
test_eq? serr, "ERR\n"
|
372
376
|
end
|
373
377
|
end
|
374
378
|
|
375
|
-
|
376
|
-
|
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
|
-
|
379
|
-
|
382
|
+
test_eq? sout, " 1\tAAA\n 2\tBBB\n"
|
383
|
+
test_eq? serr, ""
|
380
384
|
end
|
381
|
-
|
385
|
+
test_subject "[!yfohb] not raise error even if command failed." do
|
382
386
|
sout, serr = capture_command!("ls *not*exist*")
|
383
|
-
|
384
|
-
|
387
|
+
test_eq? sout, ""
|
388
|
+
test_eq? serr, "ls: *not*exist*: No such file or directory\n"
|
385
389
|
end
|
386
|
-
|
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
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
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
|
-
|
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
|
-
|
402
|
-
|
403
|
-
|
405
|
+
test_eq? called, false
|
406
|
+
test_eq? sout, " 1\tAAA\n 2\tBBB\n"
|
407
|
+
test_eq? serr, ""
|
404
408
|
end
|
405
|
-
|
409
|
+
test_subject "[!3xdgo] returns output of stdin and stderr." do
|
406
410
|
sout, serr = capture_command!("cat -n", "AAA\nBBB\n")
|
407
|
-
|
408
|
-
|
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
|
-
|
412
|
-
|
415
|
+
test_eq? sout, ""
|
416
|
+
test_eq? serr, "ERR\n"
|
413
417
|
end
|
414
418
|
end
|
415
419
|
|
416
|
-
|
417
|
-
|
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
|
-
|
423
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
450
|
+
test_subject "[!nvlkq] returns filename." do
|
446
451
|
tmpfile = "_tmp_4947.txt"
|
447
452
|
begin
|
448
453
|
ret = dummy_file(tmpfile, "foobar")
|
449
|
-
|
454
|
+
test_eq? ret, tmpfile
|
450
455
|
ensure
|
451
456
|
File.unlink(tmpfile) if File.exist?(tmpfile)
|
452
457
|
end
|
453
458
|
end
|
454
|
-
|
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
|
-
|
459
|
-
|
460
|
-
|
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
|
-
|
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
|
-
|
471
|
-
|
475
|
+
test_eq? filename, tmpfile
|
476
|
+
test_ok? File.file?(tmpfile), msg: "tmpfile should be created."
|
472
477
|
1234
|
473
478
|
end
|
474
|
-
|
475
|
-
|
476
|
-
|
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
|
-
|
484
|
-
|
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
|
-
|
490
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
521
|
-
|
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
|
-
|
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
|
-
|
536
|
+
test_subject "[!jxh30] returns directory name." do
|
531
537
|
tmpdir = "_tmpdir_2546"
|
532
538
|
begin
|
533
539
|
ret = dummy_dir(tmpdir)
|
534
|
-
|
540
|
+
test_eq? ret, tmpdir
|
535
541
|
ensure
|
536
542
|
Dir.rmdir(tmpdir) if File.exist?(tmpdir)
|
537
543
|
end
|
538
544
|
end
|
539
|
-
|
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
|
-
|
544
|
-
|
545
|
-
|
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
|
-
|
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
|
-
|
556
|
-
|
561
|
+
test_eq? dirname, tmpdir
|
562
|
+
test_ok? File.directory?(tmpdir), msg: "tmpdir should be created."
|
557
563
|
2345
|
558
564
|
end
|
559
|
-
|
560
|
-
|
561
|
-
|
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
|
-
|
569
|
-
|
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
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
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
|
-
|
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
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
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
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
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
|
-
|
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
|
-
|
601
|
+
test_eq? ret, {:a=>1000, 'b'=>2000, :x=>9000}
|
596
602
|
end
|
597
|
-
|
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
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
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
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
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
|
-
|
617
|
-
|
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
|
-
|
621
|
-
|
626
|
+
test_eq? obj.id, 999
|
627
|
+
test_eq? obj.name, "bob"
|
622
628
|
end
|
623
|
-
|
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
|
-
|
627
|
-
|
632
|
+
test_eq? obj.id, 999
|
633
|
+
test_eq? obj.name, "bob"
|
628
634
|
#
|
629
|
-
|
635
|
+
test_eq? @__at_end_blocks.length, 1
|
630
636
|
pr = @__at_end_blocks.pop()
|
631
637
|
pr.call()
|
632
|
-
|
633
|
-
|
638
|
+
test_eq? obj.id, 123
|
639
|
+
test_eq? obj.name, "alice"
|
634
640
|
end
|
635
|
-
|
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
|
-
|
644
|
+
test_eq? ret, {:id=>789, :name=>"charlie"}
|
639
645
|
end
|
640
|
-
|
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
|
-
|
644
|
-
|
645
|
-
|
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
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
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
|
-
|
656
|
-
|
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
|
-
|
660
|
-
|
665
|
+
test_eq? obj.instance_variable_get('@id'), 999
|
666
|
+
test_eq? obj.instance_variable_get('@name'), "bob"
|
661
667
|
end
|
662
|
-
|
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
|
-
|
666
|
-
|
671
|
+
test_eq? obj.instance_variable_get('@id'), 999
|
672
|
+
test_eq? obj.instance_variable_get('@name'), "bob"
|
667
673
|
#
|
668
|
-
|
674
|
+
test_eq? @__at_end_blocks.length, 1
|
669
675
|
pr = @__at_end_blocks.pop()
|
670
676
|
pr.call()
|
671
|
-
|
672
|
-
|
677
|
+
test_eq? obj.instance_variable_get('@id'), 123
|
678
|
+
test_eq? obj.instance_variable_get('@name'), "alice"
|
673
679
|
end
|
674
|
-
|
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
|
-
|
683
|
+
test_eq? ret, {:id=>789, :name=>"charlie"}
|
678
684
|
end
|
679
|
-
|
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
|
-
|
683
|
-
|
684
|
-
|
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
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
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
|
-
|
695
|
-
|
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
|
-
|
705
|
+
test_ok? !defined? Benry::Recorder, msg: "should not be loaded."
|
700
706
|
recorder()
|
701
|
-
|
707
|
+
test_ok? !!defined? Benry::Recorder, msg: "should be loaded."
|
702
708
|
end
|
703
709
|
end
|
704
|
-
|
710
|
+
test_subject "[!glfvx] creates Benry::Recorder object." do
|
705
711
|
rec = recorder()
|
706
|
-
|
712
|
+
test_ok? rec.is_a?(Benry::Recorder)
|
707
713
|
o = rec.fake_object(:foo=>123)
|
708
|
-
|
709
|
-
|
710
|
-
|
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
|
|