rspec-jumpstart 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/rspec_jumpstart/erb_factory.rb +12 -12
- data/lib/rspec_jumpstart/erb_templates.rb +87 -87
- data/lib/rspec_jumpstart/generator.rb +25 -22
- data/lib/rspec_jumpstart/rdoc_factory.rb +10 -21
- data/lib/rspec_jumpstart/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9e7fb2e27a41e53c53c809f0197079445c9dfe9c196810b11f927026fa29859e
|
4
|
+
data.tar.gz: 732a6779e43ea5cac52e7eef8737ae3f762f981784451c2c56ef4b2574c10234
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f6c2dfcaaae8f7be36c90af2f6635887ebd0ef04c259b74762681a83a96513430b4d11b3fb339d5dcc0f0d5716c65a5b12fa7e7bbb423a8a2df3efb1738cc3b
|
7
|
+
data.tar.gz: 1f37d5201e46346d07417857a5d18271e600e156fd3c760825b9480fcaa2438ccbbb6b5ee1c783264bc60823b1ba8f8a604c714e4f06e384cef1e5e4cd67fd4b
|
@@ -51,34 +51,34 @@ module RSpecJumpstart
|
|
51
51
|
|
52
52
|
def get_rails_controller_template(is_full)
|
53
53
|
if is_full
|
54
|
-
RSpecJumpstart::ERBTemplates::RAILS_CONTROLLER_NEW_SPEC_TEMPLATE
|
55
|
-
else
|
56
|
-
RSpecJumpstart::ERBTemplates::RAILS_CONTROLLER_METHODS_PART_TEMPLATE
|
54
|
+
return RSpecJumpstart::ERBTemplates::RAILS_CONTROLLER_NEW_SPEC_TEMPLATE
|
57
55
|
end
|
56
|
+
|
57
|
+
RSpecJumpstart::ERBTemplates::RAILS_CONTROLLER_METHODS_PART_TEMPLATE
|
58
58
|
end
|
59
59
|
|
60
60
|
def get_rails_model_template(is_full)
|
61
61
|
if is_full
|
62
|
-
RSpecJumpstart::ERBTemplates::RAILS_MODEL_NEW_SPEC_TEMPLATE
|
63
|
-
else
|
64
|
-
RSpecJumpstart::ERBTemplates::RAILS_MODEL_METHODS_PART_TEMPLATE
|
62
|
+
return RSpecJumpstart::ERBTemplates::RAILS_MODEL_NEW_SPEC_TEMPLATE
|
65
63
|
end
|
64
|
+
|
65
|
+
RSpecJumpstart::ERBTemplates::RAILS_MODEL_METHODS_PART_TEMPLATE
|
66
66
|
end
|
67
67
|
|
68
68
|
def get_rails_helper_template(is_full)
|
69
69
|
if is_full
|
70
|
-
RSpecJumpstart::ERBTemplates::RAILS_HELPER_NEW_SPEC_TEMPLATE
|
71
|
-
else
|
72
|
-
RSpecJumpstart::ERBTemplates::RAILS_HELPER_METHODS_PART_TEMPLATE
|
70
|
+
return RSpecJumpstart::ERBTemplates::RAILS_HELPER_NEW_SPEC_TEMPLATE
|
73
71
|
end
|
72
|
+
|
73
|
+
RSpecJumpstart::ERBTemplates::RAILS_HELPER_METHODS_PART_TEMPLATE
|
74
74
|
end
|
75
75
|
|
76
76
|
def get_basic_template(is_full)
|
77
77
|
if is_full
|
78
|
-
RSpecJumpstart::ERBTemplates::BASIC_NEW_SPEC_TEMPLATE
|
79
|
-
else
|
80
|
-
RSpecJumpstart::ERBTemplates::BASIC_METHODS_PART_TEMPLATE
|
78
|
+
return RSpecJumpstart::ERBTemplates::BASIC_NEW_SPEC_TEMPLATE
|
81
79
|
end
|
80
|
+
|
81
|
+
RSpecJumpstart::ERBTemplates::BASIC_METHODS_PART_TEMPLATE
|
82
82
|
end
|
83
83
|
|
84
84
|
end
|
@@ -9,117 +9,117 @@ require 'rspec_jumpstart'
|
|
9
9
|
module RSpecJumpstart
|
10
10
|
module ERBTemplates
|
11
11
|
|
12
|
-
BASIC_METHODS_PART_TEMPLATE =
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
12
|
+
BASIC_METHODS_PART_TEMPLATE = <<-SPEC
|
13
|
+
<%- methods_to_generate.map { |method| %>
|
14
|
+
# TODO: auto-generated
|
15
|
+
describe '<%= decorated_name(method) %>' do
|
16
|
+
it '<%= method.name %>' do
|
17
|
+
<%- if get_instantiation_code(c, method) -%><%= get_instantiation_code(c, method) %><%- end -%>
|
18
|
+
<%- if get_params_initialization_code(method) -%><%= get_params_initialization_code(method) %><%- end -%>
|
19
|
+
result = <%= get_method_invocation_code(c, method).sub(c.to_s,'described_class') %>
|
20
|
+
|
21
|
+
expect(result).not_to be_nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
<% } %>
|
25
25
|
SPEC
|
26
26
|
|
27
|
-
BASIC_NEW_SPEC_TEMPLATE =
|
28
|
-
|
27
|
+
BASIC_NEW_SPEC_TEMPLATE = <<-SPEC
|
28
|
+
# frozen_string_literal: true
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
<% if rails_mode then %>require 'rails_helper'
|
31
|
+
<% else -%>require 'spec_helper'
|
32
|
+
<% end -%>
|
33
|
+
<% unless rails_mode then %>require '<%= self_path %>'
|
34
|
+
<% end -%>
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
RSpec.describe <%= to_string_namespaced_path_whole(file_path) %> do
|
37
|
+
<%= ERB.new(BASIC_METHODS_PART_TEMPLATE, nil, '-').result(binding) -%>
|
38
|
+
end
|
39
39
|
SPEC
|
40
40
|
|
41
|
-
RAILS_CONTROLLER_METHODS_PART_TEMPLATE =
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
41
|
+
RAILS_CONTROLLER_METHODS_PART_TEMPLATE = <<-SPEC
|
42
|
+
<%- methods_to_generate.map { |method| %>
|
43
|
+
# TODO: auto-generated
|
44
|
+
describe '<%= decorated_name(method) %>' do
|
45
|
+
it '<%= get_rails_http_method(method.name).upcase %> <%= method.name %>' do
|
46
|
+
<%= get_rails_http_method(method.name) %> :<%= method.name %>, {}, {}
|
47
|
+
|
48
|
+
expect(response).to have_http_status(:ok)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
<% } %>
|
52
52
|
SPEC
|
53
53
|
|
54
|
-
RAILS_CONTROLLER_NEW_SPEC_TEMPLATE =
|
55
|
-
|
54
|
+
RAILS_CONTROLLER_NEW_SPEC_TEMPLATE = <<-SPEC
|
55
|
+
# frozen_string_literal: true
|
56
56
|
|
57
|
-
|
57
|
+
require 'rails_helper'
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
|
59
|
+
RSpec.describe <%= (to_string_namespaced_path(self_path) + get_complete_class_name(c)).split('::').uniq.join('::') %>, type: :controller do
|
60
|
+
<%= ERB.new(RAILS_CONTROLLER_METHODS_PART_TEMPLATE, nil, '-').result(binding) -%>
|
61
|
+
end
|
62
62
|
SPEC
|
63
63
|
|
64
|
-
RAILS_MODEL_METHODS_PART_TEMPLATE =
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
64
|
+
RAILS_MODEL_METHODS_PART_TEMPLATE = <<-SPEC
|
65
|
+
<%= ERB.new(RAILS_MODEL_SCOPE_PART_TEMPLATE, nil, '-').result(binding) -%>
|
66
|
+
<%- methods_to_generate.map { |method| %>
|
67
|
+
# TODO: auto-generated
|
68
|
+
describe '<%= decorated_name(method) %>' do
|
69
|
+
it '<%= method.name %>' do
|
70
|
+
<%- if get_instantiation_code(c, method) -%><%= get_instantiation_code(c, method) %><%- end -%>
|
71
|
+
<%- if get_params_initialization_code(method) -%><%= get_params_initialization_code(method) %><%- end -%>
|
72
|
+
result = <%= get_method_invocation_code(c, method).sub(c.to_s,'described_class') %>
|
73
|
+
|
74
|
+
expect(result).not_to be_nil
|
75
|
+
end
|
76
|
+
end
|
77
|
+
<% } %>
|
78
78
|
SPEC
|
79
79
|
|
80
|
-
RAILS_MODEL_SCOPE_PART_TEMPLATE =
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
80
|
+
RAILS_MODEL_SCOPE_PART_TEMPLATE = <<-SPEC
|
81
|
+
<%- scope_methods_to_generate.map { |method| %>
|
82
|
+
# TODO: auto-generated
|
83
|
+
describe '.<%= method %>' do # scope test
|
84
|
+
it 'supports named scope <%= method %>' do
|
85
|
+
expect(described_class.limit(3).<%= method %>).to all(be_a(described_class))
|
86
|
+
end
|
87
|
+
end<% } %>
|
88
88
|
SPEC
|
89
89
|
|
90
|
-
RAILS_MODEL_NEW_SPEC_TEMPLATE =
|
91
|
-
|
90
|
+
RAILS_MODEL_NEW_SPEC_TEMPLATE = <<-SPEC
|
91
|
+
# frozen_string_literal: true
|
92
92
|
|
93
|
-
|
94
|
-
|
93
|
+
require 'rails_helper'
|
94
|
+
require 'shared_model_stuff'
|
95
95
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
96
|
+
RSpec.describe <%= (to_string_namespaced_path(self_path) + get_complete_class_name(c)).split('::').uniq.join('::') %>, type: :model do
|
97
|
+
it_behaves_like 'real_model'
|
98
|
+
<%= ERB.new(RAILS_MODEL_METHODS_PART_TEMPLATE, nil, '-').result(binding) -%>
|
99
|
+
end
|
100
100
|
SPEC
|
101
101
|
|
102
|
-
RAILS_HELPER_METHODS_PART_TEMPLATE =
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
102
|
+
RAILS_HELPER_METHODS_PART_TEMPLATE = <<-SPEC
|
103
|
+
<%- methods_to_generate.map { |method| %>
|
104
|
+
# TODO: auto-generated
|
105
|
+
describe '<%= decorated_name(method) %>' do
|
106
|
+
it 'works' do
|
107
|
+
result = <%= get_rails_helper_method_invocation_code(method) %>
|
108
|
+
|
109
|
+
expect(result).not_to be_nil
|
110
|
+
end
|
111
|
+
end
|
112
|
+
<% } %>
|
113
113
|
SPEC
|
114
114
|
|
115
|
-
RAILS_HELPER_NEW_SPEC_TEMPLATE =
|
116
|
-
|
115
|
+
RAILS_HELPER_NEW_SPEC_TEMPLATE = <<-SPEC
|
116
|
+
# frozen_string_literal: true
|
117
117
|
|
118
|
-
|
118
|
+
require 'rails_helper'
|
119
119
|
|
120
|
-
|
121
|
-
|
122
|
-
|
120
|
+
RSpec.describe <%= (to_string_namespaced_path(self_path) + get_complete_class_name(c)).split('::').uniq.join('::') %>, type: :helper do
|
121
|
+
<%= ERB.new(RAILS_HELPER_METHODS_PART_TEMPLATE, nil, '-').result(binding) -%>
|
122
|
+
end
|
123
123
|
SPEC
|
124
124
|
|
125
125
|
end
|
@@ -39,7 +39,7 @@ module RSpecJumpstart
|
|
39
39
|
else
|
40
40
|
puts red("#{file_path} skipped (Class/Module not found).")
|
41
41
|
end
|
42
|
-
rescue
|
42
|
+
rescue StandardError => e
|
43
43
|
puts red("#{file_path} aborted - #{e.message}")
|
44
44
|
end
|
45
45
|
|
@@ -80,10 +80,11 @@ module RSpecJumpstart
|
|
80
80
|
# e.g. "lib/foo/bar_baz.rb" -> "spec/foo/bar_baz_spec.rb"
|
81
81
|
#
|
82
82
|
def get_spec_path(file_path)
|
83
|
-
spec_dir + '/' +
|
84
|
-
|
85
|
-
|
86
|
-
|
83
|
+
spec_dir + '/' +
|
84
|
+
file_path
|
85
|
+
.gsub(/^\.\//, '')
|
86
|
+
.gsub(%r{^(lib/)|(app/)}, '')
|
87
|
+
.sub(/\.rb$/, '_spec.rb')
|
87
88
|
end
|
88
89
|
|
89
90
|
#
|
@@ -190,14 +191,20 @@ module RSpecJumpstart
|
|
190
191
|
# rubocop:enable Lint/UselessAssignment
|
191
192
|
|
192
193
|
erb = RSpecJumpstart::ERBFactory.new(@delta_template).get_instance_for_appending(rails_mode, spec_path)
|
193
|
-
additional_spec = erb.result(binding)
|
194
|
+
additional_spec = erb.result(binding).strip
|
194
195
|
|
195
196
|
last_end_not_found = true
|
196
197
|
code = existing_spec.split("\n").reverse.reject do |line|
|
197
198
|
before_modified = last_end_not_found
|
198
199
|
last_end_not_found = line.gsub(/#.+$/, '').strip != 'end' if before_modified
|
199
200
|
before_modified
|
200
|
-
end.reverse.join("\n")
|
201
|
+
end.reverse.join("\n")
|
202
|
+
|
203
|
+
unless additional_spec.empty?
|
204
|
+
code += "\n" + additional_spec + "\n"
|
205
|
+
end
|
206
|
+
|
207
|
+
code += "\nend\n"
|
201
208
|
|
202
209
|
if dry_run
|
203
210
|
puts "----- #{spec_path} -----"
|
@@ -213,7 +220,7 @@ module RSpecJumpstart
|
|
213
220
|
|
214
221
|
def skip?(text)
|
215
222
|
RSpecJumpstart.config.behaves_like_exclusions.each do |exclude_pattern|
|
216
|
-
|
223
|
+
return true if text.match(exclude_pattern)
|
217
224
|
end
|
218
225
|
|
219
226
|
false
|
@@ -232,16 +239,14 @@ module RSpecJumpstart
|
|
232
239
|
# bar_baz = BarBaz.new(a, b)
|
233
240
|
#
|
234
241
|
def get_instantiation_code(c, method)
|
235
|
-
if method.singleton
|
236
|
-
|
242
|
+
return '' if method.singleton
|
243
|
+
|
244
|
+
constructor = c.method_list.find { |m| m.name == 'new' }
|
245
|
+
if constructor.nil?
|
246
|
+
" #{instance_name(c)} = described_class.new\n"
|
237
247
|
else
|
238
|
-
constructor
|
239
|
-
|
240
|
-
" #{instance_name(c)} = described_class.new\n"
|
241
|
-
else
|
242
|
-
get_params_initialization_code(constructor) +
|
243
|
-
" #{instance_name(c)} = described_class.new#{to_params_part(constructor.params)}\n"
|
244
|
-
end
|
248
|
+
get_params_initialization_code(constructor) +
|
249
|
+
" #{instance_name(c)} = described_class.new#{to_params_part(constructor.params)}\n"
|
245
250
|
end
|
246
251
|
end
|
247
252
|
|
@@ -277,11 +282,9 @@ module RSpecJumpstart
|
|
277
282
|
# e.g. { |a, b| }
|
278
283
|
#
|
279
284
|
def get_block_code(method)
|
280
|
-
if method.block_params.nil? || method.block_params.empty?
|
281
|
-
|
282
|
-
|
283
|
-
" { |#{method.block_params}| }"
|
284
|
-
end
|
285
|
+
return '' if method.block_params.nil? || method.block_params.empty?
|
286
|
+
|
287
|
+
" { |#{method.block_params}| }"
|
285
288
|
end
|
286
289
|
|
287
290
|
def get_rails_http_method(method_name)
|
@@ -26,20 +26,11 @@ module RSpecJumpstart
|
|
26
26
|
#
|
27
27
|
def self.get_ruby_parser(file_path)
|
28
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
|
33
29
|
|
34
|
-
# RDoc::
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
top_level.store = store
|
39
|
-
stats = RDoc::Stats.new(store, 1)
|
40
|
-
else
|
41
|
-
stats = RDoc::Stats.new(1)
|
42
|
-
end
|
30
|
+
# RDoc 4.0.0 requires RDoc::Store internally.
|
31
|
+
store = RDoc::Store.new
|
32
|
+
top_level.store = store
|
33
|
+
stats = RDoc::Stats.new(store, 1)
|
43
34
|
|
44
35
|
RDoc::Parser::Ruby.new(
|
45
36
|
top_level,
|
@@ -55,15 +46,13 @@ module RSpecJumpstart
|
|
55
46
|
#
|
56
47
|
def self.extract_target_class_or_module(top_level)
|
57
48
|
c = top_level.classes.first
|
58
|
-
if c
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
extract_target_class_or_module(m)
|
64
|
-
end
|
49
|
+
return c if c
|
50
|
+
|
51
|
+
m = top_level.modules.first
|
52
|
+
if m.nil?
|
53
|
+
top_level.is_a?(RDoc::NormalModule) ? top_level : nil
|
65
54
|
else
|
66
|
-
|
55
|
+
extract_target_class_or_module(m)
|
67
56
|
end
|
68
57
|
end
|
69
58
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-jumpstart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Timothy Chambers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: rspec-jumpstart supports you writing tests for existing code.
|
14
14
|
email:
|
@@ -45,8 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
47
|
requirements: []
|
48
|
-
|
49
|
-
rubygems_version: 2.6.11
|
48
|
+
rubygems_version: 3.0.1
|
50
49
|
signing_key:
|
51
50
|
specification_version: 4
|
52
51
|
summary: rspec-jumpstart supports you writing tests for existing code.
|