Last active
February 5, 2021 15:09
-
-
Save pecavalheiro/9694b846985e55721beb5fb097ab4406 to your computer and use it in GitHub Desktop.
Generate RSpec templates for customization
This file contains hidden or 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
| # 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