spec_producer 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cbf3344329308865bd461e0d7b32bb9bb9ffc2c0
4
- data.tar.gz: 3e31ede5c27b8ccd8699f5f9be4bad78a65eac2c
3
+ metadata.gz: 9ca6e22c07edbf180a24cea44d49e20766b84f90
4
+ data.tar.gz: 32b9e5e6ca66434d6fe562d1d1d8a3ab19f018e7
5
5
  SHA512:
6
- metadata.gz: 3273677838cbed20613bac5ce81122145b7da955e3900b9eb4af832cc1e7e1b6d55bda632f6f05423763a37c79f08453c0253896b8560d0c9d96fc73544b201b
7
- data.tar.gz: a38b7b70e7d472d7e05f0ccae9ea698db92f7c5ef3fc9594fe9b6c54f6eda1fa0f963fe48a1258ae144e3efbcafc9e40439f36622f515532576df9057cd6ec4f
6
+ metadata.gz: 76bb1000583dd9b8da82d325975e491a994346a19308a1954b66fbc294b213af7a09823460cde128e1f71a586a0e7d2b1768806589f9f6e2687d12c2049a9192
7
+ data.tar.gz: 326c949ae2375a7c3f6f7c01b89088f1af67a5420ee39199ea1e533b98629b5731bca92888c8342d7032e584b5c8f9175e79b474632bce5d658d4e17ca7aa853
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.10.0 (2016-10-07)
2
+
3
+ Features:
4
+ * Allow clients to set namespace in options for missing resources
5
+
6
+ Fixes:
7
+ * Problem with missing resources methods due to typo.
8
+
1
9
  ## 0.9.0 (2016-10-06)
2
10
 
3
11
  * Ignore optional parameters when producing routing specs
@@ -0,0 +1,64 @@
1
+ module SpecProducer::FactoriesProductionModule
2
+ def self.produce_factories
3
+ Dir.glob(Rails.root.join('app/models/*.rb')).each do |x|
4
+ require x
5
+ end
6
+
7
+ not_valid_descendants = [ ActiveRecord::SchemaMigration, Delayed::Backend::ActiveRecord::Job ]
8
+
9
+ ActiveRecord::Base.descendants.reject { |descendant| not_valid_descendants.include? descendant }.each do |descendant|
10
+ final_text = "FactoryGirl.define do\n"
11
+ final_text << " factory :#{descendant.name.underscore}, :class => #{descendant.name} do\n"
12
+
13
+ descendant.columns.each do |column|
14
+ value = case column.type
15
+ when :string then "'#{descendant.name.underscore.upcase}_#{column.name.underscore.upcase}'"
16
+ when :text then "'#{descendant.name.underscore.upcase}_#{column.name.underscore.upcase}'"
17
+ when :integer then "#{rand(1...10)}"
18
+ when :decimal then "#{rand(1.0...100.0)}"
19
+ when :float then "#{rand(1.0...100.0)}"
20
+ when :datetime then "'#{DateTime.now + 365}'"
21
+ when :time then "'#{Time.now + 365*24*60*60}'"
22
+ when :date then "'#{Date.today + 365}'"
23
+ when :boolean then "#{rand(2) == 1 ? true : false}"
24
+ when :binary then "#{5.times.collect { rand(0..1).to_s }.join('')}"
25
+ end
26
+
27
+ final_text << " #{column.name} #{value}\n"
28
+ end
29
+
30
+ final_text << " end\n"
31
+ final_text << "end"
32
+
33
+ if File.exists?(Rails.root.join("spec/factories/#{descendant.name.underscore}.rb"))
34
+ puts '#'*100
35
+ puts "Please, check whether the following lines are included in: spec/factories/" + descendant.name.underscore + ".rb\n"
36
+ puts '#'*100
37
+ puts "\n"
38
+ puts final_text
39
+ else
40
+ unless Dir.exists? Rails.root.join("spec")
41
+ puts "Generating spec directory"
42
+ Dir.mkdir(Rails.root.join("spec"))
43
+ end
44
+
45
+ unless Dir.exists? Rails.root.join("spec/factories")
46
+ puts "Generating spec/factories directory"
47
+ Dir.mkdir(Rails.root.join("spec/factories"))
48
+ end
49
+
50
+ path = "spec/factories/#{descendant.name.underscore}.rb"
51
+ puts "Producing factory file for: #{path}"
52
+ f = File.open("#{Rails.root.join(path)}", 'wb+')
53
+ f.write(final_text)
54
+ f.close
55
+ end
56
+ end
57
+
58
+ nil
59
+ rescue NameError
60
+ puts "ActiveRecord is not set for this project. Can't produce factories for this project."
61
+ rescue Exception => e
62
+ puts "Exception '#{e}' was raised. Skipping factories production."
63
+ end
64
+ end
@@ -1,6 +1,10 @@
1
- module MissingFilesModule
2
- def self.print_missing_model_specs
3
- files_list = Dir["app/models/**/*.rb"]
1
+ module SpecProducer::MissingFilesModule
2
+ def self.print_missing_model_specs(options = {})
3
+ if options[:specific_namespace]
4
+ files_list = Dir["app/models/**/#{options[:specific_namespace].gsub('app/models', '')}/**/*.rb"]
5
+ else
6
+ files_list = Dir["app/models/**/*.rb"]
7
+ end
4
8
 
5
9
  puts "\n" << "## Searching for missing model specs..."
6
10
  files_list.each do |file|
@@ -12,8 +16,12 @@ module MissingFilesModule
12
16
  nil
13
17
  end
14
18
 
15
- def self.print_missing_controller_specs
16
- files_list = Dir["app/controllers/**/*.rb"]
19
+ def self.print_missing_controller_specs(options = {})
20
+ if options[:specific_namespace]
21
+ files_list = Dir["app/controllers/**/#{options[:specific_namespace].gsub('app/controllers', '')}/**/*.rb"]
22
+ else
23
+ files_list = Dir["app/controllers/**/*.rb"]
24
+ end
17
25
 
18
26
  puts "\n" << "## Searching for missing controller specs..."
19
27
  files_list.each do |file|
@@ -25,8 +33,12 @@ module MissingFilesModule
25
33
  nil
26
34
  end
27
35
 
28
- def self.print_missing_job_specs
29
- files_list = Dir["app/jobs/**/*.rb"]
36
+ def self.print_missing_job_specs(options = {})
37
+ if options[:specific_namespace]
38
+ files_list = Dir["app/jobs/**/#{options[:specific_namespace].gsub('app/jobs', '')}/**/*.rb"]
39
+ else
40
+ files_list = Dir["app/jobs/**/*.rb"]
41
+ end
30
42
 
31
43
  puts "\n" << "## Searching for missing jobs specs..."
32
44
  files_list.each do |file|
@@ -38,8 +50,12 @@ module MissingFilesModule
38
50
  nil
39
51
  end
40
52
 
41
- def self.print_missing_mailer_specs
42
- files_list = Dir["app/mailers/**/*.rb"]
53
+ def self.print_missing_mailer_specs(options = {})
54
+ if options[:specific_namespace]
55
+ files_list = Dir["app/mailers/**/#{options[:specific_namespace].gsub('app/mailers', '')}/**/*.rb"]
56
+ else
57
+ files_list = Dir["app/mailers/**/*.rb"]
58
+ end
43
59
 
44
60
  puts "\n" << "## Searching for missing mailers specs..."
45
61
  files_list.each do |file|
@@ -51,8 +67,12 @@ module MissingFilesModule
51
67
  nil
52
68
  end
53
69
 
