Skip to content

Instantly share code, notes, and snippets.

@fmasuhr
Created October 15, 2015 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fmasuhr/dd91202e8015690906f8 to your computer and use it in GitHub Desktop.
Save fmasuhr/dd91202e8015690906f8 to your computer and use it in GitHub Desktop.
Create missing spec files for a ruby gem
require 'active_support/all'
require 'fileutils'
require 'pathname'
root = Pathname.pwd
code_folder = root.join('lib')
spec_folder = root.join('spec')
code = Dir[code_folder.join('**/*.rb')].map { |file| file[(code_folder.to_s.length+1)..-('.rb'.length+1)] }
specs = Dir[spec_folder.join('**/*_spec.rb')].map { |file| file[(spec_folder.to_s.length+1)..-('_spec.rb'.length+1)] }
(code - specs).each do |file|
klass = file.camelize
spec_file = spec_folder.join("#{file}_spec.rb")
FileUtils.mkdir_p(spec_file.dirname)
File.open(spec_file, 'w') do |f|
f.puts <<-END_OF_RUBY.strip_heredoc
require 'spec_helper'
describe #{klass} do
# please don't delete this file because it ensures that
# this class/module is taken into account for code coverage
#
# or even better proposal: please write specs :)
end
END_OF_RUBY
end
puts "created: #{spec_file}"
end
puts 'DONE all missing spec files created'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment