rspec-kickstarter 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/rspec_kickstarter/erb_factory.rb +56 -36
- data/lib/rspec_kickstarter/erb_templates.rb +12 -10
- data/lib/rspec_kickstarter/generator.rb +199 -188
- data/lib/rspec_kickstarter/rdoc_factory.rb +48 -49
- data/lib/rspec_kickstarter/version.rb +1 -1
- metadata +8 -10
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e5d045881beb098d19cfda3528d04fdaa3a7a6b5
|
4
|
+
data.tar.gz: c1a4537221a91990859ed92626e802af007e0a1d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cd77ed24e38edfa7a7c3952b8176a330ae28f61ca7f48bc4f1f4ef46d8107ecf82b358406fbd00cedf9da67aa37419a02388470378eb4afc45711271b2191910
|
7
|
+
data.tar.gz: b03fb18db2fe869cc5265884bd142f93d33de9a1a4a8b96cfcea3d3838b56adf9ae330c1e0ec1310620785ed6a718492d8facd1a886a208436025ffb1ae7d771
|
@@ -7,49 +7,69 @@ require 'rspec_kickstarter/erb_templates'
|
|
7
7
|
#
|
8
8
|
# ERB instance provider
|
9
9
|
#
|
10
|
-
|
10
|
+
module RSpecKickstarter
|
11
|
+
class ERBFactory
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
def initialize(custom_template)
|
14
|
+
@custom_template = custom_template
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
#
|
18
|
+
# Returns ERB instance for creating new spec
|
19
|
+
#
|
20
|
+
def get_instance_for_new_spec(rails_mode, target_path)
|
21
|
+
template = get_erb_template(@custom_template, true, rails_mode, target_path)
|
22
|
+
ERB.new(template, nil, '-', '_new_spec_code')
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
#
|
26
|
+
# Returns ERB instance for appeding lacking tests
|
27
|
+
#
|
28
|
+
def get_instance_for_appending(rails_mode, target_path)
|
29
|
+
template = get_erb_template(@custom_template, false, rails_mode, target_path)
|
30
|
+
ERB.new(template, nil, '-', '_additional_spec_code')
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
#
|
36
|
+
# Returns ERB template
|
37
|
+
#
|
38
|
+
def get_erb_template(custom_template, is_full, rails_mode, target_path)
|
39
|
+
if custom_template
|
40
|
+
custom_template
|
41
|
+
elsif rails_mode && target_path.match(/controllers/)
|
42
|
+
get_rails_controller_template(is_full)
|
43
|
+
elsif rails_mode && target_path.match(/helpers/)
|
44
|
+
get_rails_helper_template(is_full)
|
45
|
+
else
|
46
|
+
get_basic_template(is_full)
|
47
|
+
end
|
48
|
+
end
|
31
49
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
def get_erb_template(custom_template, is_full, rails_mode, target_path)
|
38
|
-
if custom_template
|
39
|
-
custom_template
|
40
|
-
elsif rails_mode && target_path.match(/controllers/)
|
41
|
-
if is_full then RSpecKickstarter::ERBTemplates::RAILS_CONTROLLER_NEW_SPEC_TEMPLATE
|
42
|
-
else RSpecKickstarter::ERBTemplates::RAILS_CONTROLLER_METHODS_PART_TEMPLATE
|
50
|
+
def get_rails_controller_template(is_full)
|
51
|
+
if is_full
|
52
|
+
RSpecKickstarter::ERBTemplates::RAILS_CONTROLLER_NEW_SPEC_TEMPLATE
|
53
|
+
else
|
54
|
+
RSpecKickstarter::ERBTemplates::RAILS_CONTROLLER_METHODS_PART_TEMPLATE
|
43
55
|
end
|
44
|
-
|
45
|
-
|
46
|
-
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_rails_helper_template(is_full)
|
59
|
+
if is_full
|
60
|
+
RSpecKickstarter::ERBTemplates::RAILS_HELPER_NEW_SPEC_TEMPLATE
|
61
|
+
else
|
62
|
+
RSpecKickstarter::ERBTemplates::RAILS_HELPER_METHODS_PART_TEMPLATE
|
47
63
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
64
|
+
end
|
65
|
+
|
66
|
+
def get_basic_template(is_full)
|
67
|
+
if is_full
|
68
|
+
RSpecKickstarter::ERBTemplates::BASIC_NEW_SPEC_TEMPLATE
|
69
|
+
else
|
70
|
+
RSpecKickstarter::ERBTemplates::BASIC_METHODS_PART_TEMPLATE
|
51
71
|
end
|
52
72
|
end
|
53
|
-
end
|
54
73
|
|
74
|
+
end
|
55
75
|
end
|
@@ -6,11 +6,12 @@ require 'rspec_kickstarter'
|
|
6
6
|
#
|
7
7
|
# ERB templates
|
8
8
|
#
|
9
|
-
module RSpecKickstarter
|
9
|
+
module RSpecKickstarter
|
10
|
+
module ERBTemplates
|
10
11
|
|
11
|
-
|
12
|
+
BASIC_METHODS_PART_TEMPLATE = <<SPEC
|
12
13
|
<%- methods_to_generate.map { |method| %>
|
13
|
-
# TODO auto-generated
|
14
|
+
# TODO: auto-generated
|
14
15
|
describe '#<%= method.name %>' do
|
15
16
|
it 'works' do
|
16
17
|
<%- unless get_instantiation_code(c, method).nil? -%><%= get_instantiation_code(c, method) %><%- end -%>
|
@@ -22,7 +23,7 @@ module RSpecKickstarter::ERBTemplates
|
|
22
23
|
<% } %>
|
23
24
|
SPEC
|
24
25
|
|
25
|
-
|
26
|
+
BASIC_NEW_SPEC_TEMPLATE = <<SPEC
|
26
27
|
# -*- encoding: utf-8 -*-
|
27
28
|
|
28
29
|
require 'spec_helper'
|
@@ -34,9 +35,9 @@ describe <%= get_complete_class_name(c) %> do
|
|
34
35
|
end
|
35
36
|
SPEC
|
36
37
|
|
37
|
-
|
38
|
+
RAILS_CONTROLLER_METHODS_PART_TEMPLATE = <<SPEC
|
38
39
|
<%- methods_to_generate.map { |method| %>
|
39
|
-
# TODO auto-generated
|
40
|
+
# TODO: auto-generated
|
40
41
|
describe '<%= get_rails_http_method(method.name).upcase %> <%= method.name %>' do
|
41
42
|
it 'works' do
|
42
43
|
<%= get_rails_http_method(method.name) %> :<%= method.name %>, {}, {}
|
@@ -46,7 +47,7 @@ SPEC
|
|
46
47
|
<% } %>
|
47
48
|
SPEC
|
48
49
|
|
49
|
-
|
50
|
+
RAILS_CONTROLLER_NEW_SPEC_TEMPLATE = <<SPEC
|
50
51
|
# -*- encoding: utf-8 -*-
|
51
52
|
|
52
53
|
require 'spec_helper'
|
@@ -56,9 +57,9 @@ describe <%= get_complete_class_name(c) %> do
|
|
56
57
|
end
|
57
58
|
SPEC
|
58
59
|
|
59
|
-
|
60
|
+
RAILS_HELPER_METHODS_PART_TEMPLATE = <<SPEC
|
60
61
|
<%- methods_to_generate.map { |method| %>
|
61
|
-
# TODO auto-generated
|
62
|
+
# TODO: auto-generated
|
62
63
|
describe '#<%= method.name %>' do
|
63
64
|
it 'works' do
|
64
65
|
result = <%= get_rails_helper_method_invocation_code(method) %>
|
@@ -68,7 +69,7 @@ SPEC
|
|
68
69
|
<% } %>
|
69
70
|
SPEC
|
70
71
|
|
71
|
-
|
72
|
+
RAILS_HELPER_NEW_SPEC_TEMPLATE = <<SPEC
|
72
73
|
# -*- encoding: utf-8 -*-
|
73
74
|
|
74
75
|
require 'spec_helper'
|
@@ -78,4 +79,5 @@ describe <%= get_complete_class_name(c) %> do
|
|
78
79
|
end
|
79
80
|
SPEC
|
80
81
|
|
82
|
+
end
|
81
83
|
end
|
@@ -9,230 +9,241 @@ require 'rspec_kickstarter/rdoc_factory'
|
|
9
9
|
#
|
10
10
|
# RSpec Code Generator
|
11
11
|
#
|
12
|
-
|
13
|
-
|
12
|
+
module RSpecKickstarter
|
13
|
+
class Generator
|
14
|
+
include RSpecKickstarter::ERBTemplates
|
14
15
|
|
15
|
-
|
16
|
+
attr_accessor :spec_dir, :delta_template, :full_template
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
def initialize(spec_dir = './spec', delta_template = nil, full_template = nil)
|
19
|
+
@spec_dir = spec_dir.gsub(/\/$/, '')
|
20
|
+
@delta_template = delta_template
|
21
|
+
@full_template = full_template
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
#
|
25
|
+
# Writes new spec or appends to the existing spec.
|
26
|
+
#
|
27
|
+
def write_spec(file_path, force_write = false, dry_run = false, rails_mode = false)
|
28
|
+
class_or_module = RSpecKickstarter::RDocFactory.get_rdoc_class_or_module(file_path)
|
29
|
+
if class_or_module
|
30
|
+
spec_path = get_spec_path(file_path)
|
31
|
+
if force_write && File.exist?(spec_path)
|
32
|
+
append_to_existing_spec(class_or_module, dry_run, rails_mode, spec_path)
|
33
|
+
else
|
34
|
+
create_new_spec(class_or_module, dry_run, rails_mode, file_path, spec_path)
|
35
|
+
end
|
32
36
|
else
|
33
|
-
|
37
|
+
puts "#{file_path} skipped (Class/Module not found)."
|
34
38
|
end
|
35
|
-
else
|
36
|
-
puts "#{file_path} skipped (Class/Module not found)."
|
37
39
|
end
|
38
|
-
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
41
|
+
#
|
42
|
+
# Gets the complete class name from RDoc::NormalClass/RDoc::NormalModule instance.
|
43
|
+
#
|
44
|
+
def get_complete_class_name(class_or_module, name = class_or_module.name)
|
45
|
+
if !class_or_module.parent.name.nil? && class_or_module.parent.is_a?(RDoc::NormalModule)
|
46
|
+
get_complete_class_name(class_or_module.parent, "#{class_or_module.parent.name}::#{name}")
|
47
|
+
else
|
48
|
+
name
|
49
|
+
end
|
48
50
|
end
|
49
|
-
end
|
50
|
-
|
51
|
-
#
|
52
|
-
# Returns spec file path.
|
53
|
-
# e.g. "lib/foo/bar_baz.rb" -> "spec/foo/bar_baz_spec.rb"
|
54
|
-
#
|
55
|
-
def get_spec_path(file_path)
|
56
|
-
spec_dir + '/' + file_path.gsub(/^\.\//, '').gsub(%r{^(lib/)|(app/)}, '').gsub(/\.rb$/, '_spec.rb')
|
57
|
-
end
|
58
51
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
52
|
+
#
|
53
|
+
# Returns spec file path.
|
54
|
+
# e.g. "lib/foo/bar_baz.rb" -> "spec/foo/bar_baz_spec.rb"
|
55
|
+
#
|
56
|
+
def get_spec_path(file_path)
|
57
|
+
spec_dir + '/' + file_path.gsub(/^\.\//, '').gsub(%r{^(lib/)|(app/)}, '').gsub(/\.rb$/, '_spec.rb')
|
58
|
+
end
|
66
59
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
75
|
-
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
76
|
-
.tr('-', '_')
|
77
|
-
.downcase
|
78
|
-
end
|
60
|
+
#
|
61
|
+
# Returns string value to require.
|
62
|
+
# e.g. "lib/foo/bar_baz.rb" -> "foo/bar_baz"
|
63
|
+
#
|
64
|
+
def to_string_value_to_require(file_path)
|
65
|
+
file_path.gsub(%r{^(lib/)|(app/)}, '').gsub(/\.rb$/, '')
|
66
|
+
end
|
79
67
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
68
|
+
#
|
69
|
+
# Returns snake_case name.
|
70
|
+
# e.g. FooBar -> "foo_bar"
|
71
|
+
#
|
72
|
+
def instance_name(c)
|
73
|
+
c.name.
|
74
|
+
gsub(/::/, '/').
|
75
|
+
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
|
76
|
+
gsub(/([a-z\d])([A-Z])/, '\1_\2').
|
77
|
+
tr('-', '_').
|
78
|
+
downcase
|
79
|
+
end
|
88
80
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
end
|
81
|
+
#
|
82
|
+
# Extracts parameter names as an *Array*.
|
83
|
+
# e.g. "()" -> []
|
84
|
+
# e.g. "(a, b = 'foo')" -> ["a", "b"]
|
85
|
+
#
|
86
|
+
def to_param_names_array(params)
|
87
|
+
params.split(',').map { |p| p.gsub(/[\(\)\s]/, '').gsub(/=.+$/, '') }.reject { |p| p.nil? || p.empty? }
|
88
|
+
end
|
98
89
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
self_path = to_string_value_to_require(file_path)
|
108
|
-
|
109
|
-
erb = RSpecKickstarter::ERBFactory.new(@full_template).get_instance_for_new_spec(rails_mode, file_path)
|
110
|
-
code = erb.result(binding)
|
111
|
-
|
112
|
-
if dry_run
|
113
|
-
puts "----- #{spec_path} -----"
|
114
|
-
puts code
|
115
|
-
else
|
116
|
-
if File.exist?(spec_path)
|
117
|
-
puts "#{spec_path} already exists."
|
118
|
-
else
|
119
|
-
FileUtils.mkdir_p(File.dirname(spec_path))
|
120
|
-
File.open(spec_path, 'w') { |f| f.write(code) }
|
121
|
-
puts "#{spec_path} created."
|
122
|
-
end
|
90
|
+
#
|
91
|
+
# Returns params part
|
92
|
+
# e.g. ["a","b"] -> "(a, b)"
|
93
|
+
# e.g. [] -> ""
|
94
|
+
#
|
95
|
+
def to_params_part(params)
|
96
|
+
param_csv = to_param_names_array(params).join(', ')
|
97
|
+
param_csv.empty? ? '' : "(#{param_csv})"
|
123
98
|
end
|
124
|
-
end
|
125
99
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
lacking_methods = class_or_module.method_list
|
132
|
-
.select { |m| m.visibility == :public }
|
133
|
-
.reject { |m| existing_spec.match(m.name) }
|
134
|
-
|
135
|
-
if lacking_methods.empty?
|
136
|
-
puts "#{spec_path} skipped."
|
137
|
-
else
|
100
|
+
#
|
101
|
+
# Creates new spec.
|
102
|
+
#
|
103
|
+
# rubocop:disable Metrics/AbcSize
|
104
|
+
def create_new_spec(class_or_module, dry_run, rails_mode, file_path, spec_path)
|
138
105
|
# These names are used in ERB template, don't delete.
|
139
|
-
|
106
|
+
# rubocop:disable Lint/UselessAssignment
|
107
|
+
methods_to_generate = class_or_module.method_list.select { |m| m.visibility == :public }
|
140
108
|
c = class_or_module
|
109
|
+
self_path = to_string_value_to_require(file_path)
|
110
|
+
# rubocop:enable Lint/UselessAssignment
|
141
111
|
|
142
|
-
erb = RSpecKickstarter::ERBFactory.new(@
|
143
|
-
|
144
|
-
|
145
|
-
last_end_not_found = true
|
146
|
-
code = existing_spec.split("\n").reverse.reject { |line|
|
147
|
-
before_modified = last_end_not_found
|
148
|
-
last_end_not_found = line.gsub(/#.+$/, '').strip != 'end' if before_modified
|
149
|
-
before_modified
|
150
|
-
}.reverse.join("\n") + "\n" + additional_spec + "\nend\n"
|
112
|
+
erb = RSpecKickstarter::ERBFactory.new(@full_template).get_instance_for_new_spec(rails_mode, file_path)
|
113
|
+
code = erb.result(binding)
|
151
114
|
|
152
115
|
if dry_run
|
153
116
|
puts "----- #{spec_path} -----"
|
154
117
|
puts code
|
155
118
|
else
|
156
|
-
File.
|
119
|
+
if File.exist?(spec_path)
|
120
|
+
puts "#{spec_path} already exists."
|
121
|
+
else
|
122
|
+
FileUtils.mkdir_p(File.dirname(spec_path))
|
123
|
+
File.open(spec_path, 'w') { |f| f.write(code) }
|
124
|
+
puts "#{spec_path} created."
|
125
|
+
end
|
157
126
|
end
|
158
|
-
puts "#{spec_path} modified."
|
159
127
|
end
|
160
|
-
end
|
161
128
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
constructor = c.method_list.find { |m| m.name == 'new' }
|
177
|
-
if constructor.nil?
|
178
|
-
" #{instance_name(c)} = #{get_complete_class_name(c)}.new\n"
|
129
|
+
# rubocop:enable Metrics/AbcSize
|
130
|
+
|
131
|
+
#
|
132
|
+
# Appends new tests to the existing spec.
|
133
|
+
#
|
134
|
+
# rubocop:disable Metrics/AbcSize
|
135
|
+
def append_to_existing_spec(class_or_module, dry_run, rails_mode, spec_path)
|
136
|
+
existing_spec = File.read(spec_path)
|
137
|
+
lacking_methods = class_or_module.method_list.
|
138
|
+
select { |m| m.visibility == :public }.
|
139
|
+
reject { |m| existing_spec.match(m.name) }
|
140
|
+
|
141
|
+
if lacking_methods.empty?
|
142
|
+
puts "#{spec_path} skipped."
|
179
143
|
else
|
180
|
-
|
181
|
-
|
144
|
+
# These names are used in ERB template, don't delete.
|
145
|
+
# rubocop:disable Lint/UselessAssignment
|
146
|
+
methods_to_generate = lacking_methods
|
147
|
+
c = class_or_module
|
148
|
+
# rubocop:enable Lint/UselessAssignment
|
149
|
+
|
150
|
+
erb = RSpecKickstarter::ERBFactory.new(@delta_template).get_instance_for_appending(rails_mode, spec_path)
|
151
|
+
additional_spec = erb.result(binding)
|
152
|
+
|
153
|
+
last_end_not_found = true
|
154
|
+
code = existing_spec.split("\n").reverse.reject { |line|
|
155
|
+
before_modified = last_end_not_found
|
156
|
+
last_end_not_found = line.gsub(/#.+$/, '').strip != 'end' if before_modified
|
157
|
+
before_modified
|
158
|
+
}.reverse.join("\n") + "\n" + additional_spec + "\nend\n"
|
159
|
+
|
160
|
+
if dry_run
|
161
|
+
puts "----- #{spec_path} -----"
|
162
|
+
puts code
|
163
|
+
else
|
164
|
+
File.open(spec_path, 'w') { |f| f.write(code) }
|
165
|
+
end
|
166
|
+
puts "#{spec_path} modified."
|
182
167
|
end
|
183
168
|
end
|
184
|
-
end
|
185
169
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
170
|
+
# rubocop:enable Metrics/AbcSize
|
171
|
+
|
172
|
+
# -----
|
173
|
+
# Code generation
|
174
|
+
# -----
|
175
|
+
|
176
|
+
#
|
177
|
+
# e.g.
|
178
|
+
# a = double('a')
|
179
|
+
# b = double('b')
|
180
|
+
# bar_baz = BarBaz.new(a, b)
|
181
|
+
#
|
182
|
+
def get_instantiation_code(c, method)
|
183
|
+
if method.singleton
|
184
|
+
''
|
185
|
+
else
|
186
|
+
constructor = c.method_list.find { |m| m.name == 'new' }
|
187
|
+
if constructor.nil?
|
188
|
+
" #{instance_name(c)} = #{get_complete_class_name(c)}.new\n"
|
189
|
+
else
|
190
|
+
get_params_initialization_code(constructor) +
|
191
|
+
" #{instance_name(c)} = #{get_complete_class_name(c)}.new#{to_params_part(constructor.params)}\n"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
195
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
196
|
+
#
|
197
|
+
# e.g.
|
198
|
+
# a = double('a')
|
199
|
+
# b = double('b')
|
200
|
+
#
|
201
|
+
def get_params_initialization_code(method)
|
202
|
+
code = to_param_names_array(method.params).map { |p| " #{p} = double('#{p}')" }.join("\n")
|
203
|
+
code.empty? ? '' : "#{code}\n"
|
204
|
+
end
|
203
205
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
206
|
+
#
|
207
|
+
# e.g. BarBaz.do_something(a, b) { |c| }
|
208
|
+
#
|
209
|
+
def get_method_invocation_code(c, method)
|
210
|
+
target = method.singleton ? get_complete_class_name(c) : instance_name(c)
|
211
|
+
"#{target}.#{method.name}#{to_params_part(method.params)}#{get_block_code(method)}"
|
212
|
+
end
|
210
213
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
''
|
217
|
-
else
|
218
|
-
" { |#{method.block_params}| }"
|
214
|
+
#
|
215
|
+
# e.g. do_something(a, b) { |c| }
|
216
|
+
#
|
217
|
+
def get_rails_helper_method_invocation_code(method)
|
218
|
+
"#{method.name}#{to_params_part(method.params)}#{get_block_code(method)}"
|
219
219
|
end
|
220
|
-
end
|
221
220
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
221
|
+
#
|
222
|
+
# e.g. { |a, b| }
|
223
|
+
#
|
224
|
+
def get_block_code(method)
|
225
|
+
if method.block_params.nil? || method.block_params.empty?
|
226
|
+
''
|
227
|
+
else
|
228
|
+
" { |#{method.block_params}| }"
|
229
|
+
end
|
230
|
+
end
|
226
231
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
'show' => 'get',
|
232
|
-
'edit' => 'get',
|
233
|
-
'update' => 'put',
|
234
|
-
'destroy' => 'delete'
|
235
|
-
}
|
232
|
+
def get_rails_http_method(method_name)
|
233
|
+
http_method = RAILS_RESOURCE_METHOD_AND_HTTP_METHOD[method_name]
|
234
|
+
http_method.nil? ? 'get' : http_method
|
235
|
+
end
|
236
236
|
|
237
|
+
RAILS_RESOURCE_METHOD_AND_HTTP_METHOD = {
|
238
|
+
'index' => 'get',
|
239
|
+
'new' => 'get',
|
240
|
+
'create' => 'post',
|
241
|
+
'show' => 'get',
|
242
|
+
'edit' => 'get',
|
243
|
+
'update' => 'put',
|
244
|
+
'destroy' => 'delete'
|
245
|
+
}
|
246
|
+
|
247
|
+
end
|
237
248
|
end
|
238
249
|
|
@@ -5,68 +5,67 @@ require 'rdoc/generator'
|
|
5
5
|
require 'rdoc/options'
|
6
6
|
require 'rdoc/parser/ruby'
|
7
7
|
require 'rdoc/stats'
|
8
|
-
|
9
8
|
require 'rspec_kickstarter'
|
10
9
|
|
11
10
|
#
|
12
11
|
# RDoc instance factory
|
13
12
|
#
|
14
|
-
|
13
|
+
module RSpecKickstarter
|
14
|
+
class RDocFactory
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
#
|
17
|
+
# Returns RDoc::NormalClass/RDoc::NormalModule instance.
|
18
|
+
#
|
19
|
+
def self.get_rdoc_class_or_module(file_path)
|
20
|
+
top_level = get_ruby_parser(file_path).scan
|
21
|
+
extract_target_class_or_module(top_level)
|
22
|
+
end
|
23
23
|
|
24
|
-
|
24
|
+
#
|
25
|
+
# Creates new RDoc::Parser::Ruby instance.
|
26
|
+
#
|
27
|
+
def self.get_ruby_parser(file_path)
|
28
|
+
top_level = RDoc::TopLevel.new(file_path)
|
29
|
+
if RUBY_VERSION.to_f < 2.0
|
30
|
+
# reset is removed since 2.0
|
31
|
+
RDoc::TopLevel.reset
|
32
|
+
end
|
25
33
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
# RDoc::Stats initialization
|
35
|
+
if defined?(RDoc::Store)
|
36
|
+
# RDoc 4.0.0 requires RDoc::Store internally.
|
37
|
+
store = RDoc::Store.new
|
38
|
+
top_level.store = store
|
39
|
+
stats = RDoc::Stats.new(store, 1)
|
40
|
+
else
|
41
|
+
stats = RDoc::Stats.new(1)
|
42
|
+
end
|
35
43
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
stats = RDoc::Stats.new(1)
|
44
|
+
RDoc::Parser::Ruby.new(
|
45
|
+
top_level,
|
46
|
+
file_path,
|
47
|
+
File.read(file_path),
|
48
|
+
RDoc::Options.new,
|
49
|
+
stats
|
50
|
+
)
|
44
51
|
end
|
45
52
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
def self.extract_target_class_or_module(top_level)
|
59
|
-
c = top_level.classes.first
|
60
|
-
if c.nil?
|
61
|
-
m = top_level.modules.first
|
62
|
-
if m.nil?
|
63
|
-
top_level.is_a?(RDoc::NormalModule) ? top_level : nil
|
53
|
+
#
|
54
|
+
# Extracts RDoc::NormalClass/RDoc::NormalModule from RDoc::TopLevel.
|
55
|
+
#
|
56
|
+
def self.extract_target_class_or_module(top_level)
|
57
|
+
c = top_level.classes.first
|
58
|
+
if c.nil?
|
59
|
+
m = top_level.modules.first
|
60
|
+
if m.nil?
|
61
|
+
top_level.is_a?(RDoc::NormalModule) ? top_level : nil
|
62
|
+
else
|
63
|
+
extract_target_class_or_module(m)
|
64
|
+
end
|
64
65
|
else
|
65
|
-
|
66
|
+
c
|
66
67
|
end
|
67
|
-
else
|
68
|
-
c
|
69
68
|
end
|
70
|
-
end
|
71
69
|
|
70
|
+
end
|
72
71
|
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-kickstarter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Kazuhiro Sera
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-12-20 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: rspec-kickstarter supports you writing tests for existing code.
|
15
14
|
email:
|
@@ -20,35 +19,34 @@ extensions: []
|
|
20
19
|
extra_rdoc_files: []
|
21
20
|
files:
|
22
21
|
- bin/rspec-kickstarter
|
22
|
+
- lib/rspec_kickstarter.rb
|
23
23
|
- lib/rspec_kickstarter/erb_factory.rb
|
24
24
|
- lib/rspec_kickstarter/erb_templates.rb
|
25
25
|
- lib/rspec_kickstarter/generator.rb
|
26
26
|
- lib/rspec_kickstarter/rdoc_factory.rb
|
27
27
|
- lib/rspec_kickstarter/version.rb
|
28
|
-
- lib/rspec_kickstarter.rb
|
29
28
|
homepage: https://github.com/seratch/rspec-kickstarter
|
30
29
|
licenses:
|
31
30
|
- MIT
|
31
|
+
metadata: {}
|
32
32
|
post_install_message:
|
33
33
|
rdoc_options: []
|
34
34
|
require_paths:
|
35
35
|
- lib
|
36
36
|
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
-
none: false
|
38
37
|
requirements:
|
39
|
-
- -
|
38
|
+
- - ">="
|
40
39
|
- !ruby/object:Gem::Version
|
41
40
|
version: '0'
|
42
41
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
-
none: false
|
44
42
|
requirements:
|
45
|
-
- -
|
43
|
+
- - ">="
|
46
44
|
- !ruby/object:Gem::Version
|
47
45
|
version: '0'
|
48
46
|
requirements: []
|
49
47
|
rubyforge_project:
|
50
|
-
rubygems_version:
|
48
|
+
rubygems_version: 2.2.2
|
51
49
|
signing_key:
|
52
|
-
specification_version:
|
50
|
+
specification_version: 4
|
53
51
|
summary: rspec-kickstarter supports you writing tests for existing code.
|
54
52
|
test_files: []
|