Created
June 4, 2021 06:09
-
-
Save oieioi/2c1016739a13b5a73797f2ead0085e86 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_support/all' | |
def main | |
rb_file_paths_raw = `find app -type f -name '*.rb'` | |
rb_file_paths = rb_file_paths_raw.split("\n") | |
rb_file_paths.each do |file_name| | |
spec_file_name = file_name.sub(/^app/, 'spec').sub(/.rb$/, '_spec.rb') | |
next if File.exists?(spec_file_name) | |
class_name = get_class_name(file_name) | |
describe = <<~SPEC | |
require 'rails_helper' | |
RSpec.describe #{class_name} do | |
# 自動生成されたテストファイルです | |
end | |
SPEC | |
puts spec_file_name | |
#puts describe | |
# dir 作成 | |
`mkdir -p #{spec_file_name.sub(/\/*.rb/, '')}` | |
# ファイル作成 | |
File.open(spec_file_name, 'w') { |f| f.print(describe) } | |
end | |
end | |
def get_class_name(file_name) | |
file_name | |
.sub(/^app\//, '') | |
.sub(/^(.+?)\//, '') | |
.sub(/.rb$/, '') | |
.split('/') | |
.map{ |v| v.camelize } | |
.join('::') | |
end | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment