Class: SpreeDevTools::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/spree_dev_tools/generators/install/install_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_pathsObject



7
8
9
10
11
12
# File 'lib/spree_dev_tools/generators/install/install_generator.rb', line 7

def self.source_paths
  paths = superclass.source_paths
  paths << File.expand_path('templates', __dir__)
  paths << File.expand_path('../../rspec/support', __dir__)
  paths.flatten
end

Instance Method Details

#enable_support_files_loadingObject



40
41
42
43
44
45
46
47
# File 'lib/spree_dev_tools/generators/install/install_generator.rb', line 40

def enable_support_files_loading
  rails_helper_path = Rails.root.join('spec/rails_helper.rb')
  return unless File.exist?(rails_helper_path)

  gsub_file 'spec/rails_helper.rb',
            "# Rails.root.glob('spec/support/**/*.rb').sort_by(&:to_s).each { |f| require f }",
            "Rails.root.glob('spec/support/**/*.rb').sort_by(&:to_s).each { |f| require f }"
end

#inject_rspec_support_filesObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/spree_dev_tools/generators/install/install_generator.rb', line 28

def inject_rspec_support_files
  empty_directory 'spec/support'

  template 'capybara.rb', 'spec/support/capybara.rb'
  template 'action_text.rb', 'spec/support/action_text.rb'
  template 'active_job.rb', 'spec/support/active_job.rb'
  template 'database_cleaner.rb', 'spec/support/database_cleaner.rb'
  template 'devise.rb', 'spec/support/devise.rb'
  template 'factory_bot.rb', 'spec/support/factory_bot.rb'
  template 'spree.rb', 'spec/support/spree.rb'
end

#install_spree_dev_toolsObject



22
23
24
25
26
# File 'lib/spree_dev_tools/generators/install/install_generator.rb', line 22

def install_spree_dev_tools
  return if File.exist?(Rails.root.join('config/initializers/spree_dev_tools.rb'))

  template 'spree_dev_tools.rb', 'config/initializers/spree_dev_tools.rb'
end

#run_rspec_installObject



16
17
18
19
20
# File 'lib/spree_dev_tools/generators/install/install_generator.rb', line 16

def run_rspec_install
  return if File.exist?(Rails.root.join('spec/spec_helper.rb'))

  rails_command 'generate rspec:install'
end