54
- def self.print_missing_helper_specs
55
- files_list = Dir["app/helpers/**/*.rb"]
70
+ def self.print_missing_helper_specs(options = {})(options = {})
71
+ if options[:specific_namespace]
72
+ files_list = Dir["app/helpers/**/#{options[:specific_namespace].gsub('app/helpers', '')}/**/*.rb"]
73
+ else
74
+ files_list = Dir["app/helpers/**/*.rb"]
75
+ end
56
76
 
57
77
  puts "\n" << "## Searching for missing helper specs..."
58
78
  files_list.each do |file|
@@ -64,8 +84,12 @@ module MissingFilesModule
64
84
  nil
65
85
  end
66
86
 
67
- def self.print_missing_view_specs
68
- files_list = Dir["app/views/**/*.erb"]
87
+ def self.print_missing_view_specs(options = {})
88
+ if options[:specific_namespace]
89
+ files_list = Dir["app/views/**/#{options[:specific_namespace].gsub('app/views', '')}/**/*.erb"]
90
+ else
91
+ files_list = Dir["app/views/**/*.erb"]
92
+ end
69
93
 
70
94
  puts "\n" << "## Searching for missing view specs..."
71
95
  files_list.each do |file|
@@ -1,4 +1,4 @@
1
- module SpecProductionModule
1
+ module SpecProducer::SpecProductionModule
2
2
  def self.produce_specs_for_models
3
3
  Dir.glob(Rails.root.join('app/models/*.rb')).each do |x|
4
4
  require x
@@ -78,13 +78,17 @@ module SpecProductionModule
78
78
  final_text << "end"
79
79
 
80
80
  if File.exists?(Rails.root.join("spec/models/#{descendant.name.underscore}_spec.rb"))
81
- puts '#'*100
82
- puts "Please, check whether the following lines are included in: " + descendant.name.underscore + "_spec.rb\n"
83
- puts '#'*100
84
- puts "\n"
85
- puts final_text
81
+ if File.open(Rails.root.join("spec/models/#{descendant.name.underscore}_spec.rb")).read == final_text
82
+ # nothing to do here, pre-existing content is the same :)
83
+ else
84
+ puts '#'*100
85
+ puts "Please, check whether the following lines are included in: " + descendant.name.underscore + "_spec.rb\n"
86
+ puts '#'*100
87
+ puts "\n"
88
+ puts final_text
89
+ end
86
90
  else
87
- check_if_spec_file_exists
91
+ check_if_spec_folder_exists
88
92
 
89
93
  unless Dir.exists? Rails.root.join("spec/models")
90
94
  puts "Generating spec/models directory"
@@ -150,7 +154,7 @@ module SpecProductionModule
150
154
  puts final_text
151
155
  end
152
156
  else
153
- check_if_spec_file_exists
157
+ check_if_spec_folder_exists
154
158
 
155
159
  unless Dir.exists? Rails.root.join("spec/routing")
156
160
  puts "Generating spec/routing directory"
@@ -250,9 +254,19 @@ module SpecProductionModule
250
254
 
251
255
  final_text << "end\n"
252
256
 
253
- check_if_spec_file_exists
257
+ check_if_spec_folder_exists
254
258
 
255
- unless FileTest.exists?(file_name)
259
+ if File.exists?(Rails.root.join(file_name))
260
+ if File.open(Rails.root.join(file_name)).read == final_text
261
+ # nothing to do here, pre-existing content is the same :)
262
+ else
263
+ puts '#'*100
264
+ puts "Please, check whether the following lines are included in: " + file_name + "\n"
265
+ puts '#'*100
266
+ puts "\n"
267
+ puts final_text
268
+ end
269
+ else
256
270
  puts "Producing view spec file for: #{file_name}"
257
271
  f = File.open(file_name, 'wb+')
258
272
  f.write(final_text)
@@ -286,9 +300,19 @@ module SpecProductionModule
286
300
  final_text << " pending 'view helper tests'\n"
287
301
  final_text << "end"
288
302
 
289
- check_if_spec_file_exists
303
+ check_if_spec_folder_exists
290
304
 
