rspec_piccolo 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
- module RSpecPiccolo
2
- VERSION = "0.0.6"
3
- end
1
+ module RSpecPiccolo
2
+ VERSION = '0.0.7'
3
+ end
@@ -1,747 +1,837 @@
1
- # encoding: utf-8
2
- require "spec_helper"
3
- require "rspec_piccolo"
4
- require "fileutils"
5
-
6
- describe RSpecPiccolo::Core do
7
- context :generate do
8
- CASE1_EXPECTED=<<-EOS
9
- # encoding: utf-8
10
- require "spec_helper"
11
- require "hoge_core"
12
-
13
- describe Hoge::Core do
14
-
15
-
16
- end
17
- EOS
18
-
19
- CASE2_EXPECTED=<<-EOS
20
- # encoding: utf-8
21
- require "spec_helper"
22
- require "hoge_core"
23
-
24
- describe Hoge::Core do
25
-
26
- context :method1 do
27
- cases = [
28
- {
29
- case_no: 1,
30
- case_title: "case_title",
31
- expected: "expected",
32
-
33
- },
34
- ]
35
-
36
- cases.each do |c|
37
- it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
38
- begin
39
- case_before c
40
-
41
- # -- given --
42
- hoge_core = Hoge::Core.new
43
-
44
- # -- when --
45
- # TODO: implement execute code
46
- # actual = hoge_core.method1
47
-
48
- # -- then --
49
- # TODO: implement assertion code
50
- # ret = expect(actual).to eq(c[:expected])
51
- ensure
52
- case_after c
53
-
54
- end
55
- end
56
-
57
- def case_before(c)
58
- # implement each case before
59
-
60
- end
61
-
62
- def case_after(c)
63
- # implement each case after
64
- end
65
- end
66
- end
67
-
68
- context :method2 do
69
- cases = [
70
- {
71
- case_no: 1,
72
- case_title: "case_title",
73
- expected: "expected",
74
-
75
- },
76
- ]
77
-
78
- cases.each do |c|
79
- it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
80
- begin
81
- case_before c
82
-
83
- # -- given --
84
- hoge_core = Hoge::Core.new
85
-
86
- # -- when --
87
- # TODO: implement execute code
88
- # actual = hoge_core.method2
89
-
90
- # -- then --
91
- # TODO: implement assertion code
92
- # ret = expect(actual).to eq(c[:expected])
93
- ensure
94
- case_after c
95
-
96
- end
97
- end
98
-
99
- def case_before(c)
100
- # implement each case before
101
-
102
- end
103
-
104
- def case_after(c)
105
- # implement each case after
106
- end
107
- end
108
- end
109
-
110
- end
111
- EOS
112
-
113
- CASE3_EXPECTED=<<-EOS
114
- # encoding: utf-8
115
- require "spec_helper"
116
- require "only_class"
117
-
118
- describe OnlyClass do
119
-
120
- context :method1 do
121
- cases = [
122
- {
123
- case_no: 1,
124
- case_title: "case_title",
125
- expected: "expected",
126
-
127
- },
128
- ]
129
-
130
- cases.each do |c|
131
- it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
132
- begin
133
- case_before c
134
-
135
- # -- given --
136
- only_class = OnlyClass.new
137
-
138
- # -- when --
139
- # TODO: implement execute code
140
- # actual = only_class.method1
141
-
142
- # -- then --
143
- # TODO: implement assertion code
144
- # ret = expect(actual).to eq(c[:expected])
145
- ensure
146
- case_after c
147
-
148
- end
149
- end
150
-
151
- def case_before(c)
152
- # implement each case before
153
-
154
- end
155
-
156
- def case_after(c)
157
- # implement each case after
158
- end
159
- end
160
- end
161
-
162
- context :method2 do
163
- cases = [
164
- {
165
- case_no: 1,
166
- case_title: "case_title",
167
- expected: "expected",
168
-
169
- },
170
- ]
171
-
172
- cases.each do |c|
173
- it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
174
- begin
175
- case_before c
176
-
177
- # -- given --
178
- only_class = OnlyClass.new
179
-
180
- # -- when --
181
- # TODO: implement execute code
182
- # actual = only_class.method2
183
-
184
- # -- then --
185
- # TODO: implement assertion code
186
- # ret = expect(actual).to eq(c[:expected])
187
- ensure
188
- case_after c
189
-
190
- end
191
- end
192
-
193
- def case_before(c)
194
- # implement each case before
195
-
196
- end
197
-
198
- def case_after(c)
199
- # implement each case after
200
- end
201
- end
202
- end
203
-
204
- end
205
- EOS
206
-
207
- CASE4_EXPECTED=<<-EOS
208
- # encoding: utf-8
209
- require "spec_helper"
210
- require "some_dir/hoge_core"
211
-
212
- describe Hoge::Core do
213
-
214
- context :method1 do
215
- cases = [
216
- {
217
- case_no: 1,
218
- case_title: "case_title",
219
- expected: "expected",
220
-
221
- },
222
- ]
223
-
224
- cases.each do |c|
225
- it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
226
- begin
227
- case_before c
228
-
229
- # -- given --
230
- hoge_core = Hoge::Core.new
231
-
232
- # -- when --
233
- # TODO: implement execute code
234
- # actual = hoge_core.method1
235
-
236
- # -- then --
237
- # TODO: implement assertion code
238
- # ret = expect(actual).to eq(c[:expected])
239
- ensure
240
- case_after c
241
-
242
- end
243
- end
244
-
245
- def case_before(c)
246
- # implement each case before
247
-
248
- end
249
-
250
- def case_after(c)
251
- # implement each case after
252
- end
253
- end
254
- end
255
-
256
- context :method2 do
257
- cases = [
258
- {
259
- case_no: 1,
260
- case_title: "case_title",
261
- expected: "expected",
262
-
263
- },
264
- ]
265
-
266
- cases.each do |c|
267
- it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
268
- begin
269
- case_before c
270
-
271
- # -- given --
272
- hoge_core = Hoge::Core.new
273
-
274
- # -- when --
275
- # TODO: implement execute code
276
- # actual = hoge_core.method2
277
-
278
- # -- then --
279
- # TODO: implement assertion code
280
- # ret = expect(actual).to eq(c[:expected])
281
- ensure
282
- case_after c
283
-
284
- end
285
- end
286
-
287
- def case_before(c)
288
- # implement each case before
289
-
290
- end
291
-
292
- def case_after(c)
293
- # implement each case after
294
- end
295
- end
296
- end
297
-
298
- end
299
- EOS
300
-
301
- CASE9_EXPECTED=<<-EOS
302
- # encoding: utf-8
303
- require "spec_helper"
304
- require "some_dir/some_sub_dir/hoge_core"
305
-
306
- describe Hoge::Core do
307
-
308
- context :method1 do
309
- cases = [
310
- {
311
- case_no: 1,
312
- case_title: "case_title",
313
- expected: "expected",
314
-
315
- },
316
- ]
317
-
318
- cases.each do |c|
319
- it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
320
- begin
321
- case_before c
322
-
323
- # -- given --
324
- hoge_core = Hoge::Core.new
325
-
326
- # -- when --
327
- # TODO: implement execute code
328
- # actual = hoge_core.method1
329
-
330
- # -- then --
331
- # TODO: implement assertion code
332
- # ret = expect(actual).to eq(c[:expected])
333
- ensure
334
- case_after c
335
-
336
- end
337
- end
338
-
339
- def case_before(c)
340
- # implement each case before
341
-
342
- end
343
-
344
- def case_after(c)
345
- # implement each case after
346
- end
347
- end
348
- end
349
-
350
- context :method2 do
351
- cases = [
352
- {
353
- case_no: 1,
354
- case_title: "case_title",
355
- expected: "expected",
356
-
357
- },
358
- ]
359
-
360
- cases.each do |c|
361
- it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
362
- begin
363
- case_before c
364
-
365
- # -- given --
366
- hoge_core = Hoge::Core.new
367
-
368
- # -- when --
369
- # TODO: implement execute code
370
- # actual = hoge_core.method2
371
-
372
- # -- then --
373
- # TODO: implement assertion code
374
- # ret = expect(actual).to eq(c[:expected])
375
- ensure
376
- case_after c
377
-
378
- end
379
- end
380
-
381
- def case_before(c)
382
- # implement each case before
383
-
384
- end
385
-
386
- def case_after(c)
387
- # implement each case after
388
- end
389
- end
390
- end
391
-
392
- end
393
- EOS
394
-
395
- CASE10_EXPECTED=<<-EOS
396
- # encoding: utf-8
397
- require "spec_helper"
398
- require "hoge_core"
399
-
400
- describe Hoge::Core do
401
- REPORT = "rspec_report"
402
- DIRS = File.path(__FILE__).gsub(/^.*\\/spec\\//, '').gsub(File.basename(__FILE__), '')
403
- OUT_DIR = "./#\{REPORT}/#\{DIRS}"
404
- REPORT_NAME = report_name = File.basename(__FILE__, ".rb")
405
- REPORT_FILE = "#\{OUT_DIR}#\{REPORT_NAME}.tsv"
406
-
407
- mkspec_report = Proc.new do
408
- Dir.mkdir(REPORT) unless File.exists?(REPORT)
409
- FileUtils.mkdir_p(OUT_DIR) unless File.exists?(OUT_DIR)
410
- File.open(REPORT_FILE, "w") {|f|f.puts "method\\tcase\\ttitle\\tsuccess\\/failure"}
411
- end.call
412
-
413
- success = Proc.new {|c|File.open(REPORT_FILE, "a") {|f|f.puts "\\tsuccess"}}
414
- failure = Proc.new {|c|File.open(REPORT_FILE, "a") {|f|f.puts "\\tfailure"}}
415
-
416
- context :method1 do
417
- cases = [
418
- {
419
- case_no: 1,
420
- case_title: "case_title",
421
- expected: "expected",
422
- success_hook: success,
423
- failure_hook: failure
424
- },
425
- ]
426
-
427
- cases.each do |c|
428
- it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
429
- begin
430
- case_before c
431
-
432
- # -- given --
433
- hoge_core = Hoge::Core.new
434
-
435
- # -- when --
436
- # TODO: implement execute code
437
- # actual = hoge_core.method1
438
-
439
- # -- then --
440
- # TODO: implement assertion code
441
- # ret = expect(actual).to eq(c[:expected])
442
- ensure
443
- case_after c
444
- sf_hook = ret ? c[:success_hook] : c[:failure_hook]
445
- sf_hook.call(c)
446
- end
447
- end
448
-
449
- def case_before(c)
450
- # implement each case before
451
- File.open(REPORT_FILE, "a") {|f|f.print "method1\\t#\{c[:case_no]}\\t#\{c[:case_title]}"}
452
- end
453
-
454
- def case_after(c)
455
- # implement each case after
456
- end
457
- end
458
- end
459
-
460
- context :method2 do
461
- cases = [
462
- {
463
- case_no: 1,
464
- case_title: "case_title",
465
- expected: "expected",
466
- success_hook: success,
467
- failure_hook: failure
468
- },
469
- ]
470
-
471
- cases.each do |c|
472
- it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
473
- begin
474
- case_before c
475
-
476
- # -- given --
477
- hoge_core = Hoge::Core.new
478
-
479
- # -- when --
480
- # TODO: implement execute code
481
- # actual = hoge_core.method2
482
-
483
- # -- then --
484
- # TODO: implement assertion code
485
- # ret = expect(actual).to eq(c[:expected])
486
- ensure
487
- case_after c
488
- sf_hook = ret ? c[:success_hook] : c[:failure_hook]
489
- sf_hook.call(c)
490
- end
491
- end
492
-
493
- def case_before(c)
494
- # implement each case before
495
- File.open(REPORT_FILE, "a") {|f|f.print "method2\\t#\{c[:case_no]}\\t#\{c[:case_title]}"}
496
- end
497
-
498
- def case_after(c)
499
- # implement each case after
500
- end
501
- end
502
- end
503
-
504
- end
505
- EOS
506
-
507
- CASE11_EXPECTED=<<-EOS
508
- # encoding: utf-8
509
- require "spec_helper"
510
- require "hoge_core"
511
-
512
- describe Hoge::Core do
513
-
514
- context :method1 do
515
- cases = [
516
- {
517
- case_no: 1,
518
- case_title: "case_title",
519
- expected: "expected",
520
-
521
- },
522
- ]
523
-
524
- cases.each do |c|
525
- it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
526
- begin
527
- case_before c
528
-
529
- # -- given --
530
- hoge_core = Hoge::Core.new
531
-
532
- # -- when --
533
- # TODO: implement execute code
534
- # actual = hoge_core.method1
535
-
536
- # -- then --
537
- # TODO: implement assertion code
538
- # ret = expect(actual).to eq(c[:expected])
539
- ensure
540
- case_after c
541
-
542
- end
543
- end
544
-
545
- def case_before(c)
546
- # implement each case before
547
-
548
- end
549
-
550
- def case_after(c)
551
- # implement each case after
552
- end
553
- end
554
- end
555
-
556
- context :method2 do
557
- cases = [
558
- {
559
- case_no: 1,
560
- case_title: "case_title",
561
- expected: "expected",
562
-
563
- },
564
- ]
565
-
566
- cases.each do |c|
567
- it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
568
- begin
569
- case_before c
570
-
571
- # -- given --
572
- # nothing
573
-
574
- # -- when --
575
- # TODO: implement execute code
576
- # actual = Hoge::Core.method2
577
-
578
- # -- then --
579
- # TODO: implement assertion code
580
- # ret = expect(actual).to eq(c[:expected])
581
- ensure
582
- case_after c
583
-
584
- end
585
- end
586
-
587
- def case_before(c)
588
- # implement each case before
589
-
590
- end
591
-
592
- def case_after(c)
593
- # implement each case after
594
- end
595
- end
596
- end
597
-
598
- end
599
- EOS
600
-
601
- cases = [
602
- {
603
- case_no: 1,
604
- case_title: "only classname",
605
- class_name: "Hoge::Core",
606
- class_path: "hoge_core",
607
- method_names: nil,
608
- expected_file_name: "./spec/hoge_core_spec.rb",
609
- expected_file_exists: true,
610
- expected_contents: CASE1_EXPECTED
611
- },
612
- {
613
- case_no: 2,
614
- case_title: "classname(with module) and method_names",
615
- class_name: "Hoge::Core",
616
- class_path: "hoge_core",
617
- method_names: ["method1", "method2"],
618
- expected_file_name: "./spec/hoge_core_spec.rb",
619
- expected_file_exists: true,
620
- expected_contents: CASE2_EXPECTED
621
- },
622
- {
623
- case_no: 3,
624
- case_title: "classname(with no module) and method_names",
625
- class_name: "OnlyClass",
626
- class_path: "only_class",
627
- method_names: ["method1", "method2"],
628
- expected_file_name: "./spec/only_class_spec.rb",
629
- expected_file_exists: true,
630
- expected_contents: CASE3_EXPECTED
631
- },
632
- {
633
- case_no: 4,
634
- case_title: "with directory, classname(with module) and method_names",
635
- class_name: "Hoge::Core",
636
- class_path: "some_dir/hoge_core",
637
- del_dir: "some_dir",
638
- method_names: ["method1", "method2"],
639
- expected_file_name: "./spec/some_dir/hoge_core_spec.rb",
640
- expected_file_exists: true,
641
- expected_contents: CASE4_EXPECTED
642
- },
643
- {
644
- case_no: 5,
645
- case_title: "nil_class",
646
- class_name: nil,
647
- class_path: "some_dir/hoge_core",
648
- method_names: ["method1"],
649
- expect_error: true
650
- },
651
- {
652
- case_no: 6,
653
- case_title: "empty_class",
654
- class_name: "",
655
- class_path: "empty_class",
656
- method_names: ["method1"],
657
- expect_error: true
658
- },
659
- {
660
- case_no: 7,
661
- case_title: "nil_class_path",
662
- class_name: "nil_class_path",
663
- class_path: nil,
664
- method_names: ["method1"],
665
- expect_error: true
666
- },
667
- {
668
- case_no: 8,
669
- case_title: "empty_class_path",
670
- class_name: "empty_class_path",
671
- class_path: "",
672
- method_names: ["method1"],
673
- expect_error: true
674
- },
675
- {
676
- case_no: 9,
677
- case_title: "with two directories, classname(with module) and method_names",
678
- class_name: "Hoge::Core",
679
- class_path: "some_dir/some_sub_dir/hoge_core",
680
- del_dir: "some_dir",
681
- method_names: ["method1", "method2"],
682
- expected_file_name: "./spec/some_dir/some_sub_dir/hoge_core_spec.rb",
683
- expected_file_exists: true,
684
- expected_contents: CASE9_EXPECTED
685
- },
686
- {
687
- case_no: 10,
688
- case_title: "classname(with module) and method_names",
689
- class_name: "Hoge::Core",
690
- class_path: "hoge_core",
691
- method_names: ["method1", "method2"],
692
- reportable: true,
693
- expected_file_name: "./spec/hoge_core_spec.rb",
694
- expected_file_exists: true,
695
- expected_contents: CASE10_EXPECTED
696
- },
697
- {
698
- case_no: 11,
699
- case_title: "classname(with module) and method_names(instance method, class method)",
700
- class_name: "Hoge::Core",
701
- class_path: "hoge_core",
702
- method_names: ["method1", "method2@c"],
703
- expected_file_name: "./spec/hoge_core_spec.rb",
704
- expected_file_exists: true,
705
- expected_contents: CASE11_EXPECTED
706
- },
707
- ]
708
-
709
- cases.each do |c|
710
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
711
- begin
712
- case_before c
713
-
714
- # -- given --
715
- piccolo = RSpecPiccolo::Core.new
716
-
717
- # -- when --
718
- if c[:expect_error]
719
- lambda {piccolo.generate(c[:class_name], c[:class_path], c[:method_names], c[:reportable])}.should raise_error(RSpecPiccolo::RSpecPiccoloError)
720
- # case_after c
721
- next
722
- end
723
- piccolo.generate(c[:class_name], c[:class_path], c[:method_names], c[:reportable])
724
-
725
- # -- then --
726
- expect(File.exists?(c[:expected_file_name])).to be_true
727
- actual = File.open(c[:expected_file_name]) {|f|f.read}
728
- expect(actual).to eq(c[:expected_contents])
729
- ensure
730
- case_after c
731
- end
732
- end
733
-
734
- def case_before(c)
735
- # implement each case before
736
-
737
- end
738
-
739
- def case_after(c)
740
- # implement each case after
741
- return if c[:expect_error]
742
- File.delete(c[:expected_file_name]) if File.exists?(c[:expected_file_name])
743
- FileUtils.rm_rf("spec/some_dir")
744
- end
745
- end
746
- end
747
- end
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'rspec_piccolo'
4
+ require 'fileutils'
5
+
6
+ describe RSpecPiccolo::Core do
7
+ context :generate do
8
+ CASE1_EXPECTED = <<-EOS
9
+ # encoding: utf-8
10
+ require "spec_helper"
11
+ require "hoge_core"
12
+
13
+ describe Hoge::Core do
14
+
15
+
16
+ end
17
+ EOS
18
+
19
+ CASE2_EXPECTED = <<-EOS
20
+ # encoding: utf-8
21
+ require "spec_helper"
22
+ require "hoge_core"
23
+
24
+ describe Hoge::Core do
25
+
26
+ context :method1 do
27
+ cases = [
28
+ {
29
+ case_no: 1,
30
+ case_title: "case_title",
31
+ expected: "expected",
32
+ },
33
+ ]
34
+
35
+ cases.each do |c|
36
+ it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
37
+ begin
38
+ case_before c
39
+
40
+ # -- given --
41
+ hoge_core = Hoge::Core.new
42
+
43
+ # -- when --
44
+ # TODO: implement execute code
45
+ # actual = hoge_core.method1
46
+
47
+ # -- then --
48
+ # TODO: implement assertion code
49
+ # expect(actual).to eq(c[:expected])
50
+ ensure
51
+ case_after c
52
+ end
53
+ end
54
+
55
+ def case_before(c)
56
+ # implement each case before
57
+ end
58
+
59
+ def case_after(c)
60
+ # implement each case after
61
+ end
62
+ end
63
+ end
64
+
65
+ context :method2 do
66
+ cases = [
67
+ {
68
+ case_no: 1,
69
+ case_title: "case_title",
70
+ expected: "expected",
71
+ },
72
+ ]
73
+
74
+ cases.each do |c|
75
+ it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
76
+ begin
77
+ case_before c
78
+
79
+ # -- given --
80
+ hoge_core = Hoge::Core.new
81
+
82
+ # -- when --
83
+ # TODO: implement execute code
84
+ # actual = hoge_core.method2
85
+
86
+ # -- then --
87
+ # TODO: implement assertion code
88
+ # expect(actual).to eq(c[:expected])
89
+ ensure
90
+ case_after c
91
+ end
92
+ end
93
+
94
+ def case_before(c)
95
+ # implement each case before
96
+ end
97
+
98
+ def case_after(c)
99
+ # implement each case after
100
+ end
101
+ end
102
+ end
103
+ end
104
+ EOS
105
+
106
+ CASE3_EXPECTED = <<-EOS
107
+ # encoding: utf-8
108
+ require "spec_helper"
109
+ require "only_class"
110
+
111
+ describe OnlyClass do
112
+
113
+ context :method1 do
114
+ cases = [
115
+ {
116
+ case_no: 1,
117
+ case_title: "case_title",
118
+ expected: "expected",
119
+ },
120
+ ]
121
+
122
+ cases.each do |c|
123
+ it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
124
+ begin
125
+ case_before c
126
+
127
+ # -- given --
128
+ only_class = OnlyClass.new
129
+
130
+ # -- when --
131
+ # TODO: implement execute code
132
+ # actual = only_class.method1
133
+
134
+ # -- then --
135
+ # TODO: implement assertion code
136
+ # expect(actual).to eq(c[:expected])
137
+ ensure
138
+ case_after c
139
+ end
140
+ end
141
+
142
+ def case_before(c)
143
+ # implement each case before
144
+ end
145
+
146
+ def case_after(c)
147
+ # implement each case after
148
+ end
149
+ end
150
+ end
151
+
152
+ context :method2 do
153
+ cases = [
154
+ {
155
+ case_no: 1,
156
+ case_title: "case_title",
157
+ expected: "expected",
158
+ },
159
+ ]
160
+
161
+ cases.each do |c|
162
+ it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
163
+ begin
164
+ case_before c
165
+
166
+ # -- given --
167
+ only_class = OnlyClass.new
168
+
169
+ # -- when --
170
+ # TODO: implement execute code
171
+ # actual = only_class.method2
172
+
173
+ # -- then --
174
+ # TODO: implement assertion code
175
+ # expect(actual).to eq(c[:expected])
176
+ ensure
177
+ case_after c
178
+ end
179
+ end
180
+
181
+ def case_before(c)
182
+ # implement each case before
183
+ end
184
+
185
+ def case_after(c)
186
+ # implement each case after
187
+ end
188
+ end
189
+ end
190
+ end
191
+ EOS
192
+
193
+ CASE4_EXPECTED = <<-EOS
194
+ # encoding: utf-8
195
+ require "spec_helper"
196
+ require "some_dir/hoge_core"
197
+
198
+ describe Hoge::Core do
199
+
200
+ context :method1 do
201
+ cases = [
202
+ {
203
+ case_no: 1,
204
+ case_title: "case_title",
205
+ expected: "expected",
206
+ },
207
+ ]
208
+
209
+ cases.each do |c|
210
+ it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
211
+ begin
212
+ case_before c
213
+
214
+ # -- given --
215
+ hoge_core = Hoge::Core.new
216
+
217
+ # -- when --
218
+ # TODO: implement execute code
219
+ # actual = hoge_core.method1
220
+
221
+ # -- then --
222
+ # TODO: implement assertion code
223
+ # expect(actual).to eq(c[:expected])
224
+ ensure
225
+ case_after c
226
+ end
227
+ end
228
+
229
+ def case_before(c)
230
+ # implement each case before
231
+ end
232
+
233
+ def case_after(c)
234
+ # implement each case after
235
+ end
236
+ end
237
+ end
238
+
239
+ context :method2 do
240
+ cases = [
241
+ {
242
+ case_no: 1,
243
+ case_title: "case_title",
244
+ expected: "expected",
245
+ },
246
+ ]
247
+
248
+ cases.each do |c|
249
+ it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
250
+ begin
251
+ case_before c
252
+
253
+ # -- given --
254
+ hoge_core = Hoge::Core.new
255
+
256
+ # -- when --
257
+ # TODO: implement execute code
258
+ # actual = hoge_core.method2
259
+
260
+ # -- then --
261
+ # TODO: implement assertion code
262
+ # expect(actual).to eq(c[:expected])
263
+ ensure
264
+ case_after c
265
+ end
266
+ end
267
+
268
+ def case_before(c)
269
+ # implement each case before
270
+ end
271
+
272
+ def case_after(c)
273
+ # implement each case after
274
+ end
275
+ end
276
+ end
277
+ end
278
+ EOS
279
+
280
+ CASE9_EXPECTED = <<-EOS
281
+ # encoding: utf-8
282
+ require "spec_helper"
283
+ require "some_dir/some_sub_dir/hoge_core"
284
+
285
+ describe Hoge::Core do
286
+
287
+ context :method1 do
288
+ cases = [
289
+ {
290
+ case_no: 1,
291
+ case_title: "case_title",
292
+ expected: "expected",
293
+ },
294
+ ]
295
+
296
+ cases.each do |c|
297
+ it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
298
+ begin
299
+ case_before c
300
+
301
+ # -- given --
302
+ hoge_core = Hoge::Core.new
303
+
304
+ # -- when --
305
+ # TODO: implement execute code
306
+ # actual = hoge_core.method1
307
+
308
+ # -- then --
309
+ # TODO: implement assertion code
310
+ # expect(actual).to eq(c[:expected])
311
+ ensure
312
+ case_after c
313
+ end
314
+ end
315
+
316
+ def case_before(c)
317
+ # implement each case before
318
+ end
319
+
320
+ def case_after(c)
321
+ # implement each case after
322
+ end
323
+ end
324
+ end
325
+
326
+ context :method2 do
327
+ cases = [
328
+ {
329
+ case_no: 1,
330
+ case_title: "case_title",
331
+ expected: "expected",
332
+ },
333
+ ]
334
+
335
+ cases.each do |c|
336
+ it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
337
+ begin
338
+ case_before c
339
+
340
+ # -- given --
341
+ hoge_core = Hoge::Core.new
342
+
343
+ # -- when --
344
+ # TODO: implement execute code
345
+ # actual = hoge_core.method2
346
+
347
+ # -- then --
348
+ # TODO: implement assertion code
349
+ # expect(actual).to eq(c[:expected])
350
+ ensure
351
+ case_after c
352
+ end
353
+ end
354
+
355
+ def case_before(c)
356
+ # implement each case before
357
+ end
358
+
359
+ def case_after(c)
360
+ # implement each case after
361
+ end
362
+ end
363
+ end
364
+ end
365
+ EOS
366
+
367
+ CASE10_EXPECTED = <<-EOS
368
+ # encoding: utf-8
369
+ require "spec_helper"
370
+ require "hoge_core"
371
+
372
+ describe Hoge::Core do
373
+ REPORT = "rspec_report"
374
+ DIRS = File.path(__FILE__).gsub(/^.*\\/spec\\//, '').gsub(File.basename(__FILE__), '')
375
+ OUT_DIR = "./#\{REPORT}/#\{DIRS}"
376
+ REPORT_NAME = report_name = File.basename(__FILE__, ".rb")
377
+ REPORT_FILE = "#\{OUT_DIR}#\{REPORT_NAME}.tsv"
378
+
379
+ mkspec_report = Proc.new do
380
+ Dir.mkdir(REPORT) unless File.exists?(REPORT)
381
+ FileUtils.mkdir_p(OUT_DIR) unless File.exists?(OUT_DIR)
382
+ File.open(REPORT_FILE, "w") {|f|f.puts "method\\tcase\\ttitle\\tsuccess\\/failure"}
383
+ end.call
384
+
385
+ success = Proc.new {|c|File.open(REPORT_FILE, "a") {|f|f.puts "\\tsuccess"}}
386
+ failure = Proc.new {|c|File.open(REPORT_FILE, "a") {|f|f.puts "\\tfailure"}}
387
+
388
+ context :method1 do
389
+ cases = [
390
+ {
391
+ case_no: 1,
392
+ case_title: "case_title",
393
+ expected: "expected",
394
+ success_hook: success,
395
+ failure_hook: failure
396
+ },
397
+ ]
398
+
399
+ cases.each do |c|
400
+ it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
401
+ begin
402
+ case_before c
403
+
404
+ # -- given --
405
+ hoge_core = Hoge::Core.new
406
+
407
+ # -- when --
408
+ # TODO: implement execute code
409
+ # actual = hoge_core.method1
410
+
411
+ # -- then --
412
+ # TODO: implement assertion code
413
+ # ret = expect(actual).to eq(c[:expected])
414
+ ensure
415
+ case_after c
416
+ sf_hook = ret ? c[:success_hook] : c[:failure_hook]
417
+ sf_hook.call(c)
418
+ end
419
+ end
420
+
421
+ def case_before(c)
422
+ # implement each case before
423
+ File.open(REPORT_FILE, "a") {|f|f.print "method1\\t#\{c[:case_no]}\\t#\{c[:case_title]}"}
424
+ end
425
+
426
+ def case_after(c)
427
+ # implement each case after
428
+ end
429
+ end
430
+ end
431
+
432
+ context :method2 do
433
+ cases = [
434
+ {
435
+ case_no: 1,
436
+ case_title: "case_title",
437
+ expected: "expected",
438
+ success_hook: success,
439
+ failure_hook: failure
440
+ },
441
+ ]
442
+
443
+ cases.each do |c|
444
+ it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
445
+ begin
446
+ case_before c
447
+
448
+ # -- given --
449
+ hoge_core = Hoge::Core.new
450
+
451
+ # -- when --
452
+ # TODO: implement execute code
453
+ # actual = hoge_core.method2
454
+
455
+ # -- then --
456
+ # TODO: implement assertion code
457
+ # ret = expect(actual).to eq(c[:expected])
458
+ ensure
459
+ case_after c
460
+ sf_hook = ret ? c[:success_hook] : c[:failure_hook]
461
+ sf_hook.call(c)
462
+ end
463
+ end
464
+
465
+ def case_before(c)
466
+ # implement each case before
467
+ File.open(REPORT_FILE, "a") {|f|f.print "method2\\t#\{c[:case_no]}\\t#\{c[:case_title]}"}
468
+ end
469
+
470
+ def case_after(c)
471
+ # implement each case after
472
+ end
473
+ end
474
+ end
475
+ end
476
+ EOS
477
+
478
+ CASE11_EXPECTED = <<-EOS
479
+ # encoding: utf-8
480
+ require "spec_helper"
481
+ require "hoge_core"
482
+
483
+ describe Hoge::Core do
484
+
485
+ context :method1 do
486
+ cases = [
487
+ {
488
+ case_no: 1,
489
+ case_title: "case_title",
490
+ expected: "expected",
491
+ },
492
+ ]
493
+
494
+ cases.each do |c|
495
+ it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
496
+ begin
497
+ case_before c
498
+
499
+ # -- given --
500
+ hoge_core = Hoge::Core.new
501
+
502
+ # -- when --
503
+ # TODO: implement execute code
504
+ # actual = hoge_core.method1
505
+
506
+ # -- then --
507
+ # TODO: implement assertion code
508
+ # expect(actual).to eq(c[:expected])
509
+ ensure
510
+ case_after c
511
+ end
512
+ end
513
+
514
+ def case_before(c)
515
+ # implement each case before
516
+ end
517
+
518
+ def case_after(c)
519
+ # implement each case after
520
+ end
521
+ end
522
+ end
523
+
524
+ context :method2 do
525
+ cases = [
526
+ {
527
+ case_no: 1,
528
+ case_title: "case_title",
529
+ expected: "expected",
530
+ },
531
+ ]
532
+
533
+ cases.each do |c|
534
+ it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
535
+ begin
536
+ case_before c
537
+
538
+ # -- given --
539
+ # nothing
540
+
541
+ # -- when --
542
+ # TODO: implement execute code
543
+ # actual = Hoge::Core.method2
544
+
545
+ # -- then --
546
+ # TODO: implement assertion code
547
+ # expect(actual).to eq(c[:expected])
548
+ ensure
549
+ case_after c
550
+ end
551
+ end
552
+
553
+ def case_before(c)
554
+ # implement each case before
555
+ end
556
+
557
+ def case_after(c)
558
+ # implement each case after
559
+ end
560
+ end
561
+ end
562
+ end
563
+ EOS
564
+
565
+
566
+ CASE12_EXPECTED = <<-EOS
567
+ # encoding: utf-8
568
+ require "spec_helper"
569
+ require "some_dir/hoge_core"
570
+
571
+ describe Hoge::Core do
572
+
573
+ context :method1 do
574
+ cases = [
575
+ {
576
+ case_no: 1,
577
+ case_title: "case_title",
578
+ expected: "expected",
579
+ },
580
+ ]
581
+
582
+ cases.each do |c|
583
+ it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
584
+ begin
585
+ case_before c
586
+
587
+ # -- given --
588
+ hoge_core = Hoge::Core.new
589
+
590
+ # -- when --
591
+ # TODO: implement execute code
592
+ # actual = hoge_core.method1
593
+
594
+ # -- then --
595
+ # TODO: implement assertion code
596
+ # expect(actual).to eq(c[:expected])
597
+ ensure
598
+ case_after c
599
+ end
600
+ end
601
+
602
+ def case_before(c)
603
+ # implement each case before
604
+ end
605
+
606
+ def case_after(c)
607
+ # implement each case after
608
+ end
609
+ end
610
+ end
611
+
612
+ context :method2 do
613
+ cases = [
614
+ {
615
+ case_no: 1,
616
+ case_title: "case_title",
617
+ expected: "expected",
618
+ },
619
+ ]
620
+
621
+ cases.each do |c|
622
+ it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
623
+ begin
624
+ case_before c
625
+
626
+ # -- given --
627
+ # nothing
628
+
629
+ # -- when --
630
+ # TODO: implement execute code
631
+ # actual = Hoge::Core.method2
632
+
633
+ # -- then --
634
+ # TODO: implement assertion code
635
+ # expect(actual).to eq(c[:expected])
636
+ ensure
637
+ case_after c
638
+ end
639
+ end
640
+
641
+ def case_before(c)
642
+ # implement each case before
643
+ end
644
+
645
+ def case_after(c)
646
+ # implement each case after
647
+ end
648
+ end
649
+ end
650
+ end
651
+ EOS
652
+
653
+ CASE12_PRODUCT_EXPECTED = <<-EOS
654
+ # encoding: utf-8
655
+
656
+ module Hoge
657
+ class Core
658
+ def method1
659
+ # TOOD: implement your code
660
+ end
661
+
662
+ def self.method2
663
+ # TOOD: implement your code
664
+ end
665
+ end
666
+ end
667
+ EOS
668
+
669
+ cases = [
670
+ {
671
+ case_no: 1,
672
+ case_title: 'only classname',
673
+ class_name: 'Hoge::Core',
674
+ class_path: 'hoge_core',
675
+ method_names: nil,
676
+ expected_file_name: './spec/hoge_core_spec.rb',
677
+ expected_file_exists: true,
678
+ expected_contents: CASE1_EXPECTED
679
+ },
680
+ {
681
+ case_no: 2,
682
+ case_title: 'classname(with module) and method_names',
683
+ class_name: 'Hoge::Core',
684
+ class_path: 'hoge_core',
685
+ method_names: ['method1', 'method2'],
686
+ expected_file_name: './spec/hoge_core_spec.rb',
687
+ expected_file_exists: true,
688
+ expected_contents: CASE2_EXPECTED
689
+ },
690
+ {
691
+ case_no: 3,
692
+ case_title: 'classname(with no module) and method_names',
693
+ class_name: 'OnlyClass',
694
+ class_path: 'only_class',
695
+ method_names: ['method1', 'method2'],
696
+ expected_file_name: './spec/only_class_spec.rb',
697
+ expected_file_exists: true,
698
+ expected_contents: CASE3_EXPECTED
699
+ },
700
+ {
701
+ case_no: 4,
702
+ case_title: 'with directory, classname(with module) and method_names',
703
+ class_name: 'Hoge::Core',
704
+ class_path: 'some_dir/hoge_core',
705
+ del_dir: 'some_dir',
706
+ method_names: ['method1', 'method2'],
707
+ expected_file_name: './spec/some_dir/hoge_core_spec.rb',
708
+ expected_file_exists: true,
709
+ expected_contents: CASE4_EXPECTED
710
+ },
711
+ {
712
+ case_no: 5,
713
+ case_title: 'nil_class',
714
+ class_name: nil,
715
+ class_path: 'some_dir/hoge_core',
716
+ method_names: ['method1'],
717
+ expect_error: true
718
+ },
719
+ {
720
+ case_no: 6,
721
+ case_title: 'empty_class',
722
+ class_name: '',
723
+ class_path: 'empty_class',
724
+ method_names: ['method1'],
725
+ expect_error: true
726
+ },
727
+ {
728
+ case_no: 7,
729
+ case_title: 'nil_class_path',
730
+ class_name: 'nil_class_path',
731
+ class_path: nil,
732
+ method_names: ['method1'],
733
+ expect_error: true
734
+ },
735
+ {
736
+ case_no: 8,
737
+ case_title: 'empty_class_path',
738
+ class_name: 'empty_class_path',
739
+ class_path: '',
740
+ method_names: ['method1'],
741
+ expect_error: true
742
+ },
743
+ {
744
+ case_no: 9,
745
+ case_title: 'with two directories, classname(with module) and method_names',
746
+ class_name: 'Hoge::Core',
747
+ class_path: 'some_dir/some_sub_dir/hoge_core',
748
+ del_dir: 'some_dir',
749
+ method_names: ['method1', 'method2'],
750
+ expected_file_name: './spec/some_dir/some_sub_dir/hoge_core_spec.rb',
751
+ expected_file_exists: true,
752
+ expected_contents: CASE9_EXPECTED
753
+ },
754
+ {
755
+ case_no: 10,
756
+ case_title: 'classname(with module) and method_names reportable',
757
+ class_name: 'Hoge::Core',
758
+ class_path: 'hoge_core',
759
+ method_names: ['method1', 'method2'],
760
+ reportable: true,
761
+ expected_file_name: './spec/hoge_core_spec.rb',
762
+ expected_file_exists: true,
763
+ expected_contents: CASE10_EXPECTED
764
+ },
765
+ {
766
+ case_no: 11,
767
+ case_title: 'classname(with module) and method_names(instance method, class method)',
768
+ class_name: 'Hoge::Core',
769
+ class_path: 'hoge_core',
770
+ method_names: ['method1', 'method2@c'],
771
+ expected_file_name: './spec/hoge_core_spec.rb',
772
+ expected_file_exists: true,
773
+ expected_contents: CASE11_EXPECTED
774
+ },
775
+ {
776
+ case_no: 12,
777
+ case_title: 'classname(with module) and method_names(instance method, class method) and product code output',
778
+ class_name: 'Hoge::Core',
779
+ class_path: 'some_dir/hoge_core',
780
+ method_names: ['method1', 'method2@c'],
781
+ productcode: true,
782
+ expected_file_name: './spec/some_dir/hoge_core_spec.rb',
783
+ expected_file_exists: true,
784
+ expected_product_file_name: './lib/some_dir/hoge_core.rb',
785
+ expected_product_file_exists: true,
786
+ expected_contents: CASE12_EXPECTED,
787
+ expected_product_contents: CASE12_PRODUCT_EXPECTED
788
+ },
789
+ ]
790
+
791
+ cases.each do |c|
792
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
793
+ begin
794
+ case_before c
795
+
796
+ # -- given --
797
+ piccolo = RSpecPiccolo::Core.new
798
+ options = {}
799
+ options[:reportable] = c[:reportable]
800
+ options[:productcode] = c[:productcode]
801
+
802
+ # -- when --
803
+ if c[:expect_error]
804
+ lambda { piccolo.generate(c[:class_name], c[:class_path], c[:method_names], options) }.should raise_error(RSpecPiccolo::RSpecPiccoloError)
805
+ next
806
+ end
807
+ piccolo.generate(c[:class_name], c[:class_path], c[:method_names], options)
808
+
809
+ # -- then --
810
+ expect(File.exists?(c[:expected_file_name])).to be_true
811
+ actual = File.open(c[:expected_file_name]) { |f|f.read }
812
+ expect(actual).to eq(c[:expected_contents])
813
+ if c[:productcode]
814
+ expect(File.exists?(c[:expected_product_file_name])).to be_true
815
+ actual = File.open(c[:expected_product_file_name]) { |f|f.read }
816
+ expect(actual).to eq(c[:expected_product_contents])
817
+ end
818
+ ensure
819
+ case_after c
820
+ end
821
+ end
822
+
823
+ def case_before(c)
824
+ # implement each case before
825
+ end
826
+
827
+ def case_after(c)
828
+ # implement each case after
829
+ return if c[:expect_error]
830
+ File.delete(c[:expected_file_name]) if File.exists?(c[:expected_file_name])
831
+ FileUtils.rm_rf('spec/some_dir')
832
+ File.delete(c[:expected_product_file_name]) if !c[:expected_product_file_name].nil? && File.exists?(c[:expected_product_file_name])
833
+ FileUtils.rm_rf('lib/some_dir')
834
+ end
835
+ end
836
+ end
837
+ end