rspec_piccolo 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module RSpecPiccolo
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -1,490 +1,643 @@
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
- end
16
- EOS
17
-
18
- CASE2_EXPECTED=<<-EOS
19
- # encoding: utf-8
20
- require "spec_helper"
21
- require "hoge_core"
22
-
23
- describe Hoge::Core do
24
- context :method1 do
25
- cases = [
26
- {
27
- case_no: 1,
28
- case_title: "case_title",
29
- expected: "expected"
30
- },
31
- ]
32
-
33
- cases.each do |c|
34
- it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
35
- begin
36
- case_before c
37
-
38
- # -- given --
39
- hoge_core = Hoge::Core.new
40
-
41
- # -- when --
42
- # TODO: implement execute code
43
- # actual = hoge_core.method1
44
-
45
- # -- then --
46
- # TODO: implement assertion code
47
- # expect(actual).to eq(c[:expected])
48
- ensure
49
- case_after c
50
- end
51
- end
52
-
53
- def case_before(c)
54
- # implement each case before
55
- end
56
-
57
- def case_after(c)
58
- # implement each case after
59
- end
60
- end
61
- end
62
-
63
- context :method2 do
64
- cases = [
65
- {
66
- case_no: 1,
67
- case_title: "case_title",
68
- expected: "expected"
69
- },
70
- ]
71
-
72
- cases.each do |c|
73
- it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
74
- begin
75
- case_before c
76
-
77
- # -- given --
78
- hoge_core = Hoge::Core.new
79
-
80
- # -- when --
81
- # TODO: implement execute code
82
- # actual = hoge_core.method2
83
-
84
- # -- then --
85
- # TODO: implement assertion code
86
- # expect(actual).to eq(c[:expected])
87
- ensure
88
- case_after c
89
- end
90
- end
91
-
92
- def case_before(c)
93
- # implement each case before
94
- end
95
-
96
- def case_after(c)
97
- # implement each case after
98
- end
99
- end
100
- end
101
-
102
- end
103
- EOS
104
-
105
- CASE3_EXPECTED=<<-EOS
106
- # encoding: utf-8
107
- require "spec_helper"
108
- require "only_class"
109
-
110
- describe OnlyClass do
111
- context :method1 do
112
- cases = [
113
- {
114
- case_no: 1,
115
- case_title: "case_title",
116
- expected: "expected"
117
- },
118
- ]
119
-
120
- cases.each do |c|
121
- it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
122
- begin
123
- case_before c
124
-
125
- # -- given --
126
- only_class = OnlyClass.new
127
-
128
- # -- when --
129
- # TODO: implement execute code
130
- # actual = only_class.method1
131
-
132
- # -- then --
133
- # TODO: implement assertion code
134
- # expect(actual).to eq(c[:expected])
135
- ensure
136
- case_after c
137
- end
138
- end
139
-
140
- def case_before(c)
141
- # implement each case before
142
- end
143
-
144
- def case_after(c)
145
- # implement each case after
146
- end
147
- end
148
- end
149
-
150
- context :method2 do
151
- cases = [
152
- {
153
- case_no: 1,
154
- case_title: "case_title",
155
- expected: "expected"
156
- },
157
- ]
158
-
159
- cases.each do |c|
160
- it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
161
- begin
162
- case_before c
163
-
164
- # -- given --
165
- only_class = OnlyClass.new
166
-
167
- # -- when --
168
- # TODO: implement execute code
169
- # actual = only_class.method2
170
-
171
- # -- then --
172
- # TODO: implement assertion code
173
- # expect(actual).to eq(c[:expected])
174
- ensure
175
- case_after c
176
- end
177
- end
178
-
179
- def case_before(c)
180
- # implement each case before
181
- end
182
-
183
- def case_after(c)
184
- # implement each case after
185
- end
186
- end
187
- end
188
-
189
- end
190
- EOS
191
-
192
- CASE4_EXPECTED=<<-EOS
193
- # encoding: utf-8
194
- require "spec_helper"
195
- require "some_dir/hoge_core"
196
-
197
- describe Hoge::Core do
198
- context :method1 do
199
- cases = [
200
- {
201
- case_no: 1,
202
- case_title: "case_title",
203
- expected: "expected"
204
- },
205
- ]
206
-
207
- cases.each do |c|
208
- it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
209
- begin
210
- case_before c
211
-
212
- # -- given --
213
- hoge_core = Hoge::Core.new
214
-
215
- # -- when --
216
- # TODO: implement execute code
217
- # actual = hoge_core.method1
218
-
219
- # -- then --
220
- # TODO: implement assertion code
221
- # expect(actual).to eq(c[:expected])
222
- ensure
223
- case_after c
224
- end
225
- end
226
-
227
- def case_before(c)
228
- # implement each case before
229
- end
230
-
231
- def case_after(c)
232
- # implement each case after
233
- end
234
- end
235
- end
236
-
237
- context :method2 do
238
- cases = [
239
- {
240
- case_no: 1,
241
- case_title: "case_title",
242
- expected: "expected"
243
- },
244
- ]
245
-
246
- cases.each do |c|
247
- it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
248
- begin
249
- case_before c
250
-
251
- # -- given --
252
- hoge_core = Hoge::Core.new
253
-
254
- # -- when --
255
- # TODO: implement execute code
256
- # actual = hoge_core.method2
257
-
258
- # -- then --
259
- # TODO: implement assertion code
260
- # expect(actual).to eq(c[:expected])
261
- ensure
262
- case_after c
263
- end
264
- end
265
-
266
- def case_before(c)
267
- # implement each case before
268
- end
269
-
270
- def case_after(c)
271
- # implement each case after
272
- end
273
- end
274
- end
275
-
276
- end
277
- EOS
278
-
279
- CASE9_EXPECTED=<<-EOS
280
- # encoding: utf-8
281
- require "spec_helper"
282
- require "some_dir/some_sub_dir/hoge_core"
283
-
284
- describe Hoge::Core do
285
- context :method1 do
286
- cases = [
287
- {
288
- case_no: 1,
289
- case_title: "case_title",
290
- expected: "expected"
291
- },
292
- ]
293
-
294
- cases.each do |c|
295
- it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
296
- begin
297
- case_before c
298
-
299
- # -- given --
300
- hoge_core = Hoge::Core.new
301
-
302
- # -- when --
303
- # TODO: implement execute code
304
- # actual = hoge_core.method1
305
-
306
- # -- then --
307
- # TODO: implement assertion code
308
- # expect(actual).to eq(c[:expected])
309
- ensure
310
- case_after c
311
- end
312
- end
313
-
314
- def case_before(c)
315
- # implement each case before
316
- end
317
-
318
- def case_after(c)
319
- # implement each case after
320
- end
321
- end
322
- end
323
-
324
- context :method2 do
325
- cases = [
326
- {
327
- case_no: 1,
328
- case_title: "case_title",
329
- expected: "expected"
330
- },
331
- ]
332
-
333
- cases.each do |c|
334
- it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
335
- begin
336
- case_before c
337
-
338
- # -- given --
339
- hoge_core = Hoge::Core.new
340
-
341
- # -- when --
342
- # TODO: implement execute code
343
- # actual = hoge_core.method2
344
-
345
- # -- then --
346
- # TODO: implement assertion code
347
- # expect(actual).to eq(c[:expected])
348
- ensure
349
- case_after c
350
- end
351
- end
352
-
353
- def case_before(c)
354
- # implement each case before
355
- end
356
-
357
- def case_after(c)
358
- # implement each case after
359
- end
360
- end
361
- end
362
-
363
- end
364
- EOS
365
-
366
- cases = [
367
- {
368
- case_no: 1,
369
- case_title: "only classname",
370
- class_name: "Hoge::Core",
371
- class_path: "hoge_core",
372
- method_names: nil,
373
- expected_file_name: "./spec/hoge_core_spec.rb",
374
- expected_file_exists: true,
375
- expected_contents: CASE1_EXPECTED
376
- },
377
- {
378
- case_no: 2,
379
- case_title: "classname(with module) and method_names",
380
- class_name: "Hoge::Core",
381
- class_path: "hoge_core",
382
- method_names: ["method1", "method2"],
383
- expected_file_name: "./spec/hoge_core_spec.rb",
384
- expected_file_exists: true,
385
- expected_contents: CASE2_EXPECTED
386
- },
387
- {
388
- case_no: 3,
389
- case_title: "classname(with no module) and method_names",
390
- class_name: "OnlyClass",
391
- class_path: "only_class",
392
- method_names: ["method1", "method2"],
393
- expected_file_name: "./spec/only_class_spec.rb",
394
- expected_file_exists: true,
395
- expected_contents: CASE3_EXPECTED
396
- },
397
- {
398
- case_no: 4,
399
- case_title: "with directory, classname(with module) and method_names",
400
- class_name: "Hoge::Core",
401
- class_path: "some_dir/hoge_core",
402
- del_dir: "some_dir",
403
- method_names: ["method1", "method2"],
404
- expected_file_name: "./spec/some_dir/hoge_core_spec.rb",
405
- expected_file_exists: true,
406
- expected_contents: CASE4_EXPECTED
407
- },
408
- {
409
- case_no: 5,
410
- case_title: "nil_class",
411
- class_name: nil,
412
- class_path: "some_dir/hoge_core",
413
- method_names: ["method1"],
414
- expect_error: true
415
- },
416
- {
417
- case_no: 6,
418
- case_title: "empty_class",
419
- class_name: "",
420
- class_path: "empty_class",
421
- method_names: ["method1"],
422
- expect_error: true
423
- },
424
- {
425
- case_no: 7,
426
- case_title: "nil_class_path",
427
- class_name: "nil_class_path",
428
- class_path: nil,
429
- method_names: ["method1"],
430
- expect_error: true
431
- },
432
- {
433
- case_no: 8,
434
- case_title: "empty_class_path",
435
- class_name: "empty_class_path",
436
- class_path: "",
437
- method_names: ["method1"],
438
- expect_error: true
439
- },
440
- {
441
- case_no: 9,
442
- case_title: "with two directories, classname(with module) and method_names",
443
- class_name: "Hoge::Core",
444
- class_path: "some_dir/some_sub_dir/hoge_core",
445
- del_dir: "some_dir",
446
- method_names: ["method1", "method2"],
447
- expected_file_name: "./spec/some_dir/some_sub_dir/hoge_core_spec.rb",
448
- expected_file_exists: true,
449
- expected_contents: CASE9_EXPECTED
450
- },
451
- ]
452
-
453
- cases.each do |c|
454
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
455
- begin
456
- case_before c
457
-
458
- # -- given --
459
- piccolo = RSpecPiccolo::Core.new
460
-
461
- # -- when --
462
- if c[:expect_error]
463
- lambda {piccolo.generate(c[:class_name], c[:class_path], c[:method_names])}.should raise_error(RSpecPiccolo::RSpecPiccoloError)
464
- # case_after c
465
- next
466
- end
467
- piccolo.generate(c[:class_name], c[:class_path], c[:method_names])
468
-
469
- # -- then --
470
- expect(File.exists?(c[:expected_file_name])).to be_true
471
- actual = File.open(c[:expected_file_name]) {|f|f.read}
472
- expect(actual).to eq(c[:expected_contents])
473
- ensure
474
- case_after c
475
- end
476
- end
477
-
478
- def case_before(c)
479
- # implement each case before
480
- end
481
-
482
- def case_after(c)
483
- # implement each case after
484
- return if c[:expect_error]
485
- File.delete(c[:expected_file_name]) if File.exists?(c[:expected_file_name])
486
- FileUtils.rm_rf("spec/some_dir")
487
- end
488
- end
489
- end
490
- 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
+
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
+ cases = [
508
+ {
509
+ case_no: 1,
510
+ case_title: "only classname",
511
+ class_name: "Hoge::Core",
512
+ class_path: "hoge_core",
513
+ method_names: nil,
514
+ expected_file_name: "./spec/hoge_core_spec.rb",
515
+ expected_file_exists: true,
516
+ expected_contents: CASE1_EXPECTED
517
+ },
518
+ {
519
+ case_no: 2,
520
+ case_title: "classname(with module) and method_names",
521
+ class_name: "Hoge::Core",
522
+ class_path: "hoge_core",
523
+ method_names: ["method1", "method2"],
524
+ expected_file_name: "./spec/hoge_core_spec.rb",
525
+ expected_file_exists: true,
526
+ expected_contents: CASE2_EXPECTED
527
+ },
528
+ {
529
+ case_no: 3,
530
+ case_title: "classname(with no module) and method_names",
531
+ class_name: "OnlyClass",
532
+ class_path: "only_class",
533
+ method_names: ["method1", "method2"],
534
+ expected_file_name: "./spec/only_class_spec.rb",
535
+ expected_file_exists: true,
536
+ expected_contents: CASE3_EXPECTED
537
+ },
538
+ {
539
+ case_no: 4,
540
+ case_title: "with directory, classname(with module) and method_names",
541
+ class_name: "Hoge::Core",
542
+ class_path: "some_dir/hoge_core",
543
+ del_dir: "some_dir",
544
+ method_names: ["method1", "method2"],
545
+ expected_file_name: "./spec/some_dir/hoge_core_spec.rb",
546
+ expected_file_exists: true,
547
+ expected_contents: CASE4_EXPECTED
548
+ },
549
+ {
550
+ case_no: 5,
551
+ case_title: "nil_class",
552
+ class_name: nil,
553
+ class_path: "some_dir/hoge_core",
554
+ method_names: ["method1"],
555
+ expect_error: true
556
+ },
557
+ {
558
+ case_no: 6,
559
+ case_title: "empty_class",
560
+ class_name: "",
561
+ class_path: "empty_class",
562
+ method_names: ["method1"],
563
+ expect_error: true
564
+ },
565
+ {
566
+ case_no: 7,
567
+ case_title: "nil_class_path",
568
+ class_name: "nil_class_path",
569
+ class_path: nil,
570
+ method_names: ["method1"],
571
+ expect_error: true
572
+ },
573
+ {
574
+ case_no: 8,
575
+ case_title: "empty_class_path",
576
+ class_name: "empty_class_path",
577
+ class_path: "",
578
+ method_names: ["method1"],
579
+ expect_error: true
580
+ },
581
+ {
582
+ case_no: 9,
583
+ case_title: "with two directories, classname(with module) and method_names",
584
+ class_name: "Hoge::Core",
585
+ class_path: "some_dir/some_sub_dir/hoge_core",
586
+ del_dir: "some_dir",
587
+ method_names: ["method1", "method2"],
588
+ expected_file_name: "./spec/some_dir/some_sub_dir/hoge_core_spec.rb",
589
+ expected_file_exists: true,
590
+ expected_contents: CASE9_EXPECTED
591
+ },
592
+ {
593
+ case_no: 10,
594
+ case_title: "classname(with module) and method_names",
595
+ class_name: "Hoge::Core",
596
+ class_path: "hoge_core",
597
+ method_names: ["method1", "method2"],
598
+ reportable: true,
599
+ expected_file_name: "./spec/hoge_core_spec.rb",
600
+ expected_file_exists: true,
601
+ expected_contents: CASE10_EXPECTED
602
+ },
603
+ ]
604
+
605
+ cases.each do |c|
606
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
607
+ begin
608
+ case_before c
609
+
610
+ # -- given --
611
+ piccolo = RSpecPiccolo::Core.new
612
+
613
+ # -- when --
614
+ if c[:expect_error]
615
+ lambda {piccolo.generate(c[:class_name], c[:class_path], c[:method_names], c[:reportable])}.should raise_error(RSpecPiccolo::RSpecPiccoloError)
616
+ # case_after c
617
+ next
618
+ end
619
+ piccolo.generate(c[:class_name], c[:class_path], c[:method_names], c[:reportable])
620
+
621
+ # -- then --
622
+ expect(File.exists?(c[:expected_file_name])).to be_true
623
+ actual = File.open(c[:expected_file_name]) {|f|f.read}
624
+ expect(actual).to eq(c[:expected_contents])
625
+ ensure
626
+ case_after c
627
+ end
628
+ end
629
+
630
+ def case_before(c)
631
+ # implement each case before
632
+
633
+ end
634
+
635
+ def case_after(c)
636
+ # implement each case after
637
+ return if c[:expect_error]
638
+ File.delete(c[:expected_file_name]) if File.exists?(c[:expected_file_name])
639
+ FileUtils.rm_rf("spec/some_dir")
640
+ end
641
+ end
642
+ end
643
+ end