rspec_piccolo 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +324 -0
- data/Rakefile +1 -0
- data/bin/piccolo +7 -0
- data/lib/rspec_piccolo.rb +112 -0
- data/lib/rspec_piccolo/version.rb +3 -0
- data/rspec_piccolo.gemspec +27 -0
- data/spec/rspec_piccolo_spec.rb +389 -0
- data/spec/spec_helper.rb +10 -0
- metadata +117 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 tbpgr
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,324 @@
|
|
1
|
+
# RSpecPiccolo
|
2
|
+
|
3
|
+
RSpecPiccolo generate rspec's spec with list-cases for each method.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rspec_piccolo'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rspec_piccolo
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
You have to execute these commands in your project root directory.
|
21
|
+
|
22
|
+
### Case only class_name, class_place
|
23
|
+
~~~
|
24
|
+
piccolo SomeClass some_class_place
|
25
|
+
~~~
|
26
|
+
|
27
|
+
Result, spec/some_class_place
|
28
|
+
~~~
|
29
|
+
# encoding: utf-8
|
30
|
+
require "spec_helper"
|
31
|
+
require "some_class_place"
|
32
|
+
|
33
|
+
describe SomeClass do
|
34
|
+
|
35
|
+
end
|
36
|
+
~~~
|
37
|
+
|
38
|
+
### Case module_name + class_name, directory_name + class_place
|
39
|
+
~~~
|
40
|
+
piccolo SomeModule::SomeClass some_directory/some_class_place
|
41
|
+
~~~
|
42
|
+
|
43
|
+
Result, spec/some_directory/some_class_place
|
44
|
+
~~~
|
45
|
+
# encoding: utf-8
|
46
|
+
require "spec_helper"
|
47
|
+
require "some_directory/some_class_place"
|
48
|
+
|
49
|
+
describe SomeModule::SomeClass do
|
50
|
+
|
51
|
+
end
|
52
|
+
~~~
|
53
|
+
|
54
|
+
### Case class_name, class_place, method_names
|
55
|
+
~~~
|
56
|
+
piccolo SomeClass some_class_place method1 method2
|
57
|
+
~~~
|
58
|
+
|
59
|
+
Result, spec/some_class_place
|
60
|
+
~~~
|
61
|
+
# encoding: utf-8
|
62
|
+
require "spec_helper"
|
63
|
+
require "some_class_place"
|
64
|
+
|
65
|
+
describe SomeClass do
|
66
|
+
context :method1 do
|
67
|
+
cases = [
|
68
|
+
{
|
69
|
+
case_no: 1,
|
70
|
+
case_title: "case_title",
|
71
|
+
expected: "expected"
|
72
|
+
},
|
73
|
+
]
|
74
|
+
|
75
|
+
cases.each do |c|
|
76
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
77
|
+
begin
|
78
|
+
case_before c
|
79
|
+
|
80
|
+
# -- given --
|
81
|
+
some_class = SomeClass.new
|
82
|
+
|
83
|
+
# -- when --
|
84
|
+
# TODO: implement execute code
|
85
|
+
# actual = some_class.method1
|
86
|
+
|
87
|
+
# -- then --
|
88
|
+
# TODO: implement assertion code
|
89
|
+
# expect(actual).to eq(c[:expected])
|
90
|
+
ensure
|
91
|
+
case_after c
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def case_before(c)
|
96
|
+
# implement each case before
|
97
|
+
end
|
98
|
+
|
99
|
+
def case_after(c)
|
100
|
+
# implement each case after
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context :method2 do
|
106
|
+
cases = [
|
107
|
+
{
|
108
|
+
case_no: 1,
|
109
|
+
case_title: "case_title",
|
110
|
+
expected: "expected"
|
111
|
+
},
|
112
|
+
]
|
113
|
+
|
114
|
+
cases.each do |c|
|
115
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
116
|
+
begin
|
117
|
+
case_before c
|
118
|
+
|
119
|
+
# -- given --
|
120
|
+
some_class = SomeClass.new
|
121
|
+
|
122
|
+
# -- when --
|
123
|
+
# TODO: implement execute code
|
124
|
+
# actual = some_class.method2
|
125
|
+
|
126
|
+
# -- then --
|
127
|
+
# TODO: implement assertion code
|
128
|
+
# expect(actual).to eq(c[:expected])
|
129
|
+
ensure
|
130
|
+
case_after c
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def case_before(c)
|
135
|
+
# implement each case before
|
136
|
+
end
|
137
|
+
|
138
|
+
def case_after(c)
|
139
|
+
# implement each case after
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
~~~
|
146
|
+
|
147
|
+
## Pragmatic Usase
|
148
|
+
You can edit your spec template like this sample.
|
149
|
+
|
150
|
+
This sample, you create fizzbuzz application.
|
151
|
+
|
152
|
+
If your product-code is ...
|
153
|
+
|
154
|
+
lib/fizz_buzz.rb
|
155
|
+
~~~
|
156
|
+
# encoding: utf-8
|
157
|
+
|
158
|
+
class FizzBuzz
|
159
|
+
def fizz_buzz(num)
|
160
|
+
ret = []
|
161
|
+
ret << fizz(num)
|
162
|
+
ret << buzz(num)
|
163
|
+
ret.join == "" ? num.to_s : ret.join
|
164
|
+
end
|
165
|
+
|
166
|
+
private
|
167
|
+
def fizz(num)
|
168
|
+
"Fizz" if num % 3 == 0
|
169
|
+
end
|
170
|
+
|
171
|
+
def buzz(num)
|
172
|
+
"Buzz" if num % 5 == 0
|
173
|
+
end
|
174
|
+
end
|
175
|
+
~~~
|
176
|
+
|
177
|
+
you generate rspec template
|
178
|
+
~~~
|
179
|
+
rspec --init
|
180
|
+
~~~
|
181
|
+
|
182
|
+
You generate concrete spec by piccolo.
|
183
|
+
~~~
|
184
|
+
piccolo FizzBuzz fizz_buzz fizz_buzz
|
185
|
+
~~~
|
186
|
+
|
187
|
+
Generated spec is ...
|
188
|
+
|
189
|
+
spec/fizz_buzz_spec.rb
|
190
|
+
~~~
|
191
|
+
# encoding: utf-8
|
192
|
+
require "spec_helper"
|
193
|
+
require "fizz_buzz"
|
194
|
+
|
195
|
+
describe FizzBuzz do
|
196
|
+
context :fizz_buzz do
|
197
|
+
cases = [
|
198
|
+
{
|
199
|
+
case_no: 1,
|
200
|
+
case_title: "case_title",
|
201
|
+
expected: "expected"
|
202
|
+
},
|
203
|
+
]
|
204
|
+
|
205
|
+
cases.each do |c|
|
206
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
207
|
+
begin
|
208
|
+
case_before c
|
209
|
+
|
210
|
+
# -- given --
|
211
|
+
fizz_buzz = FizzBuzz.new
|
212
|
+
|
213
|
+
# -- when --
|
214
|
+
# TODO: implement execute code
|
215
|
+
# actual = fizz_buzz.fizz_buzz
|
216
|
+
|
217
|
+
# -- then --
|
218
|
+
# TODO: implement assertion code
|
219
|
+
# expect(actual).to eq(c[:expected])
|
220
|
+
ensure
|
221
|
+
case_after c
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def case_before(c)
|
226
|
+
# implement each case before
|
227
|
+
end
|
228
|
+
|
229
|
+
def case_after(c)
|
230
|
+
# implement each case after
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
end
|
236
|
+
~~~
|
237
|
+
|
238
|
+
After edit, your spec is like this.
|
239
|
+
|
240
|
+
spec/fizz_buzz_spec.rb
|
241
|
+
~~~
|
242
|
+
# encoding: utf-8
|
243
|
+
require "spec_helper"
|
244
|
+
require "fizz_buzz"
|
245
|
+
|
246
|
+
describe FizzBuzz do
|
247
|
+
context :fizz_buzz do
|
248
|
+
cases = [
|
249
|
+
{
|
250
|
+
case_no: 1,
|
251
|
+
case_title: "fizz",
|
252
|
+
input: 3,
|
253
|
+
expected: "Fizz"
|
254
|
+
},
|
255
|
+
{
|
256
|
+
case_no: 2,
|
257
|
+
case_title: "buzz",
|
258
|
+
input: 5,
|
259
|
+
expected: "Buzz"
|
260
|
+
},
|
261
|
+
{
|
262
|
+
case_no: 3,
|
263
|
+
case_title: "fizzbuzz",
|
264
|
+
input: 15,
|
265
|
+
expected: "FizzBuzz"
|
266
|
+
},
|
267
|
+
{
|
268
|
+
case_no: 4,
|
269
|
+
case_title: "not fizz and buzz",
|
270
|
+
input: 13,
|
271
|
+
expected: "13"
|
272
|
+
},
|
273
|
+
]
|
274
|
+
|
275
|
+
cases.each do |c|
|
276
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
277
|
+
begin
|
278
|
+
# case_before c
|
279
|
+
|
280
|
+
# -- given --
|
281
|
+
fizz_buzz = FizzBuzz.new
|
282
|
+
|
283
|
+
# -- when --
|
284
|
+
actual = fizz_buzz.fizz_buzz c[:input]
|
285
|
+
|
286
|
+
# -- then --
|
287
|
+
expect(actual).to eq(c[:expected])
|
288
|
+
ensure
|
289
|
+
# case_after c
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
def case_before(c)
|
294
|
+
# implement each case before
|
295
|
+
end
|
296
|
+
|
297
|
+
def case_after(c)
|
298
|
+
# implement each case after
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
end
|
304
|
+
~~~
|
305
|
+
|
306
|
+
Test Result
|
307
|
+
~~~
|
308
|
+
$rspec
|
309
|
+
Run options: include {:focus=>true}
|
310
|
+
|
311
|
+
All examples were filtered out; ignoring {:focus=>true}
|
312
|
+
....
|
313
|
+
|
314
|
+
Finished in 0.0045 seconds
|
315
|
+
4 examples, 0 failures
|
316
|
+
~~~
|
317
|
+
|
318
|
+
## Contributing
|
319
|
+
|
320
|
+
1. Fork it
|
321
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
322
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
323
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
324
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/piccolo
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
require "rspec_piccolo/version"
|
2
|
+
require "erb"
|
3
|
+
require 'active_support/inflector'
|
4
|
+
|
5
|
+
module RSpecPiccolo
|
6
|
+
#= RSpecPiccolo Core
|
7
|
+
class Core
|
8
|
+
#== RSPec class template
|
9
|
+
CLASS_TEMPLATE=<<-EOS
|
10
|
+
# encoding: utf-8
|
11
|
+
require "spec_helper"
|
12
|
+
require "<%=class_path%>"
|
13
|
+
|
14
|
+
describe <%=class_name%> do
|
15
|
+
<%=methods_template%>
|
16
|
+
end
|
17
|
+
EOS
|
18
|
+
|
19
|
+
#== RSPec method template
|
20
|
+
METHOD_TEMPLATE=<<-EOS
|
21
|
+
context :<%=method_name%> do
|
22
|
+
cases = [
|
23
|
+
{
|
24
|
+
case_no: 1,
|
25
|
+
case_title: "case_title",
|
26
|
+
expected: "expected"
|
27
|
+
},
|
28
|
+
]
|
29
|
+
|
30
|
+
cases.each do |c|
|
31
|
+
it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
|
32
|
+
begin
|
33
|
+
case_before c
|
34
|
+
|
35
|
+
# -- given --
|
36
|
+
<%=instance_name%> = <%=class_name%>.new
|
37
|
+
|
38
|
+
# -- when --
|
39
|
+
# TODO: implement execute code
|
40
|
+
# actual = <%=instance_name%>.<%=method_name%>
|
41
|
+
|
42
|
+
# -- then --
|
43
|
+
# TODO: implement assertion code
|
44
|
+
# expect(actual).to eq(c[:expected])
|
45
|
+
ensure
|
46
|
+
case_after c
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def case_before(c)
|
51
|
+
# implement each case before
|
52
|
+
end
|
53
|
+
|
54
|
+
def case_after(c)
|
55
|
+
# implement each case after
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
EOS
|
60
|
+
|
61
|
+
#== initialize
|
62
|
+
def initialize
|
63
|
+
@contents = ""
|
64
|
+
end
|
65
|
+
|
66
|
+
#== generate rspec test case
|
67
|
+
#=== params
|
68
|
+
#- class_name: spec's module+class full name
|
69
|
+
#- class_path: spec's class_path(if you want to create spec/hoge_spec.rb, you should set 'hoge_spec.rb')
|
70
|
+
#- method_names: target class's method list
|
71
|
+
def generate(class_name, class_path, method_names)
|
72
|
+
validate_class_name class_name
|
73
|
+
validate_class_path class_path
|
74
|
+
methods_template = generate_method_template(class_name, method_names)
|
75
|
+
@contents = generate_class_template(class_name, class_path, methods_template)
|
76
|
+
create_spec_directory class_path
|
77
|
+
File.open("./spec/#{class_path}_spec.rb", "w") {|f|f.puts @contents}
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
def validate_class_name(class_name)
|
82
|
+
raise RSpecPiccoloError.new("class_name is not allowed nil value") if class_name.nil?
|
83
|
+
raise RSpecPiccoloError.new("class_name is not allowed empty value") if class_name.empty?
|
84
|
+
end
|
85
|
+
|
86
|
+
def validate_class_path(class_path)
|
87
|
+
raise RSpecPiccoloError.new("class_path is not allowed nil value") if class_path.nil?
|
88
|
+
raise RSpecPiccoloError.new("class_path is not allowed empty value") if class_path.empty?
|
89
|
+
end
|
90
|
+
|
91
|
+
def generate_method_template(class_name, method_names)
|
92
|
+
return "" if method_names.nil?
|
93
|
+
instance_name = class_name.gsub('::', '_').underscore.downcase
|
94
|
+
method_templates = []
|
95
|
+
method_names.each do |method_name|
|
96
|
+
method_templates << ERB.new(METHOD_TEMPLATE).result(binding)
|
97
|
+
end
|
98
|
+
method_templates.join("\n")
|
99
|
+
end
|
100
|
+
|
101
|
+
def create_spec_directory(class_path)
|
102
|
+
return if Dir.exists? "./spec/#{File.dirname(class_path)}"
|
103
|
+
Dir.mkdir("./spec/#{File.dirname(class_path)}")
|
104
|
+
end
|
105
|
+
|
106
|
+
def generate_class_template(class_name, class_path, methods_template)
|
107
|
+
ERB.new(CLASS_TEMPLATE).result(binding)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
class RSpecPiccoloError < StandardError;end
|
112
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rspec_piccolo/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rspec_piccolo"
|
8
|
+
spec.version = RspecPiccolo::VERSION
|
9
|
+
spec.authors = ["tbpgr"]
|
10
|
+
spec.email = ["tbpgr@tbpgr.jp"]
|
11
|
+
spec.description = %q{generate rspec spec_file with list_cases}
|
12
|
+
spec.summary = %q{generate rspec spec_file with list_cases}
|
13
|
+
spec.homepage = "https://github.com/tbpgr/rspec_piccolo"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "activesupport", "~> 4.0.1"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec", "~> 2.14.1"
|
26
|
+
spec.add_development_dependency "simplecov", "~> 0.8.2"
|
27
|
+
end
|
@@ -0,0 +1,389 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
require "rspec_piccolo"
|
4
|
+
|
5
|
+
describe RSpecPiccolo::Core do
|
6
|
+
context :generate do
|
7
|
+
CASE1_EXPECTED=<<-EOS
|
8
|
+
# encoding: utf-8
|
9
|
+
require "spec_helper"
|
10
|
+
require "hoge_core"
|
11
|
+
|
12
|
+
describe Hoge::Core do
|
13
|
+
|
14
|
+
end
|
15
|
+
EOS
|
16
|
+
|
17
|
+
CASE2_EXPECTED=<<-EOS
|
18
|
+
# encoding: utf-8
|
19
|
+
require "spec_helper"
|
20
|
+
require "hoge_core"
|
21
|
+
|
22
|
+
describe Hoge::Core do
|
23
|
+
context :method1 do
|
24
|
+
cases = [
|
25
|
+
{
|
26
|
+
case_no: 1,
|
27
|
+
case_title: "case_title",
|
28
|
+
expected: "expected"
|
29
|
+
},
|
30
|
+
]
|
31
|
+
|
32
|
+
cases.each do |c|
|
33
|
+
it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
|
34
|
+
begin
|
35
|
+
case_before c
|
36
|
+
|
37
|
+
# -- given --
|
38
|
+
hoge_core = Hoge::Core.new
|
39
|
+
|
40
|
+
# -- when --
|
41
|
+
# TODO: implement execute code
|
42
|
+
# actual = hoge_core.method1
|
43
|
+
|
44
|
+
# -- then --
|
45
|
+
# TODO: implement assertion code
|
46
|
+
# expect(actual).to eq(c[:expected])
|
47
|
+
ensure
|
48
|
+
case_after c
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def case_before(c)
|
53
|
+
# implement each case before
|
54
|
+
end
|
55
|
+
|
56
|
+
def case_after(c)
|
57
|
+
# implement each case after
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context :method2 do
|
63
|
+
cases = [
|
64
|
+
{
|
65
|
+
case_no: 1,
|
66
|
+
case_title: "case_title",
|
67
|
+
expected: "expected"
|
68
|
+
},
|
69
|
+
]
|
70
|
+
|
71
|
+
cases.each do |c|
|
72
|
+
it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
|
73
|
+
begin
|
74
|
+
case_before c
|
75
|
+
|
76
|
+
# -- given --
|
77
|
+
hoge_core = Hoge::Core.new
|
78
|
+
|
79
|
+
# -- when --
|
80
|
+
# TODO: implement execute code
|
81
|
+
# actual = hoge_core.method2
|
82
|
+
|
83
|
+
# -- then --
|
84
|
+
# TODO: implement assertion code
|
85
|
+
# expect(actual).to eq(c[:expected])
|
86
|
+
ensure
|
87
|
+
case_after c
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def case_before(c)
|
92
|
+
# implement each case before
|
93
|
+
end
|
94
|
+
|
95
|
+
def case_after(c)
|
96
|
+
# implement each case after
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
EOS
|
103
|
+
|
104
|
+
CASE3_EXPECTED=<<-EOS
|
105
|
+
# encoding: utf-8
|
106
|
+
require "spec_helper"
|
107
|
+
require "only_class"
|
108
|
+
|
109
|
+
describe OnlyClass do
|
110
|
+
context :method1 do
|
111
|
+
cases = [
|
112
|
+
{
|
113
|
+
case_no: 1,
|
114
|
+
case_title: "case_title",
|
115
|
+
expected: "expected"
|
116
|
+
},
|
117
|
+
]
|
118
|
+
|
119
|
+
cases.each do |c|
|
120
|
+
it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
|
121
|
+
begin
|
122
|
+
case_before c
|
123
|
+
|
124
|
+
# -- given --
|
125
|
+
only_class = OnlyClass.new
|
126
|
+
|
127
|
+
# -- when --
|
128
|
+
# TODO: implement execute code
|
129
|
+
# actual = only_class.method1
|
130
|
+
|
131
|
+
# -- then --
|
132
|
+
# TODO: implement assertion code
|
133
|
+
# expect(actual).to eq(c[:expected])
|
134
|
+
ensure
|
135
|
+
case_after c
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def case_before(c)
|
140
|
+
# implement each case before
|
141
|
+
end
|
142
|
+
|
143
|
+
def case_after(c)
|
144
|
+
# implement each case after
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context :method2 do
|
150
|
+
cases = [
|
151
|
+
{
|
152
|
+
case_no: 1,
|
153
|
+
case_title: "case_title",
|
154
|
+
expected: "expected"
|
155
|
+
},
|
156
|
+
]
|
157
|
+
|
158
|
+
cases.each do |c|
|
159
|
+
it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
|
160
|
+
begin
|
161
|
+
case_before c
|
162
|
+
|
163
|
+
# -- given --
|
164
|
+
only_class = OnlyClass.new
|
165
|
+
|
166
|
+
# -- when --
|
167
|
+
# TODO: implement execute code
|
168
|
+
# actual = only_class.method2
|
169
|
+
|
170
|
+
# -- then --
|
171
|
+
# TODO: implement assertion code
|
172
|
+
# expect(actual).to eq(c[:expected])
|
173
|
+
ensure
|
174
|
+
case_after c
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def case_before(c)
|
179
|
+
# implement each case before
|
180
|
+
end
|
181
|
+
|
182
|
+
def case_after(c)
|
183
|
+
# implement each case after
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
EOS
|
190
|
+
|
191
|
+
CASE4_EXPECTED=<<-EOS
|
192
|
+
# encoding: utf-8
|
193
|
+
require "spec_helper"
|
194
|
+
require "some_dir/hoge_core"
|
195
|
+
|
196
|
+
describe Hoge::Core do
|
197
|
+
context :method1 do
|
198
|
+
cases = [
|
199
|
+
{
|
200
|
+
case_no: 1,
|
201
|
+
case_title: "case_title",
|
202
|
+
expected: "expected"
|
203
|
+
},
|
204
|
+
]
|
205
|
+
|
206
|
+
cases.each do |c|
|
207
|
+
it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
|
208
|
+
begin
|
209
|
+
case_before c
|
210
|
+
|
211
|
+
# -- given --
|
212
|
+
hoge_core = Hoge::Core.new
|
213
|
+
|
214
|
+
# -- when --
|
215
|
+
# TODO: implement execute code
|
216
|
+
# actual = hoge_core.method1
|
217
|
+
|
218
|
+
# -- then --
|
219
|
+
# TODO: implement assertion code
|
220
|
+
# expect(actual).to eq(c[:expected])
|
221
|
+
ensure
|
222
|
+
case_after c
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
def case_before(c)
|
227
|
+
# implement each case before
|
228
|
+
end
|
229
|
+
|
230
|
+
def case_after(c)
|
231
|
+
# implement each case after
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
context :method2 do
|
237
|
+
cases = [
|
238
|
+
{
|
239
|
+
case_no: 1,
|
240
|
+
case_title: "case_title",
|
241
|
+
expected: "expected"
|
242
|
+
},
|
243
|
+
]
|
244
|
+
|
245
|
+
cases.each do |c|
|
246
|
+
it "|case_no=\#{c[:case_no]}|case_title=\#{c[:case_title]}" do
|
247
|
+
begin
|
248
|
+
case_before c
|
249
|
+
|
250
|
+
# -- given --
|
251
|
+
hoge_core = Hoge::Core.new
|
252
|
+
|
253
|
+
# -- when --
|
254
|
+
# TODO: implement execute code
|
255
|
+
# actual = hoge_core.method2
|
256
|
+
|
257
|
+
# -- then --
|
258
|
+
# TODO: implement assertion code
|
259
|
+
# expect(actual).to eq(c[:expected])
|
260
|
+
ensure
|
261
|
+
case_after c
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
def case_before(c)
|
266
|
+
# implement each case before
|
267
|
+
end
|
268
|
+
|
269
|
+
def case_after(c)
|
270
|
+
# implement each case after
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
end
|
276
|
+
EOS
|
277
|
+
|
278
|
+
cases = [
|
279
|
+
{
|
280
|
+
case_no: 1,
|
281
|
+
case_title: "only classname",
|
282
|
+
class_name: "Hoge::Core",
|
283
|
+
class_path: "hoge_core",
|
284
|
+
method_names: nil,
|
285
|
+
expected_file_name: "./spec/hoge_core_spec.rb",
|
286
|
+
expected_file_exists: true,
|
287
|
+
expected_contents: CASE1_EXPECTED
|
288
|
+
},
|
289
|
+
{
|
290
|
+
case_no: 2,
|
291
|
+
case_title: "classname(with module) and method_names",
|
292
|
+
class_name: "Hoge::Core",
|
293
|
+
class_path: "hoge_core",
|
294
|
+
method_names: ["method1", "method2"],
|
295
|
+
expected_file_name: "./spec/hoge_core_spec.rb",
|
296
|
+
expected_file_exists: true,
|
297
|
+
expected_contents: CASE2_EXPECTED
|
298
|
+
},
|
299
|
+
{
|
300
|
+
case_no: 3,
|
301
|
+
case_title: "classname(with no module) and method_names",
|
302
|
+
class_name: "OnlyClass",
|
303
|
+
class_path: "only_class",
|
304
|
+
method_names: ["method1", "method2"],
|
305
|
+
expected_file_name: "./spec/only_class_spec.rb",
|
306
|
+
expected_file_exists: true,
|
307
|
+
expected_contents: CASE3_EXPECTED
|
308
|
+
},
|
309
|
+
{
|
310
|
+
case_no: 4,
|
311
|
+
case_title: "with directory, classname(with module) and method_names",
|
312
|
+
class_name: "Hoge::Core",
|
313
|
+
class_path: "some_dir/hoge_core",
|
314
|
+
method_names: ["method1", "method2"],
|
315
|
+
expected_file_name: "./spec/some_dir/hoge_core_spec.rb",
|
316
|
+
expected_file_exists: true,
|
317
|
+
expected_contents: CASE4_EXPECTED
|
318
|
+
},
|
319
|
+
{
|
320
|
+
case_no: 5,
|
321
|
+
case_title: "nil_class",
|
322
|
+
class_name: nil,
|
323
|
+
class_path: "some_dir/hoge_core",
|
324
|
+
method_names: ["method1"],
|
325
|
+
expect_error: true
|
326
|
+
},
|
327
|
+
{
|
328
|
+
case_no: 6,
|
329
|
+
case_title: "empty_class",
|
330
|
+
class_name: "",
|
331
|
+
class_path: "empty_class",
|
332
|
+
method_names: ["method1"],
|
333
|
+
expect_error: true
|
334
|
+
},
|
335
|
+
{
|
336
|
+
case_no: 7,
|
337
|
+
case_title: "nil_class_path",
|
338
|
+
class_name: "nil_class_path",
|
339
|
+
class_path: nil,
|
340
|
+
method_names: ["method1"],
|
341
|
+
expect_error: true
|
342
|
+
},
|
343
|
+
{
|
344
|
+
case_no: 8,
|
345
|
+
case_title: "empty_class_path",
|
346
|
+
class_name: "empty_class_path",
|
347
|
+
class_path: "",
|
348
|
+
method_names: ["method1"],
|
349
|
+
expect_error: true
|
350
|
+
},
|
351
|
+
]
|
352
|
+
|
353
|
+
cases.each do |c|
|
354
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
355
|
+
begin
|
356
|
+
case_before c
|
357
|
+
|
358
|
+
# -- given --
|
359
|
+
piccolo = RSpecPiccolo::Core.new
|
360
|
+
|
361
|
+
# -- when --
|
362
|
+
if c[:expect_error]
|
363
|
+
lambda {piccolo.generate(c[:class_name], c[:class_path], c[:method_names])}.should raise_error(RSpecPiccolo::RSpecPiccoloError)
|
364
|
+
# case_after c
|
365
|
+
next
|
366
|
+
end
|
367
|
+
piccolo.generate(c[:class_name], c[:class_path], c[:method_names])
|
368
|
+
|
369
|
+
# -- then --
|
370
|
+
expect(File.exists?(c[:expected_file_name])).to be_true
|
371
|
+
actual = File.open(c[:expected_file_name]) {|f|f.read}
|
372
|
+
expect(actual).to eq(c[:expected_contents])
|
373
|
+
ensure
|
374
|
+
case_after c
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
def case_before(c)
|
379
|
+
# implement each case before
|
380
|
+
end
|
381
|
+
|
382
|
+
def case_after(c)
|
383
|
+
# implement each case after
|
384
|
+
return if c[:expect_error]
|
385
|
+
File.delete(c[:expected_file_name]) if File.exists?(c[:expected_file_name])
|
386
|
+
end
|
387
|
+
end
|
388
|
+
end
|
389
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec_piccolo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- tbpgr
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: &29224284 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 4.0.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *29224284
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: bundler
|
27
|
+
requirement: &29223984 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.3'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *29223984
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
requirement: &29223756 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *29223756
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: &29223432 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.14.1
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *29223432
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: simplecov
|
60
|
+
requirement: &29223132 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 0.8.2
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *29223132
|
69
|
+
description: generate rspec spec_file with list_cases
|
70
|
+
email:
|
71
|
+
- tbpgr@tbpgr.jp
|
72
|
+
executables:
|
73
|
+
- piccolo
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- .rspec
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/piccolo
|
84
|
+
- lib/rspec_piccolo.rb
|
85
|
+
- lib/rspec_piccolo/version.rb
|
86
|
+
- rspec_piccolo.gemspec
|
87
|
+
- spec/rspec_piccolo_spec.rb
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
homepage: https://github.com/tbpgr/rspec_piccolo
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 1.8.11
|
111
|
+
signing_key:
|
112
|
+
specification_version: 3
|
113
|
+
summary: generate rspec spec_file with list_cases
|
114
|
+
test_files:
|
115
|
+
- spec/rspec_piccolo_spec.rb
|
116
|
+
- spec/spec_helper.rb
|
117
|
+
has_rdoc:
|