Do not run `bundle install` when generating a new plugin.

Since bundler 1.12.0, the gemspec is validated so the `bundle install`
command will fail just after the gem is created causing confusion to the
users. This change was a bug fix to correctly validate gemspecs.
上级 14996a14
* Do not run `bundle install` when generating a new plugin.
Since bundler 1.12.0, the gemspec is validated so the `bundle install`
command will fail just after the gem is created causing confusion to the
users. This change was a bug fix to correctly validate gemspecs.
*Rafael Mendonça França*
* Default `config.assets.quiet = true` in the development environment. Suppress
logging of `sprockets-rails` requests by default.
......
......@@ -242,7 +242,7 @@ def rails_gemfile_entry
] + dev_edge_common
elsif options.edge?
[
GemfileEntry.github('rails', 'rails/rails')
GemfileEntry.github('rails', 'rails/rails', '5-0-stable')
] + dev_edge_common
else
[GemfileEntry.version('rails',
......
......@@ -258,7 +258,7 @@ def finish_template
build(:leftovers)
end
public_task :apply_rails_template, :run_bundle
public_task :apply_rails_template
def run_after_bundle_callbacks
@after_bundle_callbacks.each do |callback|
......
......@@ -597,6 +597,21 @@ def test_web_console_with_edge_option
end
end
def test_generation_runs_bundle_install
assert_generates_with_bundler
end
def test_dev_option
assert_generates_with_bundler dev: true
rails_path = File.expand_path('../../..', Rails.root)
assert_file 'Gemfile', /^gem\s+["']rails["'],\s+path:\s+["']#{Regexp.escape(rails_path)}["']$/
end
def test_edge_option
assert_generates_with_bundler edge: true
assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["'],\s+branch:\s+["']#{Regexp.escape("5-0-stable")}["']$}
end
def test_spring
run_generator
assert_gem 'spring'
......@@ -754,41 +769,61 @@ def test_after_bundle_callback
protected
def stub_rails_application(root)
Rails.application.config.root = root
Rails.application.class.stub(:name, "Myapp") do
yield
def stub_rails_application(root)
Rails.application.config.root = root
Rails.application.class.stub(:name, "Myapp") do
yield
end
end
end
def action(*args, &block)
capture(:stdout) { generator.send(*args, &block) }
end
def action(*args, &block)
capture(:stdout) { generator.send(*args, &block) }
end
def assert_gem(gem, constraint = nil)
if constraint
assert_file "Gemfile", /^\s*gem\s+["']#{gem}["'], #{constraint}$*/
else
assert_file "Gemfile", /^\s*gem\s+["']#{gem}["']$*/
def assert_gem(gem, constraint = nil)
if constraint
assert_file "Gemfile", /^\s*gem\s+["']#{gem}["'], #{constraint}$*/
else
assert_file "Gemfile", /^\s*gem\s+["']#{gem}["']$*/
end
end
end
def assert_listen_related_configuration
assert_gem 'listen'
assert_gem 'spring-watcher-listen'
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)
assert_file 'config/environments/development.rb' do |content|
assert_match(/^\s*config.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content)
end
end
end
def assert_no_listen_related_configuration
assert_file 'Gemfile' do |content|
assert_no_match(/listen/, content)
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
assert_file 'config/environments/development.rb' do |content|
assert_match(/^\s*# config.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content)
def assert_generates_with_bundler(options = {})
generator([destination_root], options)
command_check = -> command do
@install_called ||= 0
case command
when 'install'
@install_called += 1
assert_equal 1, @install_called, "install expected to be called once, but was called #{@install_called} times"
when 'exec spring binstub --all'
# Called when running tests with spring, let through unscathed.
end
end
generator.stub :bundle_command, command_check do
quietly { generator.invoke_all }
end
end
end
end
......@@ -193,13 +193,24 @@ def test_ensure_that_database_option_is_passed_to_app_generator
assert_file "test/dummy/config/database.yml", /postgres/
end
def test_generation_runs_bundle_install_with_full_and_mountable
result = run_generator [destination_root, "--mountable", "--full", "--dev"]
assert_match(/run bundle install/, result)
assert $?.success?, "Command failed: #{result}"
assert_file "#{destination_root}/Gemfile.lock" do |contents|
assert_match(/bukkits/, contents)
end
def test_generation_runs_bundle_install
assert_generates_without_bundler
end
def test_dev_option
assert_generates_without_bundler(dev: true)
rails_path = File.expand_path('../../..', Rails.root)
assert_file 'Gemfile', /^gem\s+["']rails["'],\s+path:\s+["']#{Regexp.escape(rails_path)}["']$/
end
def test_edge_option
assert_generates_without_bundler(edge: true)
assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["'],\s+branch:\s+["']#{Regexp.escape("5-0-stable")}["']$}
end
def test_generation_does_not_run_bundle_install_with_full_and_mountable
assert_generates_without_bundler(mountable: true, full: true, dev: true)
assert_no_file "#{destination_root}/Gemfile.lock"
end
def test_skipping_javascripts_without_mountable_option
......@@ -697,48 +708,38 @@ def test_generate_application_job_when_does_not_exist_in_mountable_engine
end
end
def test_after_bundle_callback
path = 'http://example.org/rails_template'
template = %{ after_bundle { run 'echo ran after_bundle' } }
template.instance_eval "def read; self; end" # Make the string respond to read
protected
check_open = -> *args do
assert_equal [ path, 'Accept' => 'application/x-thor-template' ], args
template
def action(*args, &block)
silence(:stdout){ generator.send(*args, &block) }
end
sequence = ['install', 'echo ran after_bundle']
@sequence_step ||= 0
ensure_bundler_first = -> command do
assert_equal sequence[@sequence_step], command, "commands should be called in sequence #{sequence}"
@sequence_step += 1
def default_files
::DEFAULT_PLUGIN_FILES
end
generator([destination_root], template: path).stub(:open, check_open, template) do
generator.stub(:bundle_command, ensure_bundler_first) do
generator.stub(:run, ensure_bundler_first) do
quietly { generator.invoke_all }
end
def assert_match_sqlite3(contents)
if defined?(JRUBY_VERSION)
assert_match(/group :development do\n gem 'activerecord-jdbcsqlite3-adapter'\nend/, contents)
else
assert_match(/group :development do\n gem 'sqlite3'\nend/, contents)
end
end
assert_equal 2, @sequence_step
end
def assert_generates_without_bundler(options = {})
generator([destination_root], options)
protected
def action(*args, &block)
silence(:stdout){ generator.send(*args, &block) }
end
def default_files
::DEFAULT_PLUGIN_FILES
end
command_check = -> command do
case command
when 'install'
flunk "install expected to not be called"
when 'exec spring binstub --all'
# Called when running tests with spring, let through unscathed.
end
end
def assert_match_sqlite3(contents)
if defined?(JRUBY_VERSION)
assert_match(/group :development do\n gem 'activerecord-jdbcsqlite3-adapter'\nend/, contents)
else
assert_match(/group :development do\n gem 'sqlite3'\nend/, contents)
generator.stub :bundle_command, command_check do
quietly { generator.invoke_all }
end
end
end
end
......@@ -26,30 +26,6 @@ def test_skeleton_is_created
default_files.each { |path| assert_file path }
end
def assert_generates_with_bundler(options = {})
generator([destination_root], options)
command_check = -> command do
@install_called ||= 0
case command
when 'install'
@install_called += 1
assert_equal 1, @install_called, "install expected to be called once, but was called #{@install_called} times"
when 'exec spring binstub --all'
# Called when running tests with spring, let through unscathed.
end
end
generator.stub :bundle_command, command_check do
quietly { generator.invoke_all }
end
end
def test_generation_runs_bundle_install
assert_generates_with_bundler
end
def test_plugin_new_generate_pretend
run_generator ["testapp", "--pretend"]
default_files.each{ |path| assert_no_file File.join("testapp",path) }
......@@ -114,17 +90,6 @@ def test_template_is_executed_when_supplied_an_https_path
end
end
def test_dev_option
assert_generates_with_bundler dev: true
rails_path = File.expand_path('../../..', Rails.root)
assert_file 'Gemfile', /^gem\s+["']rails["'],\s+path:\s+["']#{Regexp.escape(rails_path)}["']$/
end
def test_edge_option
assert_generates_with_bundler edge: true
assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["']$}
end
def test_skip_gemfile
assert_not_called(generator([destination_root], skip_gemfile: true), :bundle_command) do
quietly { generator.invoke_all }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册