spec_producer 0.2.0 → 0.3.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 +8 -0
- data/README.md +52 -0
- data/lib/spec_producer.rb +145 -3
- data/lib/spec_producer/version.rb +1 -1
- 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: e4d531faa30c2413786add89ceb1e7fd20093fcd
|
4
|
+
data.tar.gz: b6b86d48100f3d9066015ed01cdd69140c4b86c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f55fead5c9f34409532db1c996b979a4f81e0f877df886c6db160d788007248f9c0b45c11c3f9d635019a695bdd925811e5072c339f88eaca1b341840f2ad9e7
|
7
|
+
data.tar.gz: 2680b09089dc157b18fb8c7b0fe88c97eab5076cfa8b767525ceaa44696336f95b67776c68df23f37ad92cb1b5f39d80ddcba5a53b2a4ce2fe6325a3c85fb484
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 0.3.0 (2016-06-12)
|
2
|
+
|
3
|
+
Features:
|
4
|
+
* Added some activemodel specs through shoulda matchers
|
5
|
+
* Added produce_specs_for_views to produce spec files with pending indications for all Views.
|
6
|
+
* Added produce_specs_for_helpers to produce spec files with pending indications for all Helpers.
|
7
|
+
* Added produce_specs_for_controllers to produce spec files with pending indications for all Controllers.
|
8
|
+
|
1
9
|
## 0.2.0 (2016-06-04)
|
2
10
|
|
3
11
|
Features:
|
data/README.md
CHANGED
@@ -42,6 +42,58 @@ To produce all tests for routes, run:
|
|
42
42
|
SpecProducer.produce_specs_for_routes
|
43
43
|
```
|
44
44
|
|
45
|
+
To produce all spec files for views, run:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
SpecProducer.produce_specs_for_views
|
49
|
+
```
|
50
|
+
```
|
51
|
+
|
52
|
+
To produce all spec files for helpers, run:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
SpecProducer.produce_specs_for_helpers
|
56
|
+
```
|
57
|
+
|
58
|
+
To produce all spec files for controllers, run:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
SpecProducer.produce_specs_for_controllers
|
62
|
+
```
|
63
|
+
|
64
|
+
Additionally this gem (from version 0.2.0) allows users to print all their missing spec files by reading all
|
65
|
+
directories for Views, Models, Controllers and Helpers.
|
66
|
+
|
67
|
+
To print all types of missing tests, run:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
SpecProducer.print_all_missing_spec_files
|
71
|
+
```
|
72
|
+
|
73
|
+
To print all missing model tests, run:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
SpecProducer.print_missing_model_specs
|
77
|
+
```
|
78
|
+
|
79
|
+
To print all missing controller tests, run:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
SpecProducer.print_missing_controller_specs
|
83
|
+
```
|
84
|
+
|
85
|
+
To print all missing helper tests, run:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
SpecProducer.print_missing_helper_specs
|
89
|
+
```
|
90
|
+
|
91
|
+
To print all missing view tests, run:
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
SpecProducer.print_missing_view_specs
|
95
|
+
```
|
96
|
+
|
45
97
|
## Development
|
46
98
|
|
47
99
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/spec_producer.rb
CHANGED
@@ -4,6 +4,9 @@ module SpecProducer
|
|
4
4
|
def self.produce_specs_for_all_types
|
5
5
|
produce_specs_for_models
|
6
6
|
produce_specs_for_routes
|
7
|
+
produce_specs_for_views
|
8
|
+
produce_specs_for_controllers
|
9
|
+
produce_specs_for_helpers
|
7
10
|
end
|
8
11
|
|
9
12
|
def self.produce_specs_for_models
|
@@ -12,13 +15,41 @@ module SpecProducer
|
|
12
15
|
end
|
13
16
|
|
14
17
|
ActiveRecord::Base.descendants.each do |descendant|
|
15
|
-
final_text = "require 'rails_helper'\n"
|
18
|
+
final_text = "require 'rails_helper'\n\n"
|
16
19
|
final_text << "describe #{descendant.name} do\n"
|
17
20
|
|
18
21
|
descendant.attribute_names.each do |attribute|
|
19
22
|
final_text << "\tit { should respond_to :#{attribute}, :#{attribute}= }\n"
|
20
23
|
end
|
21
24
|
|
25
|
+
descendant.validators.each do |validator|
|
26
|
+
if validator.kind == :presence
|
27
|
+
validator.attributes.each do |attribute|
|
28
|
+
final_text << "\tit { should validate_presence_of :#{attribute} }\n"
|
29
|
+
end
|
30
|
+
elsif validator.kind == :uniqueness
|
31
|
+
validator.attributes.each do |attribute|
|
32
|
+
final_text << "\tit { should validate_uniqueness_of :#{attribute} }\n"
|
33
|
+
end
|
34
|
+
elsif validator.kind == :numericality
|
35
|
+
validator.attributes.each do |attribute|
|
36
|
+
final_text << "\tit { should validate_numericality_of :#{attribute} }\n"
|
37
|
+
end
|
38
|
+
elsif validator.kind == :acceptance
|
39
|
+
validator.attributes.each do |attribute|
|
40
|
+
final_text << "\tit { should validate_acceptance_of :#{attribute} }\n"
|
41
|
+
end
|
42
|
+
elsif validator.kind == :confirmation
|
43
|
+
validator.attributes.each do |attribute|
|
44
|
+
final_text << "\tit { should validate_confirmation_of :#{attribute} }\n"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
descendant.column_names.each do |column_name|
|
50
|
+
final_text << "\tit { should have_db_column :#{column_name} }\n"
|
51
|
+
end
|
52
|
+
|
22
53
|
final_text << "end"
|
23
54
|
|
24
55
|
if File.exists?(Rails.root.join("spec/models/#{descendant.name.downcase}_spec.rb"))
|
@@ -67,11 +98,11 @@ module SpecProducer
|
|
67
98
|
final_text << "\t\t\tshould route_to(:controller => '#{route[:controller]}',\n"
|
68
99
|
|
69
100
|
/:[a-zA-Z_]+/.match(route[:path]).to_a.each do |parameter|
|
70
|
-
final_text << "\t\t\t\t\t#{parameter} => '#{parameter.gsub(':','').upcase}',\n"
|
101
|
+
final_text << "\t\t\t\t\t\t\t#{parameter} => '#{parameter.gsub(':','').upcase}',\n"
|
71
102
|
end
|
72
103
|
|
73
104
|
final_text << "\t\t\t\t\t:action => '#{route[:action]}')\n"
|
74
|
-
final_text << "\
|
105
|
+
final_text << "\tend\n\n"
|
75
106
|
end
|
76
107
|
|
77
108
|
final_text << 'end'
|
@@ -99,6 +130,117 @@ module SpecProducer
|
|
99
130
|
nil
|
100
131
|
end
|
101
132
|
|
133
|
+
def self.produce_specs_for_views
|
134
|
+
files_list = Dir["app/views/**/*.erb"]
|
135
|
+
|
136
|
+
files_list.each do |file|
|
137
|
+
full_path = 'spec'
|
138
|
+
File.dirname(file.gsub('app/', 'spec/')).split('/').reject { |path| path == 'spec' }.each do |path|
|
139
|
+
unless /.*\.erb/.match path
|
140
|
+
full_path << "/#{path}"
|
141
|
+
|
142
|
+
unless Dir.exists? full_path
|
143
|
+
Dir.mkdir(Rails.root.join(full_path))
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
file_name = "#{file.gsub('app/', 'spec/')}_spec.rb"
|
149
|
+
final_text = "require 'rails_helper'\n\n"
|
150
|
+
final_text << "describe '#{file.gsub('app/views/', '')}' do\n"
|
151
|
+
final_text << "\tbefore do\n"
|
152
|
+
final_text << "\t\trender\n"
|
153
|
+
final_text << "\tend\n\n"
|
154
|
+
final_text << "\tpending 'view content test'\n"
|
155
|
+
final_text << "end\n"
|
156
|
+
|
157
|
+
unless FileTest.exists?(file_name)
|
158
|
+
f = File.open(file_name, 'wb+')
|
159
|
+
f.write(final_text)
|
160
|
+
f.close
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
nil
|
165
|
+
end
|
166
|
+
|
167
|
+
def self.produce_specs_for_helpers
|
168
|
+
files_list = Dir["app/helpers/**/*.rb"]
|
169
|
+
|
170
|
+
files_list.each do |file|
|
171
|
+
full_path = 'spec'
|
172
|
+
File.dirname(file.gsub('app/', 'spec/')).split('/').reject { |path| path == 'spec' }.each do |path|
|
173
|
+
unless /.*\.rb/.match path
|
174
|
+
full_path << "/#{path}"
|
175
|
+
|
176
|
+
unless Dir.exists? full_path
|
177
|
+
Dir.mkdir(Rails.root.join(full_path))
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
file_name = "#{file.gsub('app/', 'spec/').gsub('.rb', '')}_spec.rb"
|
183
|
+
final_text = "require 'rails_helper'\n\n"
|
184
|
+
final_text << "describe #{File.basename(file, ".rb").camelcase} do\n"
|
185
|
+
final_text << "\tpending 'view helper tests'\n"
|
186
|
+
final_text << "end"
|
187
|
+
|
188
|
+
unless FileTest.exists?(file_name)
|
189
|
+
f = File.open(file_name, 'wb+')
|
190
|
+
f.write(final_text)
|
191
|
+
f.close
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
nil
|
196
|
+
end
|
197
|
+
|
198
|
+
def self.produce_specs_for_controllers
|
199
|
+
Dir.glob(Rails.root.join('app/controllers/*.rb')).each do |x|
|
200
|
+
require x
|
201
|
+
end
|
202
|
+
|
203
|
+
controllers = ApplicationController.descendants
|
204
|
+
controllers << ApplicationController
|
205
|
+
|
206
|
+
controllers.each do |descendant|
|
207
|
+
path_name = 'app/controllers/' + descendant.name.split('::').map { |name| name.underscore }.join('/')
|
208
|
+
|
209
|
+
full_path = 'spec'
|
210
|
+
File.dirname(path_name.gsub('app/', 'spec/')).split('/').reject { |path| path == 'spec' }.each do |path|
|
211
|
+
unless /.*\.rb/.match path
|
212
|
+
full_path << "/#{path}"
|
213
|
+
|
214
|
+
unless Dir.exists? full_path
|
215
|
+
Dir.mkdir(Rails.root.join(full_path))
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
file_name = "#{path_name.gsub('app/', 'spec/')}_spec.rb"
|
221
|
+
final_text = "require 'rails_helper'\n\n"
|
222
|
+
final_text << "describe #{descendant.name} do\n"
|
223
|
+
|
224
|
+
descendant.action_methods.each do |method|
|
225
|
+
final_text << "\tpending '##{method}'\n"
|
226
|
+
end
|
227
|
+
|
228
|
+
unless descendant.action_methods.size > 0
|
229
|
+
final_text << "\tpending 'tests'\n"
|
230
|
+
end
|
231
|
+
|
232
|
+
final_text << "end\n"
|
233
|
+
|
234
|
+
unless FileTest.exists?(file_name)
|
235
|
+
f = File.open(file_name, 'wb+')
|
236
|
+
f.write(final_text)
|
237
|
+
f.close
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
nil
|
242
|
+
end
|
243
|
+
|
102
244
|
def self.print_all_missing_spec_files
|
103
245
|
print_missing_model_specs
|
104
246
|
print_missing_controller_specs
|
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.3.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-06-
|
11
|
+
date: 2016-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|