rspec_piccolo 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -1
- data/README.md +34 -2
- data/lib/rspec_piccolo.rb +42 -5
- data/lib/rspec_piccolo/version.rb +1 -1
- data/rspec_piccolo.gemspec +1 -0
- data/spec/rspec_piccolo_spec.rb +37 -2
- metadata +25 -14
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -159,11 +159,39 @@ Result, lib/some_class_place.rb
|
|
159
159
|
|
160
160
|
class SomeClass
|
161
161
|
def method1
|
162
|
-
#
|
162
|
+
# TODO: implement your code
|
163
163
|
end
|
164
164
|
|
165
165
|
def method2
|
166
|
-
#
|
166
|
+
# TODO: implement your code
|
167
|
+
end
|
168
|
+
end
|
169
|
+
~~~
|
170
|
+
|
171
|
+
### Case class_name, class_place, method_names, fields with product code
|
172
|
+
~~~bash
|
173
|
+
piccolo execute SomeClass some_class_place method1 method2 field1@f field2@f -p
|
174
|
+
~~~
|
175
|
+
|
176
|
+
Result, spec/some_class_place_spec.rb
|
177
|
+
~~~ruby
|
178
|
+
# omission
|
179
|
+
~~~
|
180
|
+
|
181
|
+
Result, lib/some_class_place.rb
|
182
|
+
~~~ruby
|
183
|
+
# encoding: utf-8
|
184
|
+
require 'attributes_initializable'
|
185
|
+
class SomeClass
|
186
|
+
include AttributesInitializable
|
187
|
+
attr_accessor_init :field1, :field2
|
188
|
+
|
189
|
+
def method1
|
190
|
+
# TODO: implement your code
|
191
|
+
end
|
192
|
+
|
193
|
+
def method2
|
194
|
+
# TODO: implement your code
|
167
195
|
end
|
168
196
|
end
|
169
197
|
~~~
|
@@ -750,7 +778,11 @@ Finished in 0.0045 seconds
|
|
750
778
|
4 examples, 0 failures
|
751
779
|
~~~
|
752
780
|
|
781
|
+
## Notice
|
782
|
+
* if you want to use field generation, you have to install 'tbpgr_utils' gem (ver >= 0.0.4).
|
783
|
+
|
753
784
|
## History
|
785
|
+
* version 0.0.8 : add field generation to product code.(using tbpgr_utils gem)
|
754
786
|
* version 0.0.7 : add product code generation option .delete unuse empty-line, unuse ret variable.
|
755
787
|
* version 0.0.6 : add class method generation.
|
756
788
|
* version 0.0.5 : add reportable option.
|
data/lib/rspec_piccolo.rb
CHANGED
@@ -98,10 +98,10 @@ EOS
|
|
98
98
|
|
99
99
|
PRODUCT_CLASS_TEMPLATE = <<-EOS
|
100
100
|
# encoding: utf-8
|
101
|
-
|
101
|
+
<%=require_rb%>
|
102
102
|
<%=module_start%>
|
103
103
|
<%=module_indent%>class <%=class_name%>
|
104
|
-
<%=methods_template%>
|
104
|
+
<%=fields%><%=methods_template%>
|
105
105
|
<%=module_indent%>end
|
106
106
|
<%=module_end%>
|
107
107
|
EOS
|
@@ -144,6 +144,7 @@ EOS
|
|
144
144
|
instance_name = class_name.gsub('::', '_').underscore.downcase
|
145
145
|
method_templates = []
|
146
146
|
method_names.each do |method_name|
|
147
|
+
next if is_field?(method_name)
|
147
148
|
is_class_method = is_class_method?(method_name)
|
148
149
|
method_name = method_name.gsub('@c', '') if is_class_method
|
149
150
|
given_src = is_class_method ? '# nothing' : "#{instance_name} = #{class_name}.new"
|
@@ -173,10 +174,22 @@ EOS
|
|
173
174
|
|
174
175
|
def output_product_code(class_name, class_path, method_names)
|
175
176
|
has_module = has_module? class_name
|
177
|
+
has_field = has_field?(method_names)
|
176
178
|
module_indent = has_module ? ' ' : ''
|
179
|
+
require_rb = has_field ? "require 'attributes_initializable'" : ''
|
177
180
|
module_name, class_name = get_module_class_names class_name, has_module
|
181
|
+
fields = get_fields(method_names, module_indent)
|
178
182
|
methods_template = generate_product_method_template(method_names, module_indent)
|
179
|
-
contents = generate_product_class_template(
|
183
|
+
contents = generate_product_class_template(
|
184
|
+
module_name,
|
185
|
+
class_name,
|
186
|
+
class_path,
|
187
|
+
methods_template.chop,
|
188
|
+
module_indent,
|
189
|
+
has_module,
|
190
|
+
require_rb,
|
191
|
+
fields
|
192
|
+
)
|
180
193
|
create_lib_directory(class_path)
|
181
194
|
File.open("./lib/#{class_path}.rb", 'w:UTF-8') { |f|f.puts contents }
|
182
195
|
end
|
@@ -199,9 +212,10 @@ EOS
|
|
199
212
|
def generate_product_method_template(method_names, module_indent)
|
200
213
|
method_code = []
|
201
214
|
method_names.each do |method_name|
|
215
|
+
next if is_field? method_name
|
202
216
|
method_name = "self.#{method_name.gsub('@c', '')}" if is_class_method?(method_name)
|
203
217
|
method_code << "#{module_indent} def #{method_name}"
|
204
|
-
method_code << "#{module_indent} #
|
218
|
+
method_code << "#{module_indent} # TODO: implement your code"
|
205
219
|
method_code << "#{module_indent} end"
|
206
220
|
method_code << ""
|
207
221
|
end
|
@@ -212,7 +226,18 @@ EOS
|
|
212
226
|
method_name.match(/@c$/) ? true : false
|
213
227
|
end
|
214
228
|
|
215
|
-
def
|
229
|
+
def is_field?(method_name)
|
230
|
+
method_name.match(/@f$/) ? true : false
|
231
|
+
end
|
232
|
+
|
233
|
+
def has_field?(method_names)
|
234
|
+
method_names.each do |method_name|
|
235
|
+
return true if is_field?(method_name)
|
236
|
+
end
|
237
|
+
false
|
238
|
+
end
|
239
|
+
|
240
|
+
def generate_product_class_template(module_name, class_name, class_path, methods_template, module_indent, has_module, require_rb, fields)
|
216
241
|
module_start = ""
|
217
242
|
module_end = ""
|
218
243
|
if has_module
|
@@ -221,6 +246,18 @@ EOS
|
|
221
246
|
end
|
222
247
|
ERB.new(PRODUCT_CLASS_TEMPLATE).result(binding)
|
223
248
|
end
|
249
|
+
|
250
|
+
def get_fields(method_names, module_indent)
|
251
|
+
return '' unless has_field?(method_names)
|
252
|
+
ret = []
|
253
|
+
ret << "#{module_indent} include AttributesInitializable\n"
|
254
|
+
ret << "#{module_indent} attr_accessor_init "
|
255
|
+
method_names.each do |method_name|
|
256
|
+
next unless is_field?(method_name)
|
257
|
+
ret << ":#{method_name.gsub(/@f/, '')}, "
|
258
|
+
end
|
259
|
+
"#{ret.join.chop.chop}\n\n"
|
260
|
+
end
|
224
261
|
end
|
225
262
|
|
226
263
|
class RSpecPiccoloError < StandardError; end
|
data/rspec_piccolo.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_runtime_dependency "activesupport", "~> 4.0.1"
|
22
22
|
spec.add_runtime_dependency "thor", "~> 0.18.1"
|
23
|
+
spec.add_runtime_dependency "tbpgr_utils", "~> 0.0.4"
|
23
24
|
|
24
25
|
spec.add_development_dependency "bundler", "~> 1.3"
|
25
26
|
spec.add_development_dependency "rake"
|
data/spec/rspec_piccolo_spec.rb
CHANGED
@@ -656,11 +656,32 @@ EOS
|
|
656
656
|
module Hoge
|
657
657
|
class Core
|
658
658
|
def method1
|
659
|
-
#
|
659
|
+
# TODO: implement your code
|
660
660
|
end
|
661
661
|
|
662
662
|
def self.method2
|
663
|
-
#
|
663
|
+
# TODO: implement your code
|
664
|
+
end
|
665
|
+
end
|
666
|
+
end
|
667
|
+
EOS
|
668
|
+
|
669
|
+
CASE13_EXPECTED = CASE12_EXPECTED
|
670
|
+
|
671
|
+
CASE13_PRODUCT_EXPECTED = <<-EOS
|
672
|
+
# encoding: utf-8
|
673
|
+
require 'attributes_initializable'
|
674
|
+
module Hoge
|
675
|
+
class Core
|
676
|
+
include AttributesInitializable
|
677
|
+
attr_accessor_init :field1, :field2
|
678
|
+
|
679
|
+
def method1
|
680
|
+
# TODO: implement your code
|
681
|
+
end
|
682
|
+
|
683
|
+
def self.method2
|
684
|
+
# TODO: implement your code
|
664
685
|
end
|
665
686
|
end
|
666
687
|
end
|
@@ -786,6 +807,20 @@ end
|
|
786
807
|
expected_contents: CASE12_EXPECTED,
|
787
808
|
expected_product_contents: CASE12_PRODUCT_EXPECTED
|
788
809
|
},
|
810
|
+
{
|
811
|
+
case_no: 13,
|
812
|
+
case_title: 'classname(with module) and method_names(instance method, class method, field1, field2) and product code output',
|
813
|
+
class_name: 'Hoge::Core',
|
814
|
+
class_path: 'some_dir/hoge_core',
|
815
|
+
method_names: ['method1', 'method2@c', 'field1@f', 'field2@f'],
|
816
|
+
productcode: true,
|
817
|
+
expected_file_name: './spec/some_dir/hoge_core_spec.rb',
|
818
|
+
expected_file_exists: true,
|
819
|
+
expected_product_file_name: './lib/some_dir/hoge_core.rb',
|
820
|
+
expected_product_file_exists: true,
|
821
|
+
expected_contents: CASE13_EXPECTED,
|
822
|
+
expected_product_contents: CASE13_PRODUCT_EXPECTED
|
823
|
+
},
|
789
824
|
]
|
790
825
|
|
791
826
|
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.8
|
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: 2014-01-
|
12
|
+
date: 2014-01-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &27874380 !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: *27874380
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: thor
|
27
|
-
requirement: &
|
27
|
+
requirement: &27873912 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,21 @@ dependencies:
|
|
32
32
|
version: 0.18.1
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *27873912
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: tbpgr_utils
|
38
|
+
requirement: &27873528 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.0.4
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *27873528
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: bundler
|
38
|
-
requirement: &
|
49
|
+
requirement: &27873252 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ~>
|
@@ -43,10 +54,10 @@ dependencies:
|
|
43
54
|
version: '1.3'
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *27873252
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: rake
|
49
|
-
requirement: &
|
60
|
+
requirement: &27873024 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ! '>='
|
@@ -54,10 +65,10 @@ dependencies:
|
|
54
65
|
version: '0'
|
55
66
|
type: :development
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *27873024
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: rspec
|
60
|
-
requirement: &
|
71
|
+
requirement: &27872676 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - ~>
|
@@ -65,10 +76,10 @@ dependencies:
|
|
65
76
|
version: 2.14.1
|
66
77
|
type: :development
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
79
|
+
version_requirements: *27872676
|
69
80
|
- !ruby/object:Gem::Dependency
|
70
81
|
name: simplecov
|
71
|
-
requirement: &
|
82
|
+
requirement: &27872340 !ruby/object:Gem::Requirement
|
72
83
|
none: false
|
73
84
|
requirements:
|
74
85
|
- - ~>
|
@@ -76,7 +87,7 @@ dependencies:
|
|
76
87
|
version: 0.8.2
|
77
88
|
type: :development
|
78
89
|
prerelease: false
|
79
|
-
version_requirements: *
|
90
|
+
version_requirements: *27872340
|
80
91
|
description: generate rspec spec_file with list_cases
|
81
92
|
email:
|
82
93
|
- tbpgr@tbpgr.jp
|