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

#copy_file_and_missing_parent_directories, #dest_dir_exists?, #dest_file_exists?, #empty_directory_with_keep_file, #keep_file, #setup_file_error, #symlink_dest_file_to_dest_file

Instance Method Details



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

def add_test_related_gems_to_gemfile
  gem("rspec-rails", group: :test)
  gem("capybara", group: :test)
  gem("selenium-webdriver", group: :test)
  gem("coveralls", require: false)
  gem("poltergeist")
end

#change_package_json_to_use_local_react_on_rails_moduleObject

We want to use the node module in the local build, not the one published to NPM



23
24
25
26
27
28
29
# File 'lib/generators/react_on_rails/dev_tests_generator.rb', line 23

def change_package_json_to_use_local_react_on_rails_module
  package_json = File.join(destination_root, "client", "package.json")
  old_contents = File.read(package_json)
  new_contents = old_contents.gsub(/"react-on-rails": ".+",/,
                                   '"react-on-rails": "../../..",')
  File.open(package_json, "w+") { |f| f.puts new_contents }
end

#change_webpack_client_base_config_to_include_fallbackObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/generators/react_on_rails/dev_tests_generator.rb', line 31

def change_webpack_client_base_config_to_include_fallback
  text = <<-TEXT
  },

  // This fixes an issue with resolving 'react' when using a local symlinked version
  // of the node_package folder
  resolveLoader: {
    fallback: [path.join(__dirname, 'node_modules')],
  },
  plugins: [
TEXT
  sentinel = /^\s\s},\n\s\splugins: \[\n/
  config = File.join(destination_root, "client", "webpack.client.base.config.js")
  old_contents = File.read(config)
  new_contents = old_contents.gsub(sentinel, text)
  File.open(config, "w+") { |f| f.puts new_contents }
end

#copy_rspec_filesObject



11
12
13
14
15
16
# File 'lib/generators/react_on_rails/dev_tests_generator.rb', line 11

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

#copy_testsObject



18
19
20
# File 'lib/generators/react_on_rails/dev_tests_generator.rb', line 18

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