Class: ReactOnRails::Generators::DevTestsGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
GeneratorHelper
Defined in:
lib/generators/react_on_rails/dev_tests_generator.rb

Instance Method Summary collapse

Methods included from GeneratorHelper

#add_documentation_reference, #add_npm_dependencies, #component_extension, #copy_file_and_missing_parent_directories, #dest_dir_exists?, #dest_file_exists?, #empty_directory_with_keep_file, #keep_file, #package_json, #setup_file_error, #symlink_dest_file_to_dest_file

Instance Method Details



32
33
34
35
36
# File 'lib/generators/react_on_rails/dev_tests_generator.rb', line 32

def add_test_related_gems_to_gemfile
  gem("rspec-rails", group: :test)
  gem("chromedriver-helper", group: :test)
  gem("coveralls", require: false)
end

#add_yarn_relative_install_script_in_package_jsonObject



49
50
51
52
53
54
55
# File 'lib/generators/react_on_rails/dev_tests_generator.rb', line 49

def add_yarn_relative_install_script_in_package_json
  package_json = File.join(destination_root, "package.json")
  contents = JSON.parse(File.read(package_json))
  contents["scripts"] ||= {}
  contents["scripts"]["postinstall"] = "yalc link react-on-rails"
  File.open(package_json, "w+") { |f| f.puts JSON.pretty_generate(contents) }
end

#copy_rspec_filesObject



20
21
22
23
24
25
26
# File 'lib/generators/react_on_rails/dev_tests_generator.rb', line 20

def copy_rspec_files
  %w[.eslintrc
     spec/spec_helper.rb
     spec/rails_helper.rb
     spec/simplecov_helper.rb
     .rspec].each { |file| copy_file(file) }
end

#copy_testsObject



28
29
30
# File 'lib/generators/react_on_rails/dev_tests_generator.rb', line 28

def copy_tests
  %w[spec/system/hello_world_spec.rb].each { |file| copy_file(file) }
end

#replace_prerender_if_server_renderingObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/generators/react_on_rails/dev_tests_generator.rb', line 38

def replace_prerender_if_server_rendering
  return unless options.example_server_rendering

  hello_world_index = File.join(destination_root, "app", "views", "hello_world", "index.html.erb")
  hello_world_contents = File.read(hello_world_index)
  new_hello_world_contents = hello_world_contents.gsub("prerender: false",
                                                       "prerender: true")

  File.open(hello_world_index, "w+") { |f| f.puts new_hello_world_contents }
end