Skip to content

Instantly share code, notes, and snippets.

@pecavalheiro
Last active February 5, 2021 15:09
Show Gist options
  • Select an option

  • Save pecavalheiro/9694b846985e55721beb5fb097ab4406 to your computer and use it in GitHub Desktop.

Select an option

Save pecavalheiro/9694b846985e55721beb5fb097ab4406 to your computer and use it in GitHub Desktop.
Generate RSpec templates for customization
# create rake task with the following content
namespace :spec do
namespace :templates do
# desc "Copy all the templates from rspec to the application directory for customization. Already existing local copies will be overwritten"
task :copy do
generators_lib = File.join(Gem.loaded_specs["rspec-rails"].full_gem_path, "lib/generators")
project_templates = "#{Rails.root}/lib/templates"
default_templates = { "rspec" => %w{controller helper integration mailer model observer scaffold view} }
default_templates.each do |type, names|
local_template_type_dir = File.join(project_templates, type)
FileUtils.mkdir_p local_template_type_dir
names.each do |name|
dst_name = File.join(local_template_type_dir, name)
src_name = File.join(generators_lib, type, name, "templates")
FileUtils.cp_r src_name, dst_name if File.directory?(src_name)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment