spec_producer 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +0 -1
- data/lib/spec_producer/version.rb +1 -1
- data/lib/spec_producer.rb +128 -26
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa9471f617a4a561c9341e4499b805ac78dde481
|
4
|
+
data.tar.gz: 77191d8a8f92a2e5157839a18c19150e1c63c9dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38cf7383d2bb5b2fed451719d5a474d97c639d8f7ba24a7f999d7c77ae6441a875741cc4c976230c6391ef16c83650c0d8fa60ba06b67f38d8af139963a78e83
|
7
|
+
data.tar.gz: ddcf094c9e1101b5b56083c682cd5d986d92eeb6d129cebc70c190f1a30f2a044a17f42e25b62f6a8d1837aab7a64286ee6f40a439cf7b086ed0b6d3520ce29e
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
## 0.4.0 (2016-07-09)
|
2
|
+
|
3
|
+
Features:
|
4
|
+
* Added tests for readonly attributes
|
5
|
+
* Added more validation tests
|
6
|
+
* Added tests for db associations
|
7
|
+
|
8
|
+
Bug fixes:
|
9
|
+
* Fixes bug with naming
|
10
|
+
* Fixes bug when spec directory doesn't exist
|
11
|
+
* Fixes bug that skipped models in deeper namespace
|
12
|
+
* Code reformats and clearer output
|
13
|
+
|
1
14
|
## 0.3.0 (2016-06-12)
|
2
15
|
|
3
16
|
Features:
|
data/README.md
CHANGED
data/lib/spec_producer.rb
CHANGED
@@ -19,53 +19,91 @@ module SpecProducer
|
|
19
19
|
final_text << "describe #{descendant.name} do\n"
|
20
20
|
|
21
21
|
descendant.attribute_names.each do |attribute|
|
22
|
-
final_text << "
|
22
|
+
final_text << " it { should respond_to :#{attribute}, :#{attribute}= }\n"
|
23
|
+
end
|
24
|
+
|
25
|
+
descendant.readonly_attributes.each do |attribute|
|
26
|
+
final_text << " it { should have_readonly_attribute :#{attribute} }\n"
|
27
|
+
end
|
28
|
+
|
29
|
+
if descendant.validators.reject { |validator| validator.kind == :associated }.present?
|
30
|
+
final_text << "\n # Validators\n"
|
23
31
|
end
|
24
32
|
|
25
33
|
descendant.validators.each do |validator|
|
26
34
|
if validator.kind == :presence
|
27
35
|
validator.attributes.each do |attribute|
|
28
|
-
final_text << "
|
36
|
+
final_text << " it { should validate_presence_of :#{attribute} }\n"
|
29
37
|
end
|
30
38
|
elsif validator.kind == :uniqueness
|
31
39
|
validator.attributes.each do |attribute|
|
32
|
-
final_text << "
|
40
|
+
final_text << " it { should validate_uniqueness_of :#{attribute} }\n"
|
33
41
|
end
|
34
42
|
elsif validator.kind == :numericality
|
35
43
|
validator.attributes.each do |attribute|
|
36
|
-
final_text << "
|
44
|
+
final_text << " it { should validate_numericality_of :#{attribute} }\n"
|
37
45
|
end
|
38
46
|
elsif validator.kind == :acceptance
|
39
47
|
validator.attributes.each do |attribute|
|
40
|
-
final_text << "
|
48
|
+
final_text << " it { should validate_acceptance_of :#{attribute} }\n"
|
41
49
|
end
|
42
50
|
elsif validator.kind == :confirmation
|
43
51
|
validator.attributes.each do |attribute|
|
44
|
-
final_text << "
|
52
|
+
final_text << " it { should validate_confirmation_of :#{attribute} }\n"
|
53
|
+
end
|
54
|
+
elsif validator.kind == :length
|
55
|
+
validator.attributes.each do |attribute|
|
56
|
+
final_text << " it { should validate_length_of :#{attribute} }\n"
|
57
|
+
end
|
58
|
+
elsif validator.kind == :absence
|
59
|
+
validator.attributes.each do |attribute|
|
60
|
+
final_text << " it { should validate_absence_of :#{attribute} }\n"
|
45
61
|
end
|
46
62
|
end
|
47
63
|
end
|
48
64
|
|
65
|
+
if descendant.column_names.present?
|
66
|
+
final_text << "\n # Columns\n"
|
67
|
+
end
|
68
|
+
|
49
69
|
descendant.column_names.each do |column_name|
|
50
|
-
final_text << "
|
70
|
+
final_text << " it { should have_db_column :#{column_name} }\n"
|
71
|
+
end
|
72
|
+
|
73
|
+
if descendant.reflections.keys.present?
|
74
|
+
final_text << "\n # Associations\n"
|
75
|
+
end
|
76
|
+
|
77
|
+
descendant.reflections.each_pair do |key, reflection|
|
78
|
+
final_text << case reflection.macro
|
79
|
+
when :belongs_to then " it { should belong_to(:#{key})#{produce_association_options(reflection)} }\n"
|
80
|
+
when :has_one then " it { should have_one(:#{key})#{produce_association_options(reflection)} }\n"
|
81
|
+
when :has_many then " it { should have_many(:#{key})#{produce_association_options(reflection)} }\n"
|
82
|
+
when :has_and_belongs_to_many then " it { should have_and_belong_to_many(:#{key})#{produce_association_options(reflection)} }\n"
|
83
|
+
end
|
51
84
|
end
|
52
85
|
|
53
86
|
final_text << "end"
|
54
87
|
|
55
|
-
if File.exists?(Rails.root.join("spec/models/#{descendant.name.
|
88
|
+
if File.exists?(Rails.root.join("spec/models/#{descendant.name.underscore}_spec.rb"))
|
56
89
|
puts '#'*100
|
57
|
-
puts "Please, check whether the following lines are included in: " + descendant.name.
|
90
|
+
puts "Please, check whether the following lines are included in: " + descendant.name.underscore + "_spec.rb\n"
|
58
91
|
puts '#'*100
|
59
92
|
puts "\n"
|
60
93
|
puts final_text
|
61
94
|
else
|
95
|
+
unless Dir.exists? Rails.root.join("spec")
|
96
|
+
puts "Generating spec directory"
|
97
|
+
Dir.mkdir(Rails.root.join("spec"))
|
98
|
+
end
|
99
|
+
|
62
100
|
unless Dir.exists? Rails.root.join("spec/models")
|
63
101
|
puts "Generating spec/models directory"
|
64
102
|
Dir.mkdir(Rails.root.join("spec/models"))
|
65
103
|
end
|
66
104
|
|
67
|
-
path = "spec/models/#{descendant.name.
|
68
|
-
puts "
|
105
|
+
path = "spec/models/#{descendant.name.underscore}_spec.rb"
|
106
|
+
puts "Producing model spec file for: #{path}"
|
69
107
|
f = File.open("#{Rails.root.join(path)}", 'wb+')
|
70
108
|
f.write(final_text)
|
71
109
|
f.close
|
@@ -92,17 +130,17 @@ module SpecProducer
|
|
92
130
|
final_text << "describe '#{route_group[0]} routes' do\n"
|
93
131
|
|
94
132
|
route_group[1].each do |route|
|
95
|
-
final_text << "
|
133
|
+
final_text << " it \"#{route[:verb].upcase} #{route[:path]} should route to '#{route[:controller]}##{route[:action]}'\" do\n"
|
96
134
|
|
97
|
-
final_text << "
|
98
|
-
final_text << "
|
135
|
+
final_text << " { :#{route[:verb]} => '#{route[:path].gsub(/:[a-zA-Z_]+/){ |param| param.gsub(':','').upcase }}'}.\n"
|
136
|
+
final_text << " should route_to(:controller => '#{route[:controller]}',\n"
|
99
137
|
|
100
138
|
/:[a-zA-Z_]+/.match(route[:path]).to_a.each do |parameter|
|
101
|
-
final_text << "
|
139
|
+
final_text << " #{parameter} => '#{parameter.gsub(':','').upcase}',\n"
|
102
140
|
end
|
103
141
|
|
104
|
-
final_text << "
|
105
|
-
final_text << "\
|
142
|
+
final_text << " :action => '#{route[:action]}')\n"
|
143
|
+
final_text << " end\n\n"
|
106
144
|
end
|
107
145
|
|
108
146
|
final_text << 'end'
|
@@ -114,13 +152,35 @@ module SpecProducer
|
|
114
152
|
puts "\n"
|
115
153
|
puts final_text
|
116
154
|
else
|
155
|
+
unless Dir.exists? Rails.root.join("spec")
|
156
|
+
puts "Generating spec directory"
|
157
|
+
Dir.mkdir(Rails.root.join("spec"))
|
158
|
+
end
|
159
|
+
|
117
160
|
unless Dir.exists? Rails.root.join("spec/routing")
|
118
161
|
puts "Generating spec/routing directory"
|
119
162
|
Dir.mkdir(Rails.root.join("spec/routing"))
|
120
163
|
end
|
121
164
|
|
165
|
+
# Check whether the route is not in top level namespace but deeper
|
166
|
+
full_path = 'spec/routing'
|
167
|
+
paths = route_group[0].split('/')
|
168
|
+
|
169
|
+
# And if it is deeper in the tree make sure to check if the related namespaces exist or create them
|
170
|
+
if paths.size > 1
|
171
|
+
paths.each do |path|
|
172
|
+
unless path == paths.last
|
173
|
+
full_path << "/#{path}"
|
174
|
+
|
175
|
+
unless Dir.exists? full_path
|
176
|
+
Dir.mkdir(Rails.root.join(full_path))
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
122
182
|
path = "spec/routing/#{route_group[0]}_routing_spec.rb"
|
123
|
-
puts "
|
183
|
+
puts "Producing routing spec file for: #{route_group[0]}"
|
124
184
|
f = File.open("#{Rails.root.join(path)}", 'wb+')
|
125
185
|
f.write(final_text)
|
126
186
|
f.close
|
@@ -148,13 +208,19 @@ module SpecProducer
|
|
148
208
|
file_name = "#{file.gsub('app/', 'spec/')}_spec.rb"
|
149
209
|
final_text = "require 'rails_helper'\n\n"
|
150
210
|
final_text << "describe '#{file.gsub('app/views/', '')}' do\n"
|
151
|
-
final_text << "
|
152
|
-
final_text << "\
|
153
|
-
final_text << "\
|
154
|
-
final_text << "
|
211
|
+
final_text << " before do\n"
|
212
|
+
final_text << " render\n"
|
213
|
+
final_text << " end\n\n"
|
214
|
+
final_text << " pending 'view content test'\n"
|
155
215
|
final_text << "end\n"
|
156
216
|
|
217
|
+
unless Dir.exists? Rails.root.join("spec")
|
218
|
+
puts "Generating spec directory"
|
219
|
+
Dir.mkdir(Rails.root.join("spec"))
|
220
|
+
end
|
221
|
+
|
157
222
|
unless FileTest.exists?(file_name)
|
223
|
+
puts "Producing view spec file for: #{file_name}"
|
158
224
|
f = File.open(file_name, 'wb+')
|
159
225
|
f.write(final_text)
|
160
226
|
f.close
|
@@ -182,10 +248,16 @@ module SpecProducer
|
|
182
248
|
file_name = "#{file.gsub('app/', 'spec/').gsub('.rb', '')}_spec.rb"
|
183
249
|
final_text = "require 'rails_helper'\n\n"
|
184
250
|
final_text << "describe #{File.basename(file, ".rb").camelcase} do\n"
|
185
|
-
final_text << "
|
251
|
+
final_text << " pending 'view helper tests'\n"
|
186
252
|
final_text << "end"
|
187
253
|
|
254
|
+
unless Dir.exists? Rails.root.join("spec")
|
255
|
+
puts "Generating spec directory"
|
256
|
+
Dir.mkdir(Rails.root.join("spec"))
|
257
|
+
end
|
258
|
+
|
188
259
|
unless FileTest.exists?(file_name)
|
260
|
+
puts "Producing helper spec file for: #{file_name}"
|
189
261
|
f = File.open(file_name, 'wb+')
|
190
262
|
f.write(final_text)
|
191
263
|
f.close
|
@@ -196,7 +268,7 @@ module SpecProducer
|
|
196
268
|
end
|
197
269
|
|
198
270
|
def self.produce_specs_for_controllers
|
199
|
-
Dir.glob(Rails.root.join('app/controllers
|
271
|
+
Dir.glob(Rails.root.join('app/controllers/**/*.rb')).each do |x|
|
200
272
|
require x
|
201
273
|
end
|
202
274
|
|
@@ -222,16 +294,22 @@ module SpecProducer
|
|
222
294
|
final_text << "describe #{descendant.name} do\n"
|
223
295
|
|
224
296
|
descendant.action_methods.each do |method|
|
225
|
-
final_text << "
|
297
|
+
final_text << " pending '##{method}'\n"
|
226
298
|
end
|
227
299
|
|
228
300
|
unless descendant.action_methods.size > 0
|
229
|
-
final_text << "
|
301
|
+
final_text << " pending 'tests'\n"
|
230
302
|
end
|
231
303
|
|
232
304
|
final_text << "end\n"
|
233
305
|
|
306
|
+
unless Dir.exists? Rails.root.join("spec")
|
307
|
+
puts "Generating spec directory"
|
308
|
+
Dir.mkdir(Rails.root.join("spec"))
|
309
|
+
end
|
310
|
+
|
234
311
|
unless FileTest.exists?(file_name)
|
312
|
+
puts "Producing controller spec file for: #{file_name}"
|
235
313
|
f = File.open(file_name, 'wb+')
|
236
314
|
f.write(final_text)
|
237
315
|
f.close
|
@@ -299,4 +377,28 @@ module SpecProducer
|
|
299
377
|
|
300
378
|
nil
|
301
379
|
end
|
380
|
+
|
381
|
+
#######
|
382
|
+
private
|
383
|
+
#######
|
384
|
+
|
385
|
+
def self.produce_association_options(reflection)
|
386
|
+
return if reflection.options.empty?
|
387
|
+
|
388
|
+
final_text = []
|
389
|
+
|
390
|
+
reflection.options.each_pair do |key, value|
|
391
|
+
final_text << case key
|
392
|
+
when :inverse_of then "inverse_of(:#{value})"
|
393
|
+
when :autosave then "autosave(#{value})"
|
394
|
+
when :through then "through(:#{value})"
|
395
|
+
when :class_name then "class_name('#{value}')"
|
396
|
+
when :foreign_key then "with_foreign_key('#{value}')"
|
397
|
+
when :primary_key then "with_primary_key('#{value}')"
|
398
|
+
when :source then "source(:#{value})"
|
399
|
+
when :dependent then "dependent(:#{value})"
|
400
|
+
end
|
401
|
+
end
|
402
|
+
final_text.reject(&:nil?).join('.').prepend('.')
|
403
|
+
end
|
302
404
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spec_producer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vasilis Kalligas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|