spec_producer 0.11.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -0
  3. data/CHANGELOG.md +15 -0
  4. data/README.md +73 -24
  5. data/lib/configuration.rb +41 -0
  6. data/lib/generators/spec_producer/install/install_generator.rb +13 -0
  7. data/lib/generators/spec_producer/install/templates/spec_producer +1 -0
  8. data/lib/spec_producer.rb +140 -47
  9. data/lib/spec_producer/factories_production_module.rb +17 -11
  10. data/lib/spec_producer/missing_files_module.rb +104 -41
  11. data/lib/spec_producer/missing_gems_module.rb +77 -0
  12. data/lib/spec_producer/producers.rb +10 -0
  13. data/lib/spec_producer/producers/base.rb +129 -0
  14. data/lib/spec_producer/producers/controllers_producer.rb +31 -0
  15. data/lib/spec_producer/producers/helpers_producer.rb +26 -0
  16. data/lib/spec_producer/producers/jobs_producer.rb +34 -0
  17. data/lib/spec_producer/producers/mailers_producer.rb +24 -0
  18. data/lib/spec_producer/producers/models_producer.rb +89 -0
  19. data/lib/spec_producer/producers/registry.rb +66 -0
  20. data/lib/spec_producer/producers/routes_producer.rb +44 -0
  21. data/lib/spec_producer/producers/serializers_producer.rb +46 -0
  22. data/lib/spec_producer/producers/views_producer.rb +25 -0
  23. data/lib/spec_producer/railtie.rb +13 -0
  24. data/lib/spec_producer/rspec_builders.rb +1 -0
  25. data/lib/spec_producer/rspec_builders/base.rb +148 -0
  26. data/lib/spec_producer/rspec_builders/builder.rb +220 -0
  27. data/lib/spec_producer/rspec_builders/matchers.rb +256 -0
  28. data/lib/spec_producer/spec_production_module.rb +80 -331
  29. data/lib/spec_producer/spec_runner.rb +14 -0
  30. data/lib/spec_producer/utils.rb +1 -0
  31. data/lib/spec_producer/utils/file_utils.rb +69 -0
  32. data/lib/spec_producer/version.rb +1 -1
  33. data/lib/tasks/spec_producer_tasks.rake +103 -0
  34. data/spec_producer.gemspec +6 -0
  35. metadata +111 -2
@@ -1,114 +1,6 @@
1
- module SpecProducer::SpecProductionModule
2
- def self.produce_specs_for_models
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 = "require '#{require_helper_string}'\n\n"
11
- final_text << "describe #{descendant.name}, :type => :model do\n"
12
-
13
- descendant.attribute_names.each do |attribute|
14
- final_text << " it { should respond_to :#{attribute}, :#{attribute}= }\n"
15
- end
16
-
17
- descendant.readonly_attributes.each do |attribute|
18
- final_text << " it { should have_readonly_attribute :#{attribute} }\n"
19
- end
20
-
21
- if descendant.validators.reject { |validator| validator.kind == :associated }.present?
22
- final_text << "\n # Validators\n"
23
- end
24
-
25
- descendant.validators.each do |validator|
26
- if validator.kind == :presence
27
- validator.attributes.each do |attribute|
28
- final_text << " it { should validate_presence_of :#{attribute} }\n"
29
- end
30
- elsif validator.kind == :uniqueness
31
- validator.attributes.each do |attribute|
32
- final_text << " it { should validate_uniqueness_of :#{attribute} }\n"
33
- end
34
- elsif validator.kind == :numericality
35
- validator.attributes.each do |attribute|
36
- final_text << " it { should validate_numericality_of :#{attribute} }\n"
37
- end
38
- elsif validator.kind == :acceptance
39
- validator.attributes.each do |attribute|
40
- final_text << " it { should validate_acceptance_of :#{attribute} }\n"
41
- end
42
- elsif validator.kind == :confirmation
43
- validator.attributes.each do |attribute|
44
- final_text << " it { should validate_confirmation_of :#{attribute} }\n"
45
- end
46
- elsif validator.kind == :length
47
- validator.attributes.each do |attribute|
48
- final_text << " it { should validate_length_of :#{attribute} }\n"
49
- end
50
- elsif validator.kind == :absence
51
- validator.attributes.each do |attribute|
52
- final_text << " it { should validate_absence_of :#{attribute} }\n"
53
- end
54
- end
55
- end
56
-
57
- if descendant.column_names.present?
58
- final_text << "\n # Columns\n"
59
- end
60
-
61
- descendant.column_names.each do |column_name|
62
- final_text << " it { should have_db_column :#{column_name} }\n"
63
- end
64
-
65
- if descendant.reflections.keys.present?
66
- final_text << "\n # Associations\n"
67
- end
68
-
69
- descendant.reflections.each_pair do |key, reflection|
70
- final_text << case reflection.macro
71
- when :belongs_to then " it { should belong_to(:#{key})#{produce_association_options(reflection)} }\n"
72
- when :has_one then " it { should have_one(:#{key})#{produce_association_options(reflection)} }\n"
73
- when :has_many then " it { should have_many(:#{key})#{produce_association_options(reflection)} }\n"
74
- when :has_and_belongs_to_many then " it { should have_and_belong_to_many(:#{key})#{produce_association_options(reflection)} }\n"
75
- end
76
- end
77
-
78
- final_text << "end"
79
-
80
- if File.exists?(Rails.root.join("spec/models/#{descendant.name.underscore}_spec.rb"))
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
90
- else
91
- check_if_spec_folder_exists
92
-
93
- unless Dir.exists? Rails.root.join("spec/models")
94
- puts "Generating spec/models directory"
95
- Dir.mkdir(Rails.root.join("spec/models"))
96
- end
97
-
98
- path = "spec/models/#{descendant.name.underscore}_spec.rb"
99
- puts "Producing model spec file for: #{path}"
100
- f = File.open("#{Rails.root.join(path)}", 'wb+')
101
- f.write(final_text)
102
- f.close
103
- end
104
- end
1
+ require 'colorize'
105
2
 
106
- nil
107
- rescue NameError
108
- puts "ActiveRecord is not set for this project. Skipping model specs production."
109
- rescue Exception => e
110
- puts "Exception '#{e}' was raised. Skipping model specs production."
111
- end
3
+ module SpecProducer::SpecProductionModule
112
4
 
113
5
  def self.produce_specs_for_routes
114
6
  routes = Rails.application.routes.routes.map do |route|
@@ -147,17 +39,17 @@ module SpecProducer::SpecProductionModule
147
39
  if File.open(Rails.root.join("spec/routing/#{route_group[0]}_routing_spec.rb")).read == final_text
148
40
  # nothing to do here, pre-existing content is the same :)
149
41
  else
150
- puts '#'*100
151
- puts "Please, check whether the following lines are included in: spec/routing/#{route_group[0]}_routing_spec.rb\n"
152
- puts '#'*100
153
- puts "\n"
42
+ puts ('#'*100).colorize(:light_blue)
43
+ puts "Please, check whether the following lines are included in: spec/routing/#{route_group[0]}_routing_spec.rb".colorize(:light_blue)
44
+ puts ('#'*100).colorize(:light_blue)
154
45
  puts final_text
46
+ puts "\n\n"
155
47
  end
156
48
  else
157
49
  check_if_spec_folder_exists
158
50
 
159
51
  unless Dir.exists? Rails.root.join("spec/routing")
160
- puts "Generating spec/routing directory"
52
+ puts "Generating spec/routing directory".colorize(:yellow)
161
53
  Dir.mkdir(Rails.root.join("spec/routing"))
162
54
  end
163
55
 
@@ -179,7 +71,7 @@ module SpecProducer::SpecProductionModule
179
71
  end
180
72
 
181
73
  path = "spec/routing/#{route_group[0]}_routing_spec.rb"
182
- puts "Producing routing spec file for: #{route_group[0]}"
74
+ puts "Producing routing spec file for: #{route_group[0]}".colorize(:green)
183
75
  f = File.open("#{Rails.root.join(path)}", 'wb+')
184
76
  f.write(final_text)
185
77
  f.close
@@ -188,7 +80,7 @@ module SpecProducer::SpecProductionModule
188
80
 
189
81
  nil
190
82
  rescue Exception => e
191
- puts "Exception '#{e}' was raised. Skipping route specs production."
83
+ puts "Exception '#{e}' was raised. Skipping route specs production.".colorize(:red)
192
84
  end
193
85
 
194
86
  def self.produce_specs_for_views
@@ -212,17 +104,20 @@ module SpecProducer::SpecProductionModule
212
104
  templates_in_file = file_content.scan(/render ('|")(?<template>\S*)('|")/).flatten.uniq
213
105
  partials_in_file = file_content.scan(/render :partial => ('|")(?<partial>\S*)('|")/).flatten.uniq
214
106
  links_in_file = file_content.scan(/<a.*href=\"(\S*)\".*>(.*)<\/a>/).uniq
107
+ conditions_in_file = file_content.scan(/if (?<condition>.*)%>/).flatten.uniq
108
+ unless_conditions_in_file = file_content.scan(/unless (?<condition>.*)%>/).flatten.uniq
109
+ submit_tags_in_file = file_content.scan(/submit_tag (?<value>.*),/).flatten.uniq
215
110
 
216
111
  file_name = "#{file.gsub('app/', 'spec/')}_spec.rb"
217
112
  final_text = "require '#{require_helper_string}'\n\n"
218
113
  final_text << "describe '#{file.gsub('app/views/', '')}', :type => :view do\n"
219
- final_text << " let(:page) { Capybara::Node::Simple.new(rendered) }\n\n"
114
+ final_text << " let(:page) { Capybara::Node::Simple.new(rendered) }\n"
220
115
 
221
116
  objects_in_file.each do |object|
222
- final_text << " let(:#{object}) { '#{object}' }\n"
117
+ final_text << "\n let(:#{object}) { '#{object}' }"
223
118
  end
224
-
225
- final_text << " subject { page }\n\n"
119
+
120
+ final_text << "\n subject { page }\n\n"
226
121
  final_text << " before do\n"
227
122
 
228
123
  objects_in_file.each do |object|
@@ -235,76 +130,39 @@ module SpecProducer::SpecProductionModule
235
130
  final_text << " describe 'content' do\n"
236
131
 
237
132
  fields_in_file.each do |field_name|
238
- final_text << " it { should have_field '#{ field_name }' }\n"
239
- end
133
+ final_text << " it { is_expected.to have_field '#{ field_name }' }\n"
134
+ end
135
+
136
+ submit_tags_in_file.each do |field_name|
137
+ final_text << " it { is_expected.to have_css \"input[type='submit'][value=#{ field_name }]\" }\n"
138
+ end
240
139
 
241
140
  templates_in_file.each do |template_name|
242
141
  template_path_elements = template_name.split('/')
243
142
  template_path_elements.last.gsub!(/^/, '_')
244
143
 
245
- final_text << " it { should render_template '#{ template_path_elements.join('/') }' }\n"
144
+ final_text << " it { is_expected.to render_template '#{ template_path_elements.join('/') }' }\n"
246
145
  end
247
146
 
248
147
  partials_in_file.each do |partial_name|
249
- final_text << " it { should render_template(:partial => '#{ partial_name }') }\n"
148
+ final_text << " it { is_expected.to render_template(:partial => '#{ partial_name }') }\n"
250
149
  end
251
150
 
252
151
  links_in_file.each do |link|
253
- final_text << " it { should have_link '#{link[1]}', :href => '#{link[0]}' }\n"
254
- end
255
-
256
- final_text << " pending 'view content test'\n"
257
- final_text << " end\n"
258
- final_text << "end\n"
259
-
260
- check_if_spec_folder_exists
261
-
262
- if File.exists?(Rails.root.join(file_name))
263
- if File.open(Rails.root.join(file_name)).read == final_text
264
- # nothing to do here, pre-existing content is the same :)
265
- else
266
- puts '#'*100
267
- puts "Please, check whether the following lines are included in: " + file_name + "\n"
268
- puts '#'*100
269
- puts "\n"
270
- puts final_text
271
- end
272
- else
273
- puts "Producing view spec file for: #{file_name}"
274
- f = File.open(file_name, 'wb+')
275
- f.write(final_text)
276
- f.close
152
+ final_text << " it { is_expected.to have_link '#{link[1]}', :href => '#{link[0]}' }\n"
277
153
  end
278
- end
279
154
 
280
- nil
281
- rescue Exception => e
282
- puts "Exception '#{e}' was raised. Skipping view specs production."
283
- end
284
-
285
- def self.produce_specs_for_helpers
286
- helpers_list = ActionController::Base.modules_for_helpers(ActionController::Base.all_helpers_from_path 'app/helpers')
287
-
288
- helpers_list.each do |helper|
289
- file_name = "spec/helpers/#{helper.name.gsub("::", "/").underscore}_spec.rb"
290
- full_path = 'spec'
291
- file_name.gsub("spec/", "").split("/").each do |path|
292
- unless /.*\.rb/.match path
293
- full_path << "/#{path}"
294
-
295
- unless Dir.exists? full_path
296
- Dir.mkdir(Rails.root.join(full_path))
297
- end
298
- end
155
+ conditions_in_file.each do |condition|
156
+ final_text << " pending 'if #{condition.strip}'\n"
299
157
  end
300
158
 
301
- final_text = "require '#{require_helper_string}'\n\n"
302
- final_text << "describe #{helper}, :type => :helper do\n"
303
- helper.instance_methods.each do |method_name|
304
- final_text << " pending '#{method_name.to_s}'\n"
159
+ unless_conditions_in_file.each do |condition|
160
+ final_text << " pending 'unless #{condition.strip}'\n"
305
161
  end
306
162
 
307
- final_text << "end"
163
+ final_text << " pending 'view content test'\n"
164
+ final_text << " end\n"
165
+ final_text << "end\n"
308
166
 
309
167
  check_if_spec_folder_exists
310
168
 
@@ -312,14 +170,14 @@ module SpecProducer::SpecProductionModule
312
170
  if File.open(Rails.root.join(file_name)).read == final_text
313
171
  # nothing to do here, pre-existing content is the same :)
314
172
  else
315
- puts '#'*100
316
- puts "Please, check whether the following lines are included in: " + file_name + "\n"
317
- puts '#'*100
318
- puts "\n"
173
+ puts ('#'*100).colorize(:light_blue)
174
+ puts ("Please, check whether the following lines are included in: " + file_name).colorize(:light_blue)
175
+ puts ('#'*100).colorize(:light_blue)
319
176
  puts final_text
177
+ puts "\n\n"
320
178
  end
321
179
  else
322
- puts "Producing helper spec file for: #{file_name}"
180
+ puts "Producing view spec file for: #{file_name}".colorize(:green)
323
181
  f = File.open(file_name, 'wb+')
324
182
  f.write(final_text)
325
183
  f.close
@@ -328,7 +186,7 @@ module SpecProducer::SpecProductionModule
328
186
 
329
187
  nil
330
188
  rescue Exception => e
331
- puts "Exception '#{e}' was raised. Skipping helper specs production."
189
+ puts "Exception '#{e}' was raised. Skipping view specs production.".colorize(:red)
332
190
  end
333
191
 
334
192
  def self.produce_specs_for_mailers
@@ -349,7 +207,17 @@ module SpecProducer::SpecProductionModule
349
207
  file_name = "#{file.gsub('app/', 'spec/').gsub('.rb', '')}_spec.rb"
350
208
  final_text = "require '#{require_helper_string}'\n\n"
351
209
  final_text << "describe #{File.basename(file, ".rb").camelcase}, :type => :mailer do\n"
352
- final_text << " pending 'mailer tests'\n"
210
+ final_text << " pending 'mailer tests' do\n"
211
+ final_text << " let(:mail) { #{File.basename(file, ".rb").camelcase}.action }\n"
212
+ final_text << " it 'renders the headers' do\n"
213
+ final_text << " expect(mail.subject).to eq('subject')\n"
214
+ final_text << " expect(mail.to).to eq('receiver@example.com')\n"
215
+ final_text << " expect(mail.from).to eq('sender@example.com')\n"
216
+ final_text << " end\n\n"
217
+ final_text << " it 'renders the body' do\n"
218
+ final_text << " expect(mail.body.encoded).to match('The body!')\n"
219
+ final_text << " end\n"
220
+ final_text << " end\n"
353
221
  final_text << "end"
354
222
 
355
223
  check_if_spec_folder_exists
@@ -358,14 +226,14 @@ module SpecProducer::SpecProductionModule
358
226
  if File.open(Rails.root.join(file_name)).read == final_text
359
227
  # nothing to do here, pre-existing content is the same :)
360
228
  else
361
- puts '#'*100
362
- puts "Please, check whether the following lines are included in: " + file_name + "\n"
363
- puts '#'*100
364
- puts "\n"
229
+ puts ('#'*100).colorize(:light_blue)
230
+ puts ("Please, check whether the following lines are included in: " + file_name).colorize(:light_blue)
231
+ puts ('#'*100).colorize(:light_blue)
365
232
  puts final_text
233
+ puts "\n\n"
366
234
  end
367
235
  else
368
- puts "Producing helper spec file for: #{file_name}"
236
+ puts "Producing helper spec file for: #{file_name}".colorize(:green)
369
237
  f = File.open(file_name, 'wb+')
370
238
  f.write(final_text)
371
239
  f.close
@@ -374,7 +242,7 @@ module SpecProducer::SpecProductionModule
374
242
 
375
243
  nil
376
244
  rescue Exception => e
377
- puts "Exception '#{e}' was raised. Skipping mailer specs production."
245
+ puts "Exception '#{e}' was raised. Skipping mailer specs production.".colorize(:red)
378
246
  end
379
247
 
380
248
  def self.produce_specs_for_jobs
@@ -395,135 +263,37 @@ module SpecProducer::SpecProductionModule
395
263
  file_name = "#{file.gsub('app/', 'spec/').gsub('.rb', '')}_spec.rb"
396
264
  final_text = "require '#{require_helper_string}'\n\n"
397
265
  final_text << "describe #{File.basename(file, ".rb").camelcase}, :type => :job do\n"
398
- final_text << " pending 'job tests'\n"
399
- final_text << "end"
400
-
401
- check_if_spec_folder_exists
402
-
403
- if File.exists?(Rails.root.join(file_name))
404
- if File.open(Rails.root.join(file_name)).read == final_text
405
- # nothing to do here, pre-existing content is the same :)
406
- else
407
- puts '#'*100
408
- puts "Please, check whether the following lines are included in: " + file_name + "\n"
409
- puts '#'*100
410
- puts "\n"
411
- puts final_text
412
- end
413
- else
414
- puts "Producing job spec file for: #{file_name}"
415
- f = File.open(file_name, 'wb+')
416
- f.write(final_text)
417
- f.close
418
- end
419
- end
420
-
421
- nil
422
- rescue Exception => e
423
- puts "Exception '#{e}' was raised. Skipping job specs production."
424
- end
425
-
426
- def self.produce_specs_for_serializers
427
- Dir.glob(Rails.root.join('app/serializers/*.rb')).each do |x|
428
- require x
429
- end
430
-
431
- not_valid_descendants = [ ActiveModel::Serializer::ErrorSerializer ]
432
-
433
- ActiveModel::Serializer.descendants.reject { |descendant| not_valid_descendants.include? descendant }.each do |descendant|
434
- final_text = "require '#{require_helper_string}'\n\n"
435
- final_text << "describe #{descendant.name}, :type => :serializer do\n"
436
-
437
- final_text << " describe 'serializer tests' do\n"
438
- final_text << " subject { #{descendant.name}.new(FactoryGirl.build(:#{descendant.name.underscore.gsub('_serializer', '')})) }\n\n"
439
- final_text << " it 'includes the expected attributes' do\n"
440
- final_text << " expect(subject.attributes.keys).to contain_exactly(#{descendant._attributes.map { |x| ":#{x.to_s}" }.join(', ')})\n"
441
- final_text << " expect(subject.attributes).to eq({})\n"
442
- final_text << " end\n"
266
+ final_text << " include ActiveJob::TestHelper\n\n"
267
+ final_text << " subject(:job) { described_class.perform_later(123) }\n\n"
268
+ final_text << " it 'queues the job' do\n"
269
+ final_text << " expect { job }.to change(ActiveJob::Base.queue_adapter.enqueued_jobs, :size).by(1)\n"
270
+ final_text << " end\n\n"
271
+ final_text << " it 'is in proper queue' do\n"
272
+ final_text << " expect(#{File.basename(file, ".rb").camelcase}.new.queue_name).to eq('default')\n"
273
+ final_text << " end\n\n"
274
+ final_text << " pending 'executes perform' do\n"
275
+ final_text << " perform_enqueued_jobs { job }\n"
276
+ final_text << " end\n\n"
277
+ final_text << " after do\n"
278
+ final_text << " clear_enqueued_jobs\n"
279
+ final_text << " clear_performed_jobs\n"
443
280
  final_text << " end\n"
444
281
  final_text << "end"
445
282
 
446
- if File.exists?(Rails.root.join("spec/serializers/#{descendant.name.underscore}_spec.rb"))
447
- if File.open(Rails.root.join("spec/serializers/#{descendant.name.underscore}_spec.rb")).read == final_text
448
- # nothing to do here, pre-existing content is the same :)
449
- else
450
- puts '#'*100
451
- puts "Please, check whether the following lines are included in: " + descendant.name.underscore + "_spec.rb\n"
452
- puts '#'*100
453
- puts "\n"
454
- puts final_text
455
- end
456
- else
457
- check_if_spec_folder_exists
458
-
459
- unless Dir.exists? Rails.root.join("spec/serializers")
460
- puts "Generating spec/serializers directory"
461
- Dir.mkdir(Rails.root.join("spec/serializers"))
462
- end
463
-
464
- path = "spec/serializers/#{descendant.name.underscore}_spec.rb"
465
- puts "Producing serializer spec file for: #{path}"
466
- f = File.open("#{Rails.root.join(path)}", 'wb+')
467
- f.write(final_text)
468
- f.close
469
- end
470
- end
471
-
472
- nil
473
- rescue Exception => e
474
- puts "Exception '#{e}' was raised. Skipping serializer specs production."
475
- end
476
-
477
- def self.produce_specs_for_controllers
478
- Dir.glob(Rails.root.join('app/controllers/**/*.rb')).each do |x|
479
- require x
480
- end
481
-
482
- controllers = ApplicationController.descendants
483
- controllers << ApplicationController
484
-
485
- controllers.each do |descendant|
486
- path_name = 'app/controllers/' + descendant.name.split('::').map { |name| name.underscore }.join('/')
487
-
488
- full_path = 'spec'
489
- File.dirname(path_name.gsub('app/', 'spec/')).split('/').reject { |path| path == 'spec' }.each do |path|
490
- unless /.*\.rb/.match path
491
- full_path << "/#{path}"
492
-
493
- unless Dir.exists? full_path
494
- Dir.mkdir(Rails.root.join(full_path))
495
- end
496
- end
497
- end
498
-
499
- file_name = "#{path_name.gsub('app/', 'spec/')}_spec.rb"
500
- final_text = "require '#{require_helper_string}'\n\n"
501
- final_text << "describe #{descendant.name}, :type => :controller do\n"
502
-
503
- descendant.action_methods.each do |method|
504
- final_text << " pending '##{method}'\n"
505
- end
506
-
507
- unless descendant.action_methods.size > 0
508
- final_text << " pending 'tests'\n"
509
- end
510
-
511
- final_text << "end\n"
512
-
513
283
  check_if_spec_folder_exists
514
284
 
515
285
  if File.exists?(Rails.root.join(file_name))
516
286
  if File.open(Rails.root.join(file_name)).read == final_text
517
287
  # nothing to do here, pre-existing content is the same :)
518
288
  else
519
- puts '#'*100
520
- puts "Please, check whether the following lines are included in: " + file_name + "\n"
521
- puts '#'*100
522
- puts "\n"
289
+ puts ('#'*100).colorize(:light_blue)
290
+ puts ("Please, check whether the following lines are included in: " + file_name).colorize(:light_blue)
291
+ puts ('#'*100).colorize(:light_blue)
523
292
  puts final_text
293
+ puts "\n\n"
524
294
  end
525
295
  else
526
- puts "Producing controller spec file for: #{file_name}"
296
+ puts "Producing job spec file for: #{file_name}".colorize(:green)
527
297
  f = File.open(file_name, 'wb+')
528
298
  f.write(final_text)
529
299
  f.close
@@ -532,33 +302,13 @@ module SpecProducer::SpecProductionModule
532
302
 
533
303
  nil
534
304
  rescue Exception => e
535
- puts "Exception '#{e}' was raised. Skipping controller specs production."
305
+ puts "Exception '#{e}' was raised. Skipping job specs production.".colorize(:red)
536
306
  end
537
307
 
538
308
  #######
539
309
  private
540
310
  #######
541
311
 
542
- def self.produce_association_options(reflection)
543
- return if reflection.options.empty?
544
-
545
- final_text = []
546
-
547
- reflection.options.each_pair do |key, value|
548
- final_text << case key
549
- when :inverse_of then "inverse_of(:#{value})"
550
- when :autosave then "autosave(#{value})"
551
- when :through then "through(:#{value})"
552
- when :class_name then "class_name('#{value}')"
553
- when :foreign_key then "with_foreign_key('#{value}')"
554
- when :primary_key then "with_primary_key('#{value}')"
555
- when :source then "source(:#{value})"
556
- when :dependent then "dependent(:#{value})"
557
- end
558
- end
559
- final_text.reject(&:nil?).join('.').prepend('.')
560
- end
561
-
562
312
  def self.require_helper_string
563
313
  @require_helper_string ||= collect_helper_strings
564
314
  end
@@ -578,19 +328,18 @@ module SpecProducer::SpecProductionModule
578
328
  if helper_strings_used.uniq.length == 1
579
329
  helper_strings_used.first
580
330
  else
581
- puts "More than one helpers are in place in your specs! Proceeding with 'rails_helpers'."
331
+ puts "More than one helpers are in place in your specs! Proceeding with 'rails_helpers'.".colorize(:yellow)
582
332
  'rails_helper'
583
333
  end
584
334
  end
585
335
 
586
336
  def self.check_if_spec_folder_exists
587
- unless Dir.exists? Rails.root.join("spec")
588
- puts "Generating spec directory"
589
- Dir.mkdir(Rails.root.join("spec"))
590
- end
337
+ unless Dir.exists? Rails.root.join("spec")
338
+ puts "Generating spec directory".colorize(:yellow)
339
+ Dir.mkdir(Rails.root.join("spec"))
340
+ end
591
341
  end
592
342
 
593
- private_class_method :produce_association_options
594
343
  private_class_method :require_helper_string
595
344
  private_class_method :collect_helper_strings
596
345
  private_class_method :check_if_spec_folder_exists