missing_rspec 0.0.2 → 0.1.2
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +40 -7
- data/lib/missing_rspec/core.rb +16 -25
- data/lib/missing_rspec/creator.rb +74 -0
- data/lib/missing_rspec/module_name.rb +77 -0
- data/lib/missing_rspec/{directory.rb → tree.rb} +1 -1
- data/lib/missing_rspec/version.rb +1 -1
- data/lib/missing_rspec/viewer.rb +30 -0
- data/lib/tasks/missing_rspec.rake +7 -2
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c77461cf31c770b16004fd024396d8d96cacf2f2ded526e2f9cf32d8958290ed
|
4
|
+
data.tar.gz: b01d1871f9aecc8ba9ca299864b2a639a0c5376948fb5d3401225ccfcb4756b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d761bdccc8e153a66a60af9a4a8b4c6e8c57bbae849d57fff7a244e2a0ba05aa59e660e8eda27252a99916bd0720498e7276e76ee4b5c31959b1711b8bb1957
|
7
|
+
data.tar.gz: 2f0c8d94b311a05ff805004fec31c8880c55d1abfcd77e59b02cb73dd189c80b0008fab36cd15a87438de06bde1e0106a4c889bf784e730deb0e9a7ed8088065
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -10,14 +10,10 @@ To use it, add it to your Gemfile:
|
|
10
10
|
gem 'missing_rspec', group: :development
|
11
11
|
```
|
12
12
|
|
13
|
-
##
|
13
|
+
## How to use the preview
|
14
14
|
|
15
15
|
### How to specify rails path as an argument to rake
|
16
16
|
|
17
|
-
```shell
|
18
|
-
bin/rails runner "puts Rails.root.to_s"
|
19
|
-
```
|
20
|
-
|
21
17
|
Example when rails path is /app
|
22
18
|
|
23
19
|
```shell
|
@@ -41,10 +37,19 @@ RAILS_APP_PATH=/app
|
|
41
37
|
```shell
|
42
38
|
bin/rails missing_rspec
|
43
39
|
```
|
44
|
-
|
40
|
+
|
41
|
+
### The second argument can be used to narrow down the target.
|
42
|
+
|
43
|
+
The following is an example of specifying models, controllers and jobs.
|
44
|
+
|
45
|
+
```shell
|
46
|
+
bin/rails missing_rspec[/app,models\;controllers\;jobs]
|
47
|
+
```
|
48
|
+
|
49
|
+
### Execution example
|
45
50
|
|
46
51
|
```shell
|
47
|
-
|
52
|
+
bin/rails missing_rspec
|
48
53
|
|
49
54
|
|
50
55
|
|
@@ -157,6 +162,34 @@ The following folders are targeted: ["channels", "controllers", "forms", "helper
|
|
157
162
|
└<staff>
|
158
163
|
```
|
159
164
|
|
165
|
+
## How to use the creator
|
166
|
+
Note: Due to the large number of rspec files to be written, It is recommended that you git-commit the file before executing it so that you can revert it.
|
167
|
+
### Create all RSpecs shown in preview.
|
168
|
+
|
169
|
+
Example when rails path is /app
|
170
|
+
|
171
|
+
```shell
|
172
|
+
bin/rails missing_rspec_create[/app]
|
173
|
+
```
|
174
|
+
|
175
|
+
Example .env file when rails path is /app
|
176
|
+
|
177
|
+
```shell
|
178
|
+
RAILS_APP_PATH=/app
|
179
|
+
```
|
180
|
+
|
181
|
+
```shell
|
182
|
+
bin/rails missing_rspec_create
|
183
|
+
```
|
184
|
+
|
185
|
+
### The second argument can be used to narrow down the target.
|
186
|
+
|
187
|
+
The following is an example of specifying models, controllers and jobs.
|
188
|
+
|
189
|
+
```shell
|
190
|
+
bin/rails missing_rspec_create[/app,models\;controllers\;jobs]
|
191
|
+
```
|
192
|
+
|
160
193
|
## Contributing
|
161
194
|
|
162
195
|
Bug reports and pull requests are welcome on GitHub at https://github.com/kayamak/missing_rspec. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/kayamak/missing_rspec).
|
data/lib/missing_rspec/core.rb
CHANGED
@@ -1,35 +1,26 @@
|
|
1
|
-
require 'missing_rspec/directory'
|
2
1
|
require 'missing_rspec/folder_types_finder'
|
3
|
-
require 'missing_rspec/
|
2
|
+
require 'missing_rspec/viewer'
|
3
|
+
require 'missing_rspec/creator'
|
4
4
|
|
5
5
|
module MissingRspec
|
6
6
|
class Core
|
7
|
-
|
7
|
+
def self.execute(mode:, app_path:, folder_type:)
|
8
|
+
app_path ||= ENV['RAILS_APP_PATH']
|
9
|
+
raise "Set the rails app path to the rake argument or the environment variable RAILS_APP_PATH." unless app_path
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
def execute
|
16
|
-
folder_types = MissingRspec::FolderTypesFinder.new(app_path).fetch_folder_types
|
17
|
-
puts "The following folders are targeted: #{folder_types}"
|
18
|
-
folder_types.each do |folder_type|
|
19
|
-
missing_tree = create_missing_tree(folder_type)
|
20
|
-
print_tree(missing_tree)
|
11
|
+
folder_type ||= 'all'
|
12
|
+
folder_types = MissingRspec::FolderTypesFinder.new(app_path).fetch_folder_types
|
13
|
+
if folder_type != 'all'
|
14
|
+
folder_types &&= folder_type.split(';').map!(&:strip)
|
21
15
|
end
|
16
|
+
puts "The following folders are targeted: #{folder_types}"
|
22
17
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
def print_tree(tree)
|
32
|
-
puts tree.join("\n")
|
18
|
+
case mode
|
19
|
+
when :viewer
|
20
|
+
MissingRspec::Viewer.new(app_path: app_path, folder_types: folder_types).execute
|
21
|
+
when :creator
|
22
|
+
MissingRspec::Creator.new(app_path: app_path, folder_types: folder_types).execute
|
23
|
+
end
|
33
24
|
end
|
34
25
|
end
|
35
26
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'missing_rspec/tree'
|
2
|
+
require 'missing_rspec/module_name'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
module MissingRspec
|
6
|
+
class Creator
|
7
|
+
attr_reader :app_path, :folder_types
|
8
|
+
|
9
|
+
def initialize(app_path:, folder_types:)
|
10
|
+
# e.g. app_path:/app
|
11
|
+
@app_path = app_path
|
12
|
+
@folder_types = folder_types
|
13
|
+
end
|
14
|
+
|
15
|
+
def execute
|
16
|
+
folder_types.each do |folder_type|
|
17
|
+
rspecs_per_module_name = fetch_rspecs_per_module_name(folder_type)
|
18
|
+
create_rspecs(folder_type, rspecs_per_module_name)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def fetch_rspecs_per_module_name(folder_type)
|
25
|
+
MissingRspec::ModuleName.new(app_path: app_path, folder_type: folder_type).rspecs_per_module_name
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_rspecs(folder_type, rspecs_per_module_name)
|
29
|
+
rspecs_per_module_name.each do |module_name, rspecs|
|
30
|
+
rspec_full_path = make_rspec_full_path(folder_type, module_name)
|
31
|
+
|
32
|
+
rspecs.each do |rspec|
|
33
|
+
rspec_file_name = rspec.sub(/.rb$/, '_spec.rb')
|
34
|
+
rspec_full_path_file_name = "#{rspec_full_path}#{rspec_file_name}"
|
35
|
+
class_name = rspec.sub(/.rb$/, '').classify
|
36
|
+
full_class_name = build_full_class_name(module_name, class_name)
|
37
|
+
rspec_content = build_rspec_content(full_class_name, folder_type)
|
38
|
+
|
39
|
+
write_rspec_content(rspec_full_path_file_name, rspec_content)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def build_full_class_name(module_name, class_name)
|
45
|
+
if module_name == "Concerns"
|
46
|
+
"#{'"'}#{class_name}#{'"'}"
|
47
|
+
else
|
48
|
+
"#{module_name}#{module_name.blank? ? '' : '::'}#{class_name}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def make_rspec_full_path(folder_type, module_name)
|
53
|
+
module_path = module_name.split('::').map(&:underscore).join('/')
|
54
|
+
rspec_full_path = "#{app_path}/spec/#{folder_type}/#{module_path}#{module_path.blank? ? '' : '/'}"
|
55
|
+
FileUtils.mkdir_p(rspec_full_path)
|
56
|
+
rspec_full_path
|
57
|
+
end
|
58
|
+
|
59
|
+
def build_rspec_content(full_class_name, folder_type)
|
60
|
+
<<~EOS
|
61
|
+
# rubocop:disable Lint/EmptyBlock
|
62
|
+
RSpec.describe #{full_class_name}, type: :#{folder_type.singularize} do
|
63
|
+
end
|
64
|
+
# rubocop:enaable Lint/EmptyBlock
|
65
|
+
EOS
|
66
|
+
end
|
67
|
+
|
68
|
+
def write_rspec_content(rspec_full_path_file_name, rspec_content)
|
69
|
+
File.open(rspec_full_path_file_name, "w") do |io|
|
70
|
+
io.write(rspec_content)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'pry'
|
2
|
+
|
3
|
+
module MissingRspec
|
4
|
+
class ModuleName
|
5
|
+
attr_reader :app_path, :folder_type
|
6
|
+
|
7
|
+
def initialize(app_path:, folder_type:)
|
8
|
+
@app_path = app_path
|
9
|
+
@folder_type = folder_type
|
10
|
+
end
|
11
|
+
|
12
|
+
def rspecs_per_module_name
|
13
|
+
original_module_names = make_original_module_names
|
14
|
+
spec_module_names = make_spec_module_names
|
15
|
+
|
16
|
+
target_module_names = find_rspecs_per_module_name(original_module_names, spec_module_names)
|
17
|
+
target_module_names
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def make_original_module_names
|
23
|
+
models_path = "#{app_path}/app/#{folder_type}"
|
24
|
+
fetch_module_names(target_path: models_path, is_rspec: false)
|
25
|
+
end
|
26
|
+
|
27
|
+
def make_spec_module_names
|
28
|
+
spec_models_path = "#{app_path}/spec/#{folder_type}"
|
29
|
+
fetch_module_names(target_path: spec_models_path, is_rspec: true)
|
30
|
+
end
|
31
|
+
|
32
|
+
def fetch_module_names(target_path: ,is_rspec:)
|
33
|
+
unless File.directory?(target_path)
|
34
|
+
if folder_type == target_path.split('/').last
|
35
|
+
return {}
|
36
|
+
end
|
37
|
+
raise "#{target_path} is not directory."
|
38
|
+
end
|
39
|
+
|
40
|
+
result = Hash.new{ |hash, key| hash[key] = [] }
|
41
|
+
|
42
|
+
trace_dir = lambda do |dir, module_name|
|
43
|
+
Dir.chdir(dir)
|
44
|
+
dir_files = Dir.glob('*').sort
|
45
|
+
lower_dirs = dir_files.select { |df| File.directory?(df) }
|
46
|
+
files = dir_files - lower_dirs
|
47
|
+
|
48
|
+
lower_dirs.each do |lower_dir|
|
49
|
+
lower_module_name = "#{module_name}#{module_name.blank? ? '' : '::'}#{lower_dir.camelize}"
|
50
|
+
trace_dir.call(lower_dir, lower_module_name)
|
51
|
+
end
|
52
|
+
|
53
|
+
files.each do |file|
|
54
|
+
next unless /.rb$/ =~ file
|
55
|
+
|
56
|
+
replaced_file = is_rspec ? file.sub(/_spec.rb$/, '.rb') : file
|
57
|
+
result[module_name] << replaced_file
|
58
|
+
end
|
59
|
+
|
60
|
+
Dir.chdir('..')
|
61
|
+
end
|
62
|
+
trace_dir.call(target_path, '')
|
63
|
+
|
64
|
+
result
|
65
|
+
end
|
66
|
+
|
67
|
+
def find_rspecs_per_module_name(original_module_names, spec_module_names)
|
68
|
+
target_module_names = Hash.new{ |hash, key| hash[key] = [] }
|
69
|
+
original_module_names.each do |module_name, rb_files|
|
70
|
+
spec_files = spec_module_names[module_name] || []
|
71
|
+
target_files = rb_files - spec_files
|
72
|
+
target_module_names[module_name] = target_files if target_files.present?
|
73
|
+
end
|
74
|
+
target_module_names
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'missing_rspec/tree'
|
2
|
+
require 'missing_rspec/version'
|
3
|
+
|
4
|
+
module MissingRspec
|
5
|
+
class Viewer
|
6
|
+
attr_reader :app_path, :folder_types
|
7
|
+
|
8
|
+
def initialize(app_path:, folder_types:)
|
9
|
+
# e.g. app_path:/app
|
10
|
+
@app_path = app_path
|
11
|
+
@folder_types = folder_types
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute
|
15
|
+
folder_types.each do |folder_type|
|
16
|
+
missing_tree = create_missing_tree(folder_type)
|
17
|
+
print_tree(missing_tree)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def create_missing_tree(folder_type)
|
23
|
+
MissingRspec::Tree.new(app_path: app_path, folder_type: folder_type).missing_tree
|
24
|
+
end
|
25
|
+
|
26
|
+
def print_tree(tree)
|
27
|
+
puts tree.join("\n")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,6 +1,11 @@
|
|
1
1
|
require 'missing_rspec/core'
|
2
2
|
|
3
3
|
desc "mechanically extracts uncreated RSpecs"
|
4
|
-
task :missing_rspec, [
|
5
|
-
MissingRspec::Core.
|
4
|
+
task :missing_rspec, %w[app_path folder_type] => :environment do |_, args|
|
5
|
+
MissingRspec::Core.execute(mode: :viewer, app_path: args.app_path, folder_type: args.folder_type)
|
6
|
+
end
|
7
|
+
|
8
|
+
desc "Create an uncreated Rsepc files"
|
9
|
+
task :missing_rspec_create, %w[app_path folder_type] => :environment do |_, args|
|
10
|
+
MissingRspec::Core.execute(mode: :creator, app_path: args.app_path, folder_type: args.folder_type)
|
6
11
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: missing_rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keiichi Kayama
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This Gem extracts RSpec files that have not yet been created.
|
14
14
|
email:
|
@@ -30,9 +30,12 @@ files:
|
|
30
30
|
- bin/setup
|
31
31
|
- lib/missing_rspec.rb
|
32
32
|
- lib/missing_rspec/core.rb
|
33
|
-
- lib/missing_rspec/
|
33
|
+
- lib/missing_rspec/creator.rb
|
34
34
|
- lib/missing_rspec/folder_types_finder.rb
|
35
|
+
- lib/missing_rspec/module_name.rb
|
36
|
+
- lib/missing_rspec/tree.rb
|
35
37
|
- lib/missing_rspec/version.rb
|
38
|
+
- lib/missing_rspec/viewer.rb
|
36
39
|
- lib/tasks/missing_rspec.rake
|
37
40
|
- missing_rspec.gemspec
|
38
41
|
homepage: https://github.com/kayamak/missing_rspec
|