Class: CypressOnRails::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- CypressOnRails::InstallGenerator
- Defined in:
- lib/generators/cypress_on_rails/install_generator.rb
Instance Method Summary collapse
- #add_initial_files ⇒ Object
- #install_cypress ⇒ Object
- #update_files ⇒ Object
- #update_test_rb ⇒ Object
Instance Method Details
#add_initial_files ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/generators/cypress_on_rails/install_generator.rb', line 33 def add_initial_files template "config/initializers/cypress_on_rails.rb.erb", "config/initializers/cypress_on_rails.rb" copy_file "spec/cypress/cypress_helper.rb", "#{.cypress_folder}/cypress_helper.rb" copy_file "spec/cypress/support/on-rails.js", "#{.cypress_folder}/support/on-rails.js" directory 'spec/cypress/app_commands', "#{.cypress_folder}/app_commands" directory 'spec/cypress/integration/rails_examples', "#{.cypress_folder}/integration/rails_examples" end |
#install_cypress ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/generators/cypress_on_rails/install_generator.rb', line 8 def install_cypress if !Dir.exists?(.cypress_folder) || Dir["#{.cypress_folder}/*"].empty? directories = .cypress_folder.split('/') directories.pop install_dir = "#{Dir.pwd}/#{directories.join('/')}" command = nil if .install_cypress_with == 'yarn' command = "yarn --cwd=#{install_dir} add cypress --dev --silent" elsif .install_cypress_with == 'npm' command = "cd #{install_dir}; npm install cypress --save-dev --silent" end if command say command fail 'failed to install cypress' unless system(command) end if .install_cypress_examples directory 'spec/cypress/integration/examples', "#{.cypress_folder}/integration/examples" directory 'spec/cypress/fixtures', "#{.cypress_folder}/fixtures" end copy_file "spec/cypress/support/index.js", "#{.cypress_folder}/support/index.js" copy_file "spec/cypress/support/commands.js", "#{.cypress_folder}/support/commands.js" copy_file "spec/cypress.json", "#{.cypress_folder}/../cypress.json" end end |
#update_files ⇒ Object
41 42 43 44 45 |
# File 'lib/generators/cypress_on_rails/install_generator.rb', line 41 def update_files append_to_file "#{.cypress_folder}/support/index.js", "\nimport './on-rails'", after: 'import \'./commands\'' end |
#update_test_rb ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/generators/cypress_on_rails/install_generator.rb', line 48 def update_test_rb if File.exist?('config/environments/test.rb') gsub_file 'config/environments/test.rb', 'config.cache_classes = true', 'config.cache_classes = ENV[\'CI\'].present?' end if File.exist?('spec/dummy/config/environments/test.rb') gsub_file 'spec/dummy/config/environments/test.rb', 'config.cache_classes = true', 'config.cache_classes = ENV[\'CI\'].present?' end end |