From 7173c4f931c9026bd3bc0b644d93dae744433f09 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Sat, 22 Dec 2012 11:13:10 -0800 Subject: Detect rbenv and update the shebang --- railties/lib/rails/generators/app_base.rb | 9 ++++++++- railties/test/generators/shared_generator_tests.rb | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 9874fb462a..9b9ae72e18 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -261,7 +261,14 @@ module Rails end def run_bundle - bundle_command('install --binstubs') unless options[:skip_gemfile] || options[:skip_bundle] || options[:pretend] + command = "install --binstubs" + command << " --shebang ruby-local-exec" if detect_ruby_local_exec + + bundle_command(command) unless options[:skip_gemfile] || options[:skip_bundle] || options[:pretend] + end + + def detect_ruby_local_exec + ENV["PATH"].split(":").find { |path| File.file?(File.join(path, "ruby-local-exec")) } end def empty_directory_with_keep_file(destination, config = {}) diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb index df34612574..85a90cd968 100644 --- a/railties/test/generators/shared_generator_tests.rb +++ b/railties/test/generators/shared_generator_tests.rb @@ -31,6 +31,16 @@ module SharedGeneratorTests quietly { generator.invoke_all } end + def test_generation_runs_bundle_install_with_shebang_if_needed + original_path = ENV["PATH"] + ENV["PATH"] = ENV["PATH"] + ":" + File.expand_path("../../fixtures/path", __FILE__) + + generator([destination_root]).expects(:bundle_command).with('install --binstubs --shebang ruby-local-exec').once + quietly { generator.invoke_all } + ensure + ENV["PATH"] = original_path + end + def test_plugin_new_generate_pretend run_generator ["testapp", "--pretend"] default_files.each{ |path| assert_no_file File.join("testapp",path) } -- cgit v1.2.3