oktest 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,123 @@
1
+ ###
2
+ ### $Release: 1.0.0 $
3
+ ### $Copyright: copyright(c) 2011-2021 kuwata-lab.com all rights reserved $
4
+ ### $License: MIT License $
5
+ ###
6
+
7
+ require_relative './initialize'
8
+
9
+ require 'stringio'
10
+
11
+
12
+ class TestGenerator_TC < TC
13
+
14
+ INPUT = <<END
15
+ class Hello
16
+ def hello(name=nil)
17
+ #; default name is 'world'.
18
+ if name.nil?
19
+ name = "world"
20
+ end
21
+ #; returns greeting message.
22
+ return "Hello, #{name}!"
23
+ end
24
+ end
25
+ END
26
+
27
+ describe '#parse()' do
28
+ it "[!5mzd3] parses ruby code." do
29
+ g = Oktest::TestGenerator.new()
30
+ tree = g.parse(StringIO.new(INPUT))
31
+ expected = [
32
+ ["", "class", "Hello", [
33
+ [" ", "def", "#hello", [
34
+ [" ", "spec", "default name is 'world'."],
35
+ [" ", "spec", "returns greeting message."],
36
+ ]]
37
+ ]]
38
+ ]
39
+ assert_eq tree, expected
40
+ end
41
+ end
42
+
43
+ describe '#transform()' do
44
+ it "[!te7zw] converts tree into test code." do
45
+ g = Oktest::TestGenerator.new()
46
+ tree = g.parse(StringIO.new(INPUT))
47
+ code = g.transform(tree, 1)
48
+ expected = <<'END'
49
+
50
+ topic Hello do
51
+
52
+
53
+ topic '#hello()' do
54
+
55
+ spec "default name is 'world'."
56
+
57
+ spec "returns greeting message."
58
+
59
+ end # #hello()
60
+
61
+
62
+ end # Hello
63
+ END
64
+ assert_eq code, expected
65
+ end
66
+ it "[!q5duk] supports 'unaryop' style option." do
67
+ g = Oktest::TestGenerator.new('unaryop')
68
+ tree = g.parse(StringIO.new(INPUT))
69
+ code = g.transform(tree, 1)
70
+ expected = <<'END'
71
+
72
+ + topic(Hello) do
73
+
74
+
75
+ + topic('#hello()') do
76
+
77
+ - spec("default name is 'world'.")
78
+
79
+ - spec("returns greeting message.")
80
+
81
+ end # #hello()
82
+
83
+
84
+ end # Hello
85
+ END
86
+ assert_eq code, expected
87
+ end
88
+ end
89
+
90
+ describe '#generate()' do
91
+ it "[!5hdw4] generates test code." do
92
+ g = Oktest::TestGenerator.new()
93
+ code = g.generate(StringIO.new(INPUT))
94
+ expected = <<'END'
95
+ # coding: utf-8
96
+
97
+ require 'oktest'
98
+
99
+ Oktest.scope do
100
+
101
+
102
+ topic Hello do
103
+
104
+
105
+ topic '#hello()' do
106
+
107
+ spec "default name is 'world'."
108
+
109
+ spec "returns greeting message."
110
+
111
+ end # #hello()
112
+
113
+
114
+ end # Hello
115
+
116
+
117
+ end
118
+ END
119
+ assert_eq code, expected
120
+ end
121
+ end
122
+
123
+ end
@@ -0,0 +1,542 @@
1
+ ###
2
+ ### $Release: 1.0.0 $
3
+ ### $Copyright: copyright(c) 2011-2021 kuwata-lab.com all rights reserved $
4
+ ### $License: MIT License $
5
+ ###
6
+
7
+ require_relative './initialize'
8
+
9
+
10
+ class DummyUser
11
+ def initialize(id, name)
12
+ @id = id
13
+ @name = name
14
+ end
15
+ attr_accessor :id, :name
16
+ end
17
+
18
+
19
+ class SpecHelper_TC < TC
20
+ include Oktest::SpecHelper
21
+
22
+ def setup()
23
+ end
24
+
25
+ def teardown()
26
+ Oktest::AssertionObject::NOT_YET.clear()
27
+ end
28
+
29
+ describe '#ok()' do
30
+ it "[!3jhg6] creates new assertion object." do
31
+ o = ok {"foo"}
32
+ assert_eq o.class, Oktest::AssertionObject
33
+ assert_eq o.actual, "foo"
34
+ assert_eq o.bool, true
35
+ end
36
+ it "[!bc3l2] records invoked location." do
37
+ lineno = __LINE__ + 1
38
+ o = ok {"bar"}
39
+ assert o.location.start_with?("#{__FILE__}:#{lineno}:")
40
+ end
41
+ it "[!mqtdy] not record invoked location when `Config.ok_location == false`." do
42
+ bkup = Oktest::Config.ok_location
43
+ begin
44
+ Oktest::Config.ok_location = false
45
+ o = ok {"bar"}
46
+ assert_eq o.location, nil
47
+ ensure
48
+ Oktest::Config.ok_location = bkup
49
+ end
50
+ end
51
+ end
52
+
53
+ describe '#not_ok()' do
54
+ it "[!d332o] creates new assertion object for negative condition." do
55
+ o = not_ok {"abc"}
56
+ assert_eq o.class, Oktest::AssertionObject
57
+ assert_eq o.actual, "abc"
58
+ assert_eq o.bool, false
59
+ end
60
+ it "[!agmx8] records invoked location." do
61
+ lineno = __LINE__ + 1
62
+ o = not_ok {"bar"}
63
+ assert o.location.start_with?("#{__FILE__}:#{lineno}:")
64
+ end
65
+ it "[!a9508] not record invoked location when `Config.ok_location == false`." do
66
+ bkup = Oktest::Config.ok_location
67
+ begin
68
+ Oktest::Config.ok_location = false
69
+ o = not_ok {"bar"}
70
+ assert_eq o.location, nil
71
+ ensure
72
+ Oktest::Config.ok_location = bkup
73
+ end
74
+ end
75
+ end
76
+
77
+ describe '#skip_when()' do
78
+ it "[!3xqf4] raises SkipException if condition is truthy." do
79
+ assert_exc(Oktest::SkipException, "..reason..") do
80
+ skip_when (1+1 == 2), "..reason.."
81
+ end
82
+ end
83
+ it "[!r7cxx] not raise nothing if condition is falsy." do
84
+ begin
85
+ skip_when (1+1 == 0), "..reason.."
86
+ rescue Exception => exc
87
+ assert false, "nothing should be raised but #{exc.class} raised"
88
+ else
89
+ assert true, "OK"
90
+ end
91
+ end
92
+ end
93
+
94
+ describe '#fixture()' do
95
+ it "[!m4ava] calls fixture block and returns result of it." do
96
+ val = nil
97
+ Oktest.scope() do
98
+ topic 'Example' do
99
+ fixture :foo do "<<foo>>" end
100
+ spec 'sample' do
101
+ val = fixture(:foo)
102
+ end
103
+ end
104
+ end
105
+ capture { Oktest.run() }
106
+ assert_eq val, "<<foo>>"
107
+ end
108
+ it "[!zgfg9] finds fixture block in current or parent node." do
109
+ val1 = val2 = val3 = nil
110
+ Oktest.scope() do
111
+ fixture :foo do "<<foo>>" end
112
+ topic 'Outer' do
113
+ fixture :bar do "<<bar>>" end
114
+ topic 'Inner' do
115
+ fixture :baz do "<<baz>>" end
116
+ spec 'sample' do
117
+ val1 = fixture(:baz)
118
+ val2 = fixture(:bar)
119
+ val3 = fixture(:foo)
120
+ end
121
+ end
122
+ end
123
+ end
124
+ capture { Oktest.run() }
125
+ assert_eq val1, "<<baz>>"
126
+ assert_eq val2, "<<bar>>"
127
+ assert_eq val3, "<<foo>>"
128
+ end
129
+ it "[!l2mcx] accepts block arguments." do
130
+ val = nil
131
+ Oktest.scope() do
132
+ fixture :foo do |x, y|
133
+ {x: x, y: y}
134
+ end
135
+ topic 'Example' do
136
+ spec 'sample' do
137
+ val = fixture(:foo, 10, 20)
138
+ end
139
+ end
140
+ end
141
+ capture { Oktest.run() }
142
+ assert_eq val, {x: 10, y: 20}
143
+ end
144
+ it "[!wxcsp] raises error when fixture not found." do
145
+ exc = nil
146
+ Oktest.scope() do
147
+ fixture :foo do "<<foo>>" end
148
+ topic 'Example' do
149
+ spec 'sample' do
150
+ begin
151
+ fixture(:bar)
152
+ rescue Exception => exc
153
+ end
154
+ end
155
+ end
156
+ end
157
+ capture { Oktest.run() }
158
+ assert_eq exc.class, Oktest::FixtureNotFoundError
159
+ assert_eq exc.message, "`:bar`: fixture not found."
160
+ end
161
+ end
162
+
163
+ describe '#at_end()' do
164
+ it "[!x58eo] records clean-up block." do
165
+ Oktest.scope() do
166
+ topic 'Example' do
167
+ spec 'sample #1' do
168
+ puts "before at_end()"
169
+ at_end { puts "in at_end()" }
170
+ puts "after at_end()"
171
+ end
172
+ end
173
+ end
174
+ sout, serr = capture { Oktest.run() }
175
+ expected = <<'END'
176
+ before at_end()
177
+ after at_end()
178
+ in at_end()
179
+ END
180
+ assert sout.include?(expected), "not matched"
181
+ end
182
+ end
183
+
184
+ describe '#capture_sio()' do
185
+ it "[!1kbnj] captures $stdio and $stderr." do
186
+ sout, serr = capture_sio() do
187
+ puts "fooo"
188
+ $stderr.puts "baaa"
189
+ end
190
+ assert_eq sout, "fooo\n"
191
+ assert_eq serr, "baaa\n"
192
+ end
193
+ it "[!53mai] takes $stdin data." do
194
+ data = nil
195
+ sout, serr = capture_sio("blabla") do
196
+ data = $stdin.read()
197
+ end
198
+ data = "blabla"
199
+ end
200
+ it "[!wq8a9] recovers stdio even when exception raised." do
201
+ stdin_, stdout_, stderr_ = $stdin, $stdout, $stderr
202
+ exception = nil
203
+ begin
204
+ sout, serr = capture_sio() do
205
+ puts "fooo"
206
+ $stderr.puts "baaa"
207
+ assert stdin_ != $stdin , "stdin should be replaced"
208
+ assert stdout_ != $stdout, "stdout should be replaced"
209
+ assert stderr_ != $stderr, "stderr should be replaced"
210
+ 1/0 # ZeroDivisionError
211
+ end
212
+ rescue ZeroDivisionError => exc
213
+ exception = exc
214
+ end
215
+ assert exception != nil, "exception should be raised."
216
+ assert exception.is_a?(ZeroDivisionError), "ZeroDivisionError should be raised."
217
+ assert stdin_ == $stdin , "stdin should be recovered"
218
+ assert stdout_ == $stdout, "stdout should be recovered"
219
+ assert stderr_ == $stderr, "stderr should be recovered"
220
+ end
221
+ it "[!4j494] returns outpouts of stdout and stderr." do
222
+ sout, serr = capture_sio() do
223
+ puts "foo"
224
+ $stderr.puts "bar"
225
+ end
226
+ assert_eq sout, "foo\n"
227
+ assert_eq serr, "bar\n"
228
+ end
229
+ it "[!6ik8b] can simulate tty." do
230
+ sout, serr = capture_sio() do
231
+ assert_eq $stdin.tty?, false
232
+ assert_eq $stdout.tty?, false
233
+ assert_eq $stderr.tty?, false
234
+ end
235
+ #
236
+ sout, serr = capture_sio(tty: true) do
237
+ assert_eq $stdin.tty?, true
238
+ assert_eq $stdout.tty?, true
239
+ assert_eq $stderr.tty?, true
240
+ end
241
+ end
242
+ end
243
+
244
+ describe '#dummy_file()' do
245
+ it "[!7e0bo] creates dummy file." do
246
+ tmpfile = "_tmp_3511.txt"
247
+ File.unlink(tmpfile) if File.exist?(tmpfile)
248
+ begin
249
+ dummy_file(tmpfile, "foobar")
250
+ assert File.exist?(tmpfile), "tmpfile should be created."
251
+ assert_eq @__at_end_blocks.length, 1
252
+ pr = @__at_end_blocks.pop()
253
+ pr.call()
254
+ assert !File.exist?(tmpfile), "tmpfile should be removed."
255
+ ensure
256
+ File.unlink(tmpfile) if File.exist?(tmpfile)
257
+ end
258
+ end
259
+ it "[!yvfxq] raises error when dummy file already exists." do
260
+ tmp = "_tmp_4883.txt"
261
+ [true, false].each do |flag|
262
+ begin
263
+ flag ? File.write(tmp, "") : Dir.mkdir(tmp)
264
+ assert_exc(ArgumentError, "dummy_file('#{tmp}'): temporary file already exists.") do
265
+ dummy_file(tmp, "foobar")
266
+ end
267
+ ensure
268
+ File.unlink(tmp) if File.file?(tmp)
269
+ Dir.rmdir(tmp) if File.directory?(tmp)
270
+ end
271
+ end
272
+ end
273
+ it "[!nvlkq] returns filename." do
274
+ tmpfile = "_tmp_4947.txt"
275
+ begin
276
+ ret = dummy_file(tmpfile, "foobar")
277
+ assert_eq ret, tmpfile
278
+ ensure
279
+ File.unlink(tmpfile) if File.exist?(tmpfile)
280
+ end
281
+ end
282
+ it "[!3mg26] generates temporary filename if 1st arg is nil." do
283
+ begin
284
+ tmpfile1 = dummy_file(nil, "foobar")
285
+ tmpfile2 = dummy_file(nil, "foobar")
286
+ assert tmpfile1 =~ /^_tmpfile_\d{6}/, "tempoary filename should be generated."
287
+ assert tmpfile2 =~ /^_tmpfile_\d{6}/, "tempoary filename should be generated."
288
+ assert tmpfile1 != tmpfile2, "tempoary filename should contain random number."
289
+ ensure
290
+ File.unlink(tmpfile1) if File.exist?(tmpfile1)
291
+ File.unlink(tmpfile2) if File.exist?(tmpfile2)
292
+ end
293
+ end
294
+ it "[!ky7nh] can take block argument." do
295
+ tmpfile = "_tmp_9080"
296
+ begin
297
+ ret = dummy_file(tmpfile) do |filename|
298
+ assert_eq filename, tmpfile
299
+ assert File.file?(tmpfile), "tmpfile should be created."
300
+ 1234
301
+ end
302
+ assert !File.file?(tmpfile), "tmpfile should be removed."
303
+ assert_eq ret, 1234
304
+ assert_eq @__at_end_blocks, nil
305
+ ensure
306
+ File.unlink(tmpfile) if File.exist?(tmpfile)
307
+ end
308
+ end
309
+ end
310
+
311
+ describe '#dummy_dir()' do
312
+ it "[!l34d5] creates dummy directory." do
313
+ tmpdir = "_tmpdir_7903"
314
+ Dir.rmdir(tmpdir) if File.exist?(tmpdir)
315
+ begin
316
+ dummy_dir(tmpdir)
317
+ assert File.exist?(tmpdir), "tmpdir should be created."
318
+ assert_eq @__at_end_blocks.length, 1
319
+ pr = @__at_end_blocks.pop()
320
+ pr.call()
321
+ assert !File.exist?(tmpdir), "tmpdir should be removed."
322
+ ensure
323
+ Dir.rmdir(tmpdir) if File.exist?(tmpdir)
324
+ end
325
+ end
326
+ it "[!zypj6] raises error when dummy dir already exists." do
327
+ tmp = "_tmpdir_1062"
328
+ [true, false].each do |flag|
329
+ begin
330
+ flag ? Dir.mkdir(tmp) : File.write(tmp, "")
331
+ assert_exc(ArgumentError, "dummy_dir('#{tmp}'): temporary directory already exists.") do
332
+ dummy_dir(tmp)
333
+ end
334
+ ensure
335
+ Dir.rmdir(tmp) if File.directory?(tmp)
336
+ File.unlink(tmp) if File.file?(tmp)
337
+ end
338
+ end
339
+ end
340
+ it "[!01gt7] removes dummy directory even if it contains other files." do
341
+ tmpdir = "_tmpdir_3869"
342
+ begin
343
+ dummy_dir(tmpdir)
344
+ File.write("#{tmpdir}/foo.txt", "foofoo", encoding: 'utf-8')
345
+ Dir.mkdir("#{tmpdir}/d1")
346
+ Dir.mkdir("#{tmpdir}/d1/d2")
347
+ File.write("#{tmpdir}/d1/d2/bar.txt", "barbar", encoding: 'utf-8')
348
+ assert File.exist?("#{tmpdir}/foo.txt"), "should exists."
349
+ assert File.exist?("#{tmpdir}/d1/d2/bar.txt"), "should exists."
350
+ #
351
+ pr = @__at_end_blocks.pop()
352
+ pr.call()
353
+ assert !File.exist?(tmpdir), "tmpdir should be removed."
354
+ ensure
355
+ FileUtils.rm_rf(tmpdir) if File.exist?(tmpdir)
356
+ end
357
+ end
358
+ it "[!jxh30] returns directory name." do
359
+ tmpdir = "_tmpdir_2546"
360
+ begin
361
+ ret = dummy_dir(tmpdir)
362
+ assert_eq ret, tmpdir
363
+ ensure
364
+ Dir.rmdir(tmpdir) if File.exist?(tmpdir)
365
+ end
366
+ end
367
+ it "[!r14uy] generates temporary directory name if 1st arg is nil." do
368
+ begin
369
+ tmpdir1 = dummy_dir(nil)
370
+ tmpdir2 = dummy_dir()
371
+ assert tmpdir1 =~ /^_tmpdir_\d{6}/, "tempoary directory name should be generated."
372
+ assert tmpdir2 =~ /^_tmpdir_\d{6}/, "tempoary directory name should be generated."
373
+ assert tmpdir1 != tmpdir2, "tempoary directory name should contain random number."
374
+ ensure
375
+ Dir.rmdir(tmpdir1) if File.exist?(tmpdir1)
376
+ Dir.rmdir(tmpdir2) if File.exist?(tmpdir2)
377
+ end
378
+ end
379
+ it "[!tfsqo] can take block argument." do
380
+ tmpdir = "_tmp_5799"
381
+ begin
382
+ ret = dummy_dir(tmpdir) do |dirname|
383
+ assert_eq dirname, tmpdir
384
+ assert File.directory?(tmpdir), "tmpdir should be created."
385
+ 2345
386
+ end
387
+ assert !File.directory?(tmpdir), "tmpdir should be removed."
388
+ assert_eq ret, 2345
389
+ assert_eq @__at_end_blocks, nil
390
+ ensure
391
+ Dir.rmdir(tmpdir) if File.exist?(tmpdir)
392
+ end
393
+ end
394
+ end
395
+
396
+ describe '#dummy_values()' do
397
+ it "[!hgwg2] changes hash value temporarily." do
398
+ hashobj = {:a=>10, 'b'=>20, :c=>30}
399
+ dummy_values(hashobj, :a=>1000, 'b'=>2000, :x=>9000)
400
+ assert_eq hashobj[:a], 1000
401
+ assert_eq hashobj['b'], 2000
402
+ assert_eq hashobj[:c], 30
403
+ assert_eq hashobj[:x], 9000
404
+ end
405
+ it "[!jw2kx] recovers hash values." do
406
+ hashobj = {:a=>10, 'b'=>20, :c=>30}
407
+ dummy_values(hashobj, :a=>1000, 'b'=>2000, :x=>9000)
408
+ assert_eq hashobj[:a], 1000
409
+ assert_eq hashobj['b'], 2000
410
+ assert_eq hashobj[:c], 30
411
+ assert_eq hashobj[:x], 9000
412
+ assert_eq @__at_end_blocks.length, 1
413
+ pr = @__at_end_blocks.pop()
414
+ pr.call()
415
+ assert_eq hashobj[:a], 10
416
+ assert_eq hashobj['b'], 20
417
+ assert_eq hashobj[:c], 30
418
+ assert !hashobj.key?(:x), "key :x should not exist."
419
+ end
420
+ it "[!w3r0p] returns keyvals." do
421
+ hashobj = {:a=>10, 'b'=>20, :c=>30}
422
+ ret = dummy_values(hashobj, :a=>1000, 'b'=>2000, :x=>9000)
423
+ assert_eq ret, {:a=>1000, 'b'=>2000, :x=>9000}
424
+ end
425
+ it "[!pwq6v] can take block argument." do
426
+ hashobj = {:a=>10, 'b'=>20, :c=>30}
427
+ ret = dummy_values(hashobj, :a=>1000, 'b'=>2000, :x=>9000) do |kvs|
428
+ assert_eq hashobj[:a], 1000
429
+ assert_eq hashobj['b'], 2000
430
+ assert_eq hashobj[:c], 30
431
+ assert_eq hashobj[:x], 9000
432
+ assert_eq kvs, {:a=>1000, 'b'=>2000, :x=>9000}
433
+ 5678
434
+ end
435
+ assert_eq ret, 5678
436
+ assert_eq hashobj[:a], 10
437
+ assert_eq hashobj['b'], 20
438
+ assert_eq hashobj[:c], 30
439
+ assert !hashobj.key?(:x), "key :x should not exist."
440
+ assert_eq @__at_end_blocks, nil
441
+ end
442
+ end
443
+
444
+ describe '#dummy_attrs()' do
445
+ it "[!4vd73] changes object attributes temporarily." do
446
+ obj = DummyUser.new(123, "alice")
447
+ dummy_attrs(obj, :id=>999, :name=>"bob")
448
+ assert_eq obj.id, 999
449
+ assert_eq obj.name, "bob"
450
+ end
451
+ it "[!fi0t3] recovers attribute values." do
452
+ obj = DummyUser.new(123, "alice")
453
+ dummy_attrs(obj, :id=>999, :name=>"bob")
454
+ assert_eq obj.id, 999
455
+ assert_eq obj.name, "bob"
456
+ #
457
+ assert_eq @__at_end_blocks.length, 1
458
+ pr = @__at_end_blocks.pop()
459
+ pr.call()
460
+ assert_eq obj.id, 123
461
+ assert_eq obj.name, "alice"
462
+ end
463
+ it "[!27yeh] returns keyvals." do
464
+ obj = DummyUser.new(123, "alice")
465
+ ret = dummy_attrs(obj, :id=>789, :name=>"charlie")
466
+ assert_eq ret, {:id=>789, :name=>"charlie"}
467
+ end
468
+ it "[!j7tvp] can take block argument." do
469
+ obj = DummyUser.new(123, "alice")
470
+ ret = dummy_attrs(obj, :id=>888, :name=>"dave") do |kvs|
471
+ assert_eq obj.id, 888
472
+ assert_eq obj.name, "dave"
473
+ assert_eq kvs, {:id=>888, :name=>"dave"}
474
+ 4567
475
+ end
476
+ assert_eq ret, 4567
477
+ assert_eq obj.id, 123
478
+ assert_eq obj.name, "alice"
479
+ assert_eq @__at_end_blocks, nil
480
+ end
481
+ end
482
+
483
+ describe '#dummy_ivars()' do
484
+ it "[!rnqiv] changes instance variables temporarily." do
485
+ obj = DummyUser.new(123, "alice")
486
+ dummy_ivars(obj, :id=>999, :name=>"bob")
487
+ assert_eq obj.instance_variable_get('@id'), 999
488
+ assert_eq obj.instance_variable_get('@name'), "bob"
489
+ end
490
+ it "[!8oirn] recovers instance variables." do
491
+ obj = DummyUser.new(123, "alice")
492
+ dummy_ivars(obj, :id=>999, :name=>"bob")
493
+ assert_eq obj.instance_variable_get('@id'), 999
494
+ assert_eq obj.instance_variable_get('@name'), "bob"
495
+ #
496
+ assert_eq @__at_end_blocks.length, 1
497
+ pr = @__at_end_blocks.pop()
498
+ pr.call()
499
+ assert_eq obj.instance_variable_get('@id'), 123
500
+ assert_eq obj.instance_variable_get('@name'), "alice"
501
+ end
502
+ it "[!01dc8] returns keyvals." do
503
+ obj = DummyUser.new(123, "alice")
504
+ ret = dummy_ivars(obj, :id=>789, :name=>"charlie")
505
+ assert_eq ret, {:id=>789, :name=>"charlie"}
506
+ end
507
+ it "[!myzk4] can take block argument." do
508
+ obj = DummyUser.new(123, "alice")
509
+ ret = dummy_attrs(obj, :id=>888, :name=>"dave") do |kvs|
510
+ assert_eq obj.instance_variable_get('@id'), 888
511
+ assert_eq obj.instance_variable_get('@name'), "dave"
512
+ assert_eq kvs, {:id=>888, :name=>"dave"}
513
+ 4567
514
+ end
515
+ assert_eq ret, 4567
516
+ assert_eq obj.id, 123
517
+ assert_eq obj.name, "alice"
518
+ assert_eq @__at_end_blocks, nil
519
+ end
520
+ end
521
+
522
+ describe '#recorder()' do
523
+ it "[!qwrr8] loads 'benry/recorder' automatically." do
524
+ if defined?(Benry::Recorder)
525
+ $stderr.puts "** skip because 'benry/recorder' already loaded."
526
+ else
527
+ assert !defined? Benry::Recorder, "should not be loaded."
528
+ recorder()
529
+ assert defined? Benry::Recorder, "should be loaded."
530
+ end
531
+ end
532
+ it "[!glfvx] creates Benry::Recorder object." do
533
+ rec = recorder()
534
+ assert rec.is_a?(Benry::Recorder)
535
+ o = rec.fake_object(:foo=>123)
536
+ assert_eq o.foo(), 123
537
+ assert_eq rec[0].name, :foo
538
+ assert_eq rec[0].obj, o
539
+ end
540
+ end
541
+
542
+ end