rspec_piccolo 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +121 -19
- data/lib/rspec_piccolo.rb +9 -2
- data/lib/rspec_piccolo/version.rb +1 -1
- data/spec/rspec_piccolo_spec.rb +104 -0
- metadata +14 -14
data/README.md
CHANGED
@@ -20,12 +20,12 @@ Or install it yourself as:
|
|
20
20
|
You have to execute these commands in your project root directory.
|
21
21
|
|
22
22
|
### Case only class_name, class_place
|
23
|
-
~~~
|
23
|
+
~~~bash
|
24
24
|
piccolo execute SomeClass some_class_place
|
25
25
|
~~~
|
26
26
|
|
27
27
|
Result, spec/some_class_place
|
28
|
-
~~~
|
28
|
+
~~~ruby
|
29
29
|
# encoding: utf-8
|
30
30
|
require "spec_helper"
|
31
31
|
require "some_class_place"
|
@@ -36,12 +36,12 @@ end
|
|
36
36
|
~~~
|
37
37
|
|
38
38
|
### Case module_name + class_name, directory_name + class_place
|
39
|
-
~~~
|
39
|
+
~~~bash
|
40
40
|
piccolo execute SomeModule::SomeClass some_directory/some_class_place
|
41
41
|
~~~
|
42
42
|
|
43
43
|
Result, spec/some_directory/some_class_place
|
44
|
-
~~~
|
44
|
+
~~~ruby
|
45
45
|
# encoding: utf-8
|
46
46
|
require "spec_helper"
|
47
47
|
require "some_directory/some_class_place"
|
@@ -52,12 +52,12 @@ end
|
|
52
52
|
~~~
|
53
53
|
|
54
54
|
### Case class_name, class_place, method_names
|
55
|
-
~~~
|
55
|
+
~~~bash
|
56
56
|
piccolo execute SomeClass some_class_place method1 method2
|
57
57
|
~~~
|
58
58
|
|
59
59
|
Result, spec/some_class_place
|
60
|
-
~~~
|
60
|
+
~~~ruby
|
61
61
|
# encoding: utf-8
|
62
62
|
require "spec_helper"
|
63
63
|
require "some_class_place"
|
@@ -144,15 +144,116 @@ describe SomeClass do
|
|
144
144
|
end
|
145
145
|
~~~
|
146
146
|
|
147
|
+
### Case class_name, class_place, instance_method_name and class_method_name
|
148
|
+
~~~bash
|
149
|
+
piccolo execute SomeClass some_class_place instance_method class_method@c
|
150
|
+
~~~
|
151
|
+
|
152
|
+
Result, spec/some_class_place
|
153
|
+
~~~ruby
|
154
|
+
$ cat spec/some_class_place_spec.rb
|
155
|
+
# encoding: utf-8
|
156
|
+
require "spec_helper"
|
157
|
+
require "some_class_place"
|
158
|
+
|
159
|
+
describe SomeClass do
|
160
|
+
|
161
|
+
context :instance_method do
|
162
|
+
cases = [
|
163
|
+
{
|
164
|
+
case_no: 1,
|
165
|
+
case_title: "case_title",
|
166
|
+
expected: "expected",
|
167
|
+
|
168
|
+
},
|
169
|
+
]
|
170
|
+
|
171
|
+
cases.each do |c|
|
172
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
173
|
+
begin
|
174
|
+
case_before c
|
175
|
+
|
176
|
+
# -- given --
|
177
|
+
some_class = SomeClass.new
|
178
|
+
|
179
|
+
# -- when --
|
180
|
+
# TODO: implement execute code
|
181
|
+
# actual = some_class.instance_method
|
182
|
+
|
183
|
+
# -- then --
|
184
|
+
# TODO: implement assertion code
|
185
|
+
# ret = expect(actual).to eq(c[:expected])
|
186
|
+
ensure
|
187
|
+
case_after c
|
188
|
+
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def case_before(c)
|
193
|
+
# implement each case before
|
194
|
+
|
195
|
+
end
|
196
|
+
|
197
|
+
def case_after(c)
|
198
|
+
# implement each case after
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
context :class_method do
|
204
|
+
cases = [
|
205
|
+
{
|
206
|
+
case_no: 1,
|
207
|
+
case_title: "case_title",
|
208
|
+
expected: "expected",
|
209
|
+
|
210
|
+
},
|
211
|
+
]
|
212
|
+
|
213
|
+
cases.each do |c|
|
214
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
215
|
+
begin
|
216
|
+
case_before c
|
217
|
+
|
218
|
+
# -- given --
|
219
|
+
# nothing
|
220
|
+
|
221
|
+
# -- when --
|
222
|
+
# TODO: implement execute code
|
223
|
+
# actual = SomeClass.class_method
|
224
|
+
|
225
|
+
# -- then --
|
226
|
+
# TODO: implement assertion code
|
227
|
+
# ret = expect(actual).to eq(c[:expected])
|
228
|
+
ensure
|
229
|
+
case_after c
|
230
|
+
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
def case_before(c)
|
235
|
+
# implement each case before
|
236
|
+
|
237
|
+
end
|
238
|
+
|
239
|
+
def case_after(c)
|
240
|
+
# implement each case after
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
end
|
246
|
+
~~~
|
247
|
+
|
147
248
|
### Case class_name, class_place, method_names with report
|
148
249
|
you can output report by -r(reportable) option.
|
149
250
|
|
150
|
-
~~~
|
251
|
+
~~~bash
|
151
252
|
piccolo execute Hoge hoge/hige/hoge hoge hige -r
|
152
253
|
~~~
|
153
254
|
|
154
255
|
product code
|
155
|
-
~~~
|
256
|
+
~~~ruby
|
156
257
|
# encoding: utf-8
|
157
258
|
|
158
259
|
class Hoge
|
@@ -167,7 +268,7 @@ end
|
|
167
268
|
~~~
|
168
269
|
|
169
270
|
Result, spec/hoge/hige/hoge_spec.rb
|
170
|
-
~~~
|
271
|
+
~~~ruby
|
171
272
|
# encoding: utf-8
|
172
273
|
require "spec_helper"
|
173
274
|
require "hoge/hige/hoge"
|
@@ -280,7 +381,7 @@ end
|
|
280
381
|
~~~
|
281
382
|
|
282
383
|
Edit manually, spec/hoge/hige/hoge_spec.rb
|
283
|
-
~~~
|
384
|
+
~~~ruby
|
284
385
|
# encoding: utf-8
|
285
386
|
require "spec_helper"
|
286
387
|
require "hoge/hige/hoge"
|
@@ -403,7 +504,7 @@ end
|
|
403
504
|
~~~
|
404
505
|
|
405
506
|
Execute rspec command.
|
406
|
-
~~~
|
507
|
+
~~~bash
|
407
508
|
$rspec
|
408
509
|
Run options: include {:focus=>true}
|
409
510
|
|
@@ -440,8 +541,8 @@ rspec ./spec/hoge/hige/hoge_spec.rb:89 # Hoge hige |case_no=2|case_title=invalid
|
|
440
541
|
~~~
|
441
542
|
|
442
543
|
you get tsv report.
|
443
|
-
~~~
|
444
|
-
tree
|
544
|
+
~~~bash
|
545
|
+
$ tree
|
445
546
|
┠ lib
|
446
547
|
┃┗ hoge
|
447
548
|
┃ ┗ hige
|
@@ -472,7 +573,7 @@ This sample, you create fizzbuzz application.
|
|
472
573
|
If your product-code is ...
|
473
574
|
|
474
575
|
lib/fizz_buzz.rb
|
475
|
-
~~~
|
576
|
+
~~~ruby
|
476
577
|
# encoding: utf-8
|
477
578
|
|
478
579
|
class FizzBuzz
|
@@ -495,19 +596,19 @@ end
|
|
495
596
|
~~~
|
496
597
|
|
497
598
|
you generate rspec template
|
498
|
-
~~~
|
599
|
+
~~~bash
|
499
600
|
rspec --init
|
500
601
|
~~~
|
501
602
|
|
502
603
|
You generate concrete spec by piccolo.
|
503
|
-
~~~
|
604
|
+
~~~bash
|
504
605
|
piccolo execute FizzBuzz fizz_buzz fizz_buzz
|
505
606
|
~~~
|
506
607
|
|
507
608
|
Generated spec is ...
|
508
609
|
|
509
610
|
spec/fizz_buzz_spec.rb
|
510
|
-
~~~
|
611
|
+
~~~ruby
|
511
612
|
# encoding: utf-8
|
512
613
|
require "spec_helper"
|
513
614
|
require "fizz_buzz"
|
@@ -558,7 +659,7 @@ end
|
|
558
659
|
After edit, your spec is like this.
|
559
660
|
|
560
661
|
spec/fizz_buzz_spec.rb
|
561
|
-
~~~
|
662
|
+
~~~ruby
|
562
663
|
# encoding: utf-8
|
563
664
|
require "spec_helper"
|
564
665
|
require "fizz_buzz"
|
@@ -624,7 +725,7 @@ end
|
|
624
725
|
~~~
|
625
726
|
|
626
727
|
Test Result
|
627
|
-
~~~
|
728
|
+
~~~bash
|
628
729
|
$rspec
|
629
730
|
Run options: include {:focus=>true}
|
630
731
|
|
@@ -636,6 +737,7 @@ Finished in 0.0045 seconds
|
|
636
737
|
~~~
|
637
738
|
|
638
739
|
## History
|
740
|
+
* version 0.0.6 : add class method generation.
|
639
741
|
* version 0.0.5 : add reportable option.
|
640
742
|
* version 0.0.4 : you can get multi level directory spec case.
|
641
743
|
* version 0.0.2 : fix bin.(use thor).
|
data/lib/rspec_piccolo.rb
CHANGED
@@ -53,11 +53,11 @@ end
|
|
53
53
|
case_before c
|
54
54
|
|
55
55
|
# -- given --
|
56
|
-
<%=
|
56
|
+
<%=given_src%>
|
57
57
|
|
58
58
|
# -- when --
|
59
59
|
# TODO: implement execute code
|
60
|
-
|
60
|
+
<%=when_src%>
|
61
61
|
|
62
62
|
# -- then --
|
63
63
|
# TODO: implement assertion code
|
@@ -79,6 +79,8 @@ end
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
EOS
|
82
|
+
# <%=given_src%>
|
83
|
+
# <%=when_src%>
|
82
84
|
|
83
85
|
REPORTABLE_CASE =<<-EOS
|
84
86
|
success_hook: success,
|
@@ -124,10 +126,15 @@ EOS
|
|
124
126
|
|
125
127
|
def generate_method_template(class_name, method_names, reportable)
|
126
128
|
return "" if method_names.nil?
|
129
|
+
|
127
130
|
reportable_case = reportable ? REPORTABLE_CASE.chop : ""
|
128
131
|
instance_name = class_name.gsub('::', '_').underscore.downcase
|
129
132
|
method_templates = []
|
130
133
|
method_names.each do |method_name|
|
134
|
+
is_class_method = (method_name.match(/@c$/) ? true : false)
|
135
|
+
method_name = method_name.gsub("@c", "") if is_class_method
|
136
|
+
given_src = is_class_method ? "# nothing" : "#{instance_name} = #{class_name}.new"
|
137
|
+
when_src = is_class_method ? "# actual = #{class_name}.#{method_name}" : "# actual = #{instance_name}.#{method_name}"
|
131
138
|
reportable_case_before = reportable ? REPORTABLE_CASE_BEFORE.dup : ""
|
132
139
|
reportable_case_before.gsub!("method_name", method_name)
|
133
140
|
reportable_case_after = reportable ? REPORTABLE_CASE_AFTER.dup.chop : ""
|
data/spec/rspec_piccolo_spec.rb
CHANGED
@@ -501,6 +501,100 @@ describe Hoge::Core do
|
|
501
501
|
end
|
502
502
|
end
|
503
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
|
+
|
504
598
|
end
|
505
599
|
EOS
|
506
600
|
|
@@ -600,6 +694,16 @@ EOS
|
|
600
694
|
expected_file_exists: true,
|
601
695
|
expected_contents: CASE10_EXPECTED
|
602
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
|
+
},
|
603
707
|
]
|
604
708
|
|
605
709
|
cases.each do |c|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec_piccolo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-12-
|
12
|
+
date: 2013-12-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &21257544 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 4.0.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *21257544
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: thor
|
27
|
-
requirement: &
|
27
|
+
requirement: &21257112 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.18.1
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *21257112
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &21256728 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '1.3'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *21256728
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rake
|
49
|
-
requirement: &
|
49
|
+
requirement: &21255900 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *21255900
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rspec
|
60
|
-
requirement: &
|
60
|
+
requirement: &21253164 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 2.14.1
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *21253164
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: simplecov
|
71
|
-
requirement: &
|
71
|
+
requirement: &21252156 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: 0.8.2
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *21252156
|
80
80
|
description: generate rspec spec_file with list_cases
|
81
81
|
email:
|
82
82
|
- tbpgr@tbpgr.jp
|