291
- unless FileTest.exists?(file_name)
305
+ if File.exists?(Rails.root.join(file_name))
306
+ if File.open(Rails.root.join(file_name)).read == final_text
307
+ # nothing to do here, pre-existing content is the same :)
308
+ else
309
+ puts '#'*100
310
+ puts "Please, check whether the following lines are included in: " + file_name + "\n"
311
+ puts '#'*100
312
+ puts "\n"
313
+ puts final_text
314
+ end
315
+ else
292
316
  puts "Producing helper spec file for: #{file_name}"
293
317
  f = File.open(file_name, 'wb+')
294
318
  f.write(final_text)
@@ -322,9 +346,19 @@ module SpecProductionModule
322
346
  final_text << " pending 'mailer tests'\n"
323
347
  final_text << "end"
324
348
 
325
- check_if_spec_file_exists
349
+ check_if_spec_folder_exists
326
350
 
327
- unless FileTest.exists?(file_name)
351
+ if File.exists?(Rails.root.join(file_name))
352
+ if File.open(Rails.root.join(file_name)).read == final_text
353
+ # nothing to do here, pre-existing content is the same :)
354
+ else
355
+ puts '#'*100
356
+ puts "Please, check whether the following lines are included in: " + file_name + "\n"
357
+ puts '#'*100
358
+ puts "\n"
359
+ puts final_text
360
+ end
361
+ else
328
362
  puts "Producing helper spec file for: #{file_name}"
329
363
  f = File.open(file_name, 'wb+')
330
364
  f.write(final_text)
@@ -358,9 +392,19 @@ module SpecProductionModule
358
392
  final_text << " pending 'job tests'\n"
359
393
  final_text << "end"
360
394
 
361
- check_if_spec_file_exists
395
+ check_if_spec_folder_exists
362
396
 
363
- unless FileTest.exists?(file_name)
397
+ if File.exists?(Rails.root.join(file_name))
398
+ if File.open(Rails.root.join(file_name)).read == final_text
399
+ # nothing to do here, pre-existing content is the same :)
400
+ else
401
+ puts '#'*100
402
+ puts "Please, check whether the following lines are included in: " + file_name + "\n"
403
+ puts '#'*100
404
+ puts "\n"
405
+ puts final_text
406
+ end
407
+ else
364
408
  puts "Producing helper spec file for: #{file_name}"
365
409
  f = File.open(file_name, 'wb+')
366
410
  f.write(final_text)
@@ -410,9 +454,19 @@ module SpecProductionModule
410
454
 
411
455
  final_text << "end\n"
412
456
 
413
- check_if_spec_file_exists
457
+ check_if_spec_folder_exists
414
458
 
415
- unless FileTest.exists?(file_name)
459
+ if File.exists?(Rails.root.join(file_name))
460
+ if File.open(Rails.root.join(file_name)).read == final_text
461
+ # nothing to do here, pre-existing content is the same :)
462
+ else
463
+ puts '#'*100
464
+ puts "Please, check whether the following lines are included in: " + file_name + "\n"
465
+ puts '#'*100
466
+ puts "\n"
467
+ puts final_text
468
+ end
469
+ else
416
470
  puts "Producing controller spec file for: #{file_name}"
417
471
  f = File.open(file_name, 'wb+')
418
472
  f.write(final_text)
@@ -473,7 +527,7 @@ module SpecProductionModule
473
527
  end
474
528
  end
475
529
 
476
- def self.check_if_spec_file_exists
530
+ def self.check_if_spec_folder_exists
477
531
  unless Dir.exists? Rails.root.join("spec")
478
532
  puts "Generating spec directory"
479
533
  Dir.mkdir(Rails.root.join("spec"))
@@ -483,5 +537,5 @@ module SpecProductionModule
483
537
  private_class_method :produce_association_options
484
538
  private_class_method :require_helper_string
485
539
  private_class_method :collect_helper_strings
486
- private_class_method :check_if_spec_file_exists
540
+ private_class_method :check_if_spec_folder_exists
487
541
  end
@@ -1,3 +1,3 @@
1
1
  module SpecProducer
2
- VERSION = "0.9.0"
2
+ VERSION = "0.10.0"
3
3
  end
data/lib/spec_producer.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "spec_producer/version"
2
2
  require "spec_producer/missing_files_module"
3
3
  require "spec_producer/spec_production_module"
4
+ require "spec_producer/factories_production_module"
4
5
 
5
6
  module SpecProducer
6
7
  def self.produce_specs_for_all_types
@@ -130,42 +131,39 @@ module SpecProducer
130
131
  end
131
132
 
132
133
  nil
133
- rescue NameError
134
- puts "ActiveRecord is not set for this project. Can't produce factories for this project."
135
- rescue Exception => e
136
- puts "Exception '#{e}' was raised. Skipping factories production."
134
+ FactoriesProductionModule.produce_factories
137
135
  end
138
136
 
139
- def self.print_all_missing_spec_files
140
- MissingFiles.print_missing_model_specs
141
- MissingFiles.print_missing_controller_specs
142
- MissingFiles.print_missing_helper_specs
143
- MissingFiles.print_missing_view_specs
144
- MissingFiles.print_missing_mailer_specs
145
- MissingFiles.print_missing_job_specs
137
+ def self.print_all_missing_spec_files(options = {})
138
+ MissingFilesModule.print_missing_model_specs(options)
139
+ MissingFilesModule.print_missing_controller_specs(options)
140
+ MissingFilesModule.print_missing_helper_specs(options)
141
+ MissingFilesModule.print_missing_view_specs(options)
142
+ MissingFilesModule.print_missing_mailer_specs(options)
143
+ MissingFilesModule.print_missing_job_specs(options)
146
144
  end
147
145
 
148
- def self.print_missing_model_specs
149
- MissingFiles.print_missing_model_specs
146
+ def self.print_missing_model_specs(options = {})
147
+ MissingFilesModule.print_missing_model_specs(options)
150
148
  end
151
149
 
152
- def self.print_missing_controller_specs
153
- MissingFiles.print_missing_controller_specs
150
+ def self.print_missing_controller_specs(options = {})
151
+ MissingFilesModule.print_missing_controller_specs(options)
154
152
  end
155
153
 
156
- def self.print_missing_helper_specs
157
- MissingFiles.print_missing_helper_specs
154
+ def self.print_missing_helper_specs(options = {})
155
+ MissingFilesModule.print_missing_helper_specs(options)
158
156
  end
159
157
 
160
- def self.print_missing_view_specs
161
- MissingFiles.print_missing_view_specs
158
+ def self.print_missing_view_specs(options = {})
159
+ MissingFilesModule.print_missing_view_specs(options)
162
160
  end
163
161
 
164
- def self.print_missing_mailer_specs
165
- MissingFiles.print_missing_mailer_specs
162
+ def self.print_missing_mailer_specs(options = {})
163
+ MissingFilesModule.print_missing_mailer_specs(options)
166
164
  end
167
165
 
168
- def self.print_missing_job_specs
169
- MissingFiles.print_missing_job_specs
166
+ def self.print_missing_job_specs(options = {})
167
+ MissingFilesModule.print_missing_job_specs(options)
170
168
  end
171
169
  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.9.0
4
+ version: 0.10.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-10-05 00:00:00.000000000 Z
11
+ date: 2016-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,6 +72,7 @@ files:
72
72
  - bin/console
73
73
  - bin/setup
74
74
  - lib/spec_producer.rb
75
+ - lib/spec_producer/factories_production_module.rb
75
76
  - lib/spec_producer/missing_files_module.rb
76
77
  - lib/spec_producer/spec_production_module.rb
77
78
  - lib/spec_producer/version.rb