spec_producer 0.11.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,14 @@
1
+ module SpecProducer
2
+ module SpecRunner
3
+ module_function
4
+
5
+ def run(spec_types = [])
6
+ puts "\nRunning related spec tests...\n"
7
+
8
+ system 'bundle exec rake' if spec_types.empty?
9
+ spec_types.each do |type|
10
+ system "bundle exec rspec spec/#{type}"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1 @@
1
+ require 'spec_producer/utils/file_utils'
@@ -0,0 +1,69 @@
1
+ module SpecProducer
2
+ module Utils
3
+ module FileUtils
4
+ module_function
5
+
6
+ def try_to_create_spec_file(context, filename, final_text)
7
+ if File.exists?(Rails.root.join("spec/#{context}/#{filename}_spec.rb"))
8
+ if File.open(Rails.root.join("spec/#{context}/#{filename}_spec.rb")).read == final_text
9
+ # nothing to do here, pre-existing content is the same :)
10
+ else
11
+ puts ('#'*100).colorize(:light_blue)
12
+ puts ("Please, check whether the following lines are included in: " + filename + "_spec.rb").colorize(:light_blue)
13
+ puts ('#'*100).colorize(:light_blue)
14
+ puts final_text
15
+ puts "\n\n"
16
+ end
17
+ else
18
+ unless Dir.exists? Rails.root.join("spec")
19
+ puts "Generating spec directory".colorize(:yellow)
20
+ Dir.mkdir(Rails.root.join("spec"))
21
+ end
22
+
23
+ unless Dir.exists? Rails.root.join("spec/#{context}")
24
+ puts "Generating spec/#{context} directory".colorize(:yellow)
25
+ Dir.mkdir(Rails.root.join("spec/#{context}"))
26
+ end
27
+
28
+ full_path = 'spec'
29
+ File.dirname("spec/#{context}/#{filename}_spec.rb").split('/').reject { |path| path == 'spec' }.each do |path|
30
+ unless /.*\.erb/.match path
31
+ full_path << "/#{path}"
32
+
33
+ unless Dir.exists? full_path
34
+ puts "Generating #{full_path} directory".colorize(:yellow)
35
+ Dir.mkdir(Rails.root.join(full_path))
36
+ end
37
+ end
38
+ end
39
+
40
+ path = "spec/#{context}/#{filename}_spec.rb"
41
+ puts "Producing spec file for: #{path}".colorize(:green)
42
+ f = File.open("#{Rails.root.join(path)}", 'wb+')
43
+ f.write(final_text)
44
+ f.close
45
+ end
46
+ end
47
+
48
+ def collect_helper_strings
49
+ spec_files = Dir.glob(Rails.root.join('spec/**/*_spec.rb'))
50
+ helper_strings_used = []
51
+
52
+ spec_files.each do |file|
53
+ helper = /require \'(?<helpers>\S*)\'/.match File.read(file)
54
+
55
+ helper_strings_used << helper[1] if helper.present?
56
+ end
57
+
58
+ helper_strings_used.compact!
59
+
60
+ if helper_strings_used.uniq.length == 1
61
+ "#{helper_strings_used.first}"
62
+ else
63
+ puts "More than one helpers are in place in your specs! Proceeding with 'rails_helpers'.".colorize(:yellow)
64
+ "rails_helper"
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -1,3 +1,3 @@
1
1
  module SpecProducer
2
- VERSION = "0.11.0"
2
+ VERSION = "0.13.0"
3
3
  end
@@ -0,0 +1,103 @@
1
+ namespace :spec_producer do
2
+ desc 'Produces controller specs files'
3
+ task :controllers => :environment do
4
+ SpecProducer.produce(only: :controllers)
5
+ end
6
+
7
+ desc 'Produces FactoryGirl factory files for each model'
8
+ task :factories => :environment do
9
+ SpecProducer.produce_factories
10
+ end
11
+
12
+ desc 'Checks if there are any of the suggested gems for testing missing from your Gemfile and adds them'
13
+ task :set_up_necessities => :environment do
14
+ SpecProducer.set_up_necessities
15
+ end
16
+
17
+ desc 'Produces helper specs files'
18
+ task :helpers => :environment do
19
+ SpecProducer.produce(only: :helpers)
20
+ end
21
+
22
+ desc 'Produces job specs files'
23
+ task :jobs => :environment do
24
+ SpecProducer.produce(only: :jobs)
25
+ end
26
+
27
+ desc 'Produces mailer specs files'
28
+ task :mailers => :environment do
29
+ SpecProducer.produce(only: :mailers)
30
+ end
31
+
32
+ desc 'Produces model specs files'
33
+ task :models => :environment do
34
+ SpecProducer.produce(only: :models)
35
+ end
36
+
37
+ desc 'Produces route specs files'
38
+ task :routes => :environment do
39
+ SpecProducer.produce(only: :routes)
40
+ end
41
+
42
+ desc 'Produces serializer specs files'
43
+ task :serializers => :environment do
44
+ SpecProducer.produce(only: :serializers)
45
+ end
46
+
47
+ desc 'Produces view specs files'
48
+ task :views => :environment do
49
+ SpecProducer.produce(only: :views)
50
+ end
51
+
52
+ desc 'Produces all spec files the current gem supports'
53
+ task :all => :environment do
54
+ SpecProducer.produce()
55
+ end
56
+ end
57
+
58
+ namespace :missing_specs_printer do
59
+ desc 'Prints missing view spec files'
60
+ task :views => :environment do
61
+ SpecProducer.print_missing_view_specs()
62
+ end
63
+
64
+ desc 'Prints missing controller spec files'
65
+ task :controllers => :environment do
66
+ SpecProducer.print_missing_controller_specs()
67
+ end
68
+
69
+ desc 'Prints missing job spec files'
70
+ task :jobs => :environment do
71
+ SpecProducer.print_missing_job_specs()
72
+ end
73
+
74
+ desc 'Prints missing helper spec files'
75
+ task :helpers => :environment do
76
+ SpecProducer.print_missing_helper_specs()
77
+ end
78
+
79
+ desc 'Prints missing mailer spec files'
80
+ task :mailers => :environment do
81
+ SpecProducer.print_missing_mailer_specs()
82
+ end
83
+
84
+ desc 'Prints missing model spec files'
85
+ task :models => :environment do
86
+ SpecProducer.print_missing_model_specs()
87
+ end
88
+
89
+ desc 'Prints missing route spec files'
90
+ task :routes => :environment do
91
+ SpecProducer.print_missing_route_specs()
92
+ end
93
+
94
+ desc 'Prints missing serializer spec files'
95
+ task :serializers => :environment do
96
+ SpecProducer.print_missing_serializer_specs()
97
+ end
98
+
99
+ desc 'Prints all types of missing spec files'
100
+ task :all => :environment do
101
+ SpecProducer.print_all_missing_spec_files()
102
+ end
103
+ end
@@ -22,4 +22,10 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "bundler", "~> 1.10"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "sqlite3"
26
+ spec.add_development_dependency "factory_girl"
27
+ spec.add_development_dependency "shoulda-matchers"
28
+ spec.add_runtime_dependency "active_model_serializers"
29
+ spec.add_runtime_dependency "colorize"
30
+ spec.add_runtime_dependency "rails"
25
31
  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.11.0
4
+ version: 0.13.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-18 00:00:00.000000000 Z
11
+ date: 2017-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,90 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: factory_girl
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: shoulda-matchers
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: active_model_serializers
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: colorize
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rails
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
55
139
  description: This gem reads through the files of the rails app and produces as many
56
140
  specs as possible.
57
141
  email:
@@ -62,6 +146,7 @@ extra_rdoc_files: []
62
146
  files:
63
147
  - ".gitignore"
64
148
  - ".rspec"
149
+ - ".ruby-version"
65
150
  - ".travis.yml"
66
151
  - CHANGELOG.md
67
152
  - CODE_OF_CONDUCT.md
@@ -71,11 +156,35 @@ files:
71
156
  - Rakefile
72
157
  - bin/console
73
158
  - bin/setup
159
+ - lib/configuration.rb
160
+ - lib/generators/spec_producer/install/install_generator.rb
161
+ - lib/generators/spec_producer/install/templates/spec_producer
74
162
  - lib/spec_producer.rb
75
163
  - lib/spec_producer/factories_production_module.rb
76
164
  - lib/spec_producer/missing_files_module.rb
165
+ - lib/spec_producer/missing_gems_module.rb
166
+ - lib/spec_producer/producers.rb
167
+ - lib/spec_producer/producers/base.rb
168
+ - lib/spec_producer/producers/controllers_producer.rb
169
+ - lib/spec_producer/producers/helpers_producer.rb
170
+ - lib/spec_producer/producers/jobs_producer.rb
171
+ - lib/spec_producer/producers/mailers_producer.rb
172
+ - lib/spec_producer/producers/models_producer.rb
173
+ - lib/spec_producer/producers/registry.rb
174
+ - lib/spec_producer/producers/routes_producer.rb
175
+ - lib/spec_producer/producers/serializers_producer.rb
176
+ - lib/spec_producer/producers/views_producer.rb
177
+ - lib/spec_producer/railtie.rb
178
+ - lib/spec_producer/rspec_builders.rb
179
+ - lib/spec_producer/rspec_builders/base.rb
180
+ - lib/spec_producer/rspec_builders/builder.rb
181
+ - lib/spec_producer/rspec_builders/matchers.rb
77
182
  - lib/spec_producer/spec_production_module.rb
183
+ - lib/spec_producer/spec_runner.rb
184
+ - lib/spec_producer/utils.rb
185
+ - lib/spec_producer/utils/file_utils.rb
78
186
  - lib/spec_producer/version.rb
187
+ - lib/tasks/spec_producer_tasks.rake
79
188
  - spec_producer.gemspec
80
189
  homepage: https://rubygems.org/gems/spec_producer
81
190
  licenses: