mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
adds --skip-listen to the application generator [closes #23590]
This commit is contained in:
parent
5971fddb79
commit
94dbc48887
6 changed files with 42 additions and 13 deletions
|
@ -1,3 +1,7 @@
|
|||
* The application generator supports `--skip-listen` to opt-out of features
|
||||
that depend on the listen gem. As of this writing they are the evented file
|
||||
system monitor and the async plugin for spring.
|
||||
|
||||
* The Gemfiles of new applications include spring-watcher-listen on Linux and
|
||||
Mac OS X (unless --skip-spring).
|
||||
|
||||
|
|
|
@ -63,6 +63,9 @@ module Rails
|
|||
class_option :skip_spring, type: :boolean, default: false,
|
||||
desc: "Don't install Spring application preloader"
|
||||
|
||||
class_option :skip_listen, type: :boolean, default: false,
|
||||
desc: "Don't generate configuration that depends on the listen gem"
|
||||
|
||||
class_option :skip_javascript, type: :boolean, aliases: '-J', default: false,
|
||||
desc: 'Skip JavaScript files'
|
||||
|
||||
|
@ -390,6 +393,10 @@ module Rails
|
|||
!options[:skip_spring] && !options.dev? && Process.respond_to?(:fork) && !RUBY_PLATFORM.include?("cygwin")
|
||||
end
|
||||
|
||||
def depend_on_listen?
|
||||
!options[:skip_listen] && os_supports_listen_out_of_the_box?
|
||||
end
|
||||
|
||||
def os_supports_listen_out_of_the_box?
|
||||
RbConfig::CONFIG['host_os'] =~ /darwin|linux/
|
||||
end
|
||||
|
|
|
@ -38,13 +38,13 @@ group :development do
|
|||
gem 'web-console', '~> 3.0'
|
||||
<%- end -%>
|
||||
<%- end -%>
|
||||
<% if os_supports_listen_out_of_the_box? -%>
|
||||
<% if depend_on_listen? -%>
|
||||
gem 'listen', '~> 3.0.5'
|
||||
<% end -%>
|
||||
<% if spring_install? -%>
|
||||
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
|
||||
gem 'spring'
|
||||
<% if os_supports_listen_out_of_the_box? -%>
|
||||
<% if depend_on_listen? -%>
|
||||
gem 'spring-watcher-listen', '~> 2.0.0'
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
|
|
|
@ -58,5 +58,5 @@ Rails.application.configure do
|
|||
|
||||
# Use an evented file watcher to asynchronously detect changes in source code,
|
||||
# routes, locales, etc. This feature depends on the listen gem.
|
||||
<%= '# ' unless os_supports_listen_out_of_the_box? %>config.file_watcher = ActiveSupport::EventedFileUpdateChecker
|
||||
<%= '# ' unless depend_on_listen? %>config.file_watcher = ActiveSupport::EventedFileUpdateChecker
|
||||
end
|
||||
|
|
|
@ -479,18 +479,20 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_inclusion_of_listen_related_gems
|
||||
def test_inclusion_of_listen_related_configuration_by_default
|
||||
run_generator
|
||||
if RbConfig::CONFIG['host_os'] =~ /darwin|linux/
|
||||
assert_gem 'listen'
|
||||
assert_gem 'spring-watcher-listen'
|
||||
assert_listen_related_configuration
|
||||
else
|
||||
assert_file 'Gemfile' do |content|
|
||||
assert_no_match(/listen/, content)
|
||||
end
|
||||
assert_no_listen_related_configuration
|
||||
end
|
||||
end
|
||||
|
||||
def test_non_inclusion_of_listen_related_configuration_if_skip_listen
|
||||
run_generator [destination_root, '--skip-listen']
|
||||
assert_no_listen_related_configuration
|
||||
end
|
||||
|
||||
def test_evented_file_update_checker_config
|
||||
run_generator
|
||||
assert_file 'config/environments/development.rb' do |content|
|
||||
|
@ -759,4 +761,23 @@ class AppGeneratorTest < Rails::Generators::TestCase
|
|||
assert_file "Gemfile", /^\s*gem\s+["']#{gem}["']$*/
|
||||
end
|
||||
end
|
||||
|
||||
def assert_listen_related_configuration
|
||||
assert_gem 'listen'
|
||||
assert_gem 'spring-watcher-listen'
|
||||
|
||||
assert_file 'config/environments/development.rb' do |content|
|
||||
assert_match(/^\s*config.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content)
|
||||
end
|
||||
end
|
||||
|
||||
def assert_no_listen_related_configuration
|
||||
assert_file 'Gemfile' do |content|
|
||||
assert_no_match(/listen/, content)
|
||||
end
|
||||
|
||||
assert_file 'config/environments/development.rb' do |content|
|
||||
assert_match(/^\s*# config.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -154,8 +154,6 @@ module TestHelpers
|
|||
config.action_controller.allow_forgery_protection = false
|
||||
config.log_level = :info
|
||||
RUBY
|
||||
|
||||
remove_from_env_config('development', 'config.file_watcher.*')
|
||||
end
|
||||
|
||||
def teardown_app
|
||||
|
@ -328,7 +326,6 @@ class ActiveSupport::TestCase
|
|||
include ActiveSupport::Testing::Stream
|
||||
|
||||
self.test_order = :sorted
|
||||
|
||||
end
|
||||
|
||||
# Create a scope and build a fixture rails app
|
||||
|
@ -342,7 +339,7 @@ Module.new do
|
|||
environment = File.expand_path('../../../../load_paths', __FILE__)
|
||||
require_environment = "-r #{environment}"
|
||||
|
||||
`#{Gem.ruby} #{require_environment} #{RAILS_FRAMEWORK_ROOT}/railties/exe/rails new #{app_template_path} --skip-gemfile --no-rc`
|
||||
`#{Gem.ruby} #{require_environment} #{RAILS_FRAMEWORK_ROOT}/railties/exe/rails new #{app_template_path} --skip-gemfile --skip-listen --no-rc`
|
||||
File.open("#{app_template_path}/config/boot.rb", 'w') do |f|
|
||||
f.puts "require '#{environment}'"
|
||||
f.puts "require 'rails/all'"
|
||||
|
|
Loading…
Reference in a new issue