diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c08f223..af3935c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ * Preserve comments right after the shebang line which might include magic comments such as `frozen_string_literal: true' * Fix binstub failures when Bundler's `BUNDLE_APP_CONFIG` environment variable is present (#545) * Properly suspend and resume on ctrl-z TSTP and CONT (#361) +* Added support for `gems.rb` with Gemfile file name detection using Bundler + method (#524) + + *MichaƂ Zalewski*, *JuPlutonic* ## 2.0.2 diff --git a/lib/spring/configuration.rb b/lib/spring/configuration.rb index 103f0882..eba8e9a7 100644 --- a/lib/spring/configuration.rb +++ b/lib/spring/configuration.rb @@ -5,7 +5,11 @@ class << self attr_accessor :application_root, :quiet def gemfile - ENV['BUNDLE_GEMFILE'] || "Gemfile" + if /\s1.9.[0-9]/ === Bundler.ruby_scope.gsub(/[\/\s]+/,'') + ENV["BUNDLE_GEMFILE"] || "Gemfile" + else + Bundler.default_gemfile + end end def after_fork_callbacks diff --git a/lib/spring/test/acceptance_test.rb b/lib/spring/test/acceptance_test.rb index 4625fc64..a8c12f03 100644 --- a/lib/spring/test/acceptance_test.rb +++ b/lib/spring/test/acceptance_test.rb @@ -503,6 +503,20 @@ def exec_name assert_failure %(bin/rails runner 'require "sqlite3"'), stderr: "sqlite3" end + if RUBY_VERSION >= "2.0.0" + test "changing the gems.rb works" do + FileUtils.mv(app.gemfile, app.gems_rb) + FileUtils.mv(app.gemfile_lock, app.gems_locked) + + assert_success %(bin/rails runner 'require "sqlite3"') + + File.write(app.gems_rb, app.gems_rb.read.sub(%{gem 'sqlite3'}, %{# gem 'sqlite3'})) + app.await_reload + + assert_failure %(bin/rails runner 'require "sqlite3"'), stderr: "sqlite3" + end + end + test "changing the Gemfile works when Spring calls into itself" do File.write(app.path("script.rb"), <<-RUBY.strip_heredoc) gemfile = Rails.root.join("Gemfile") @@ -517,6 +531,25 @@ def exec_name assert_success [%(bin/rails runner 'load Rails.root.join("script.rb")'), timeout: 60] end + if RUBY_VERSION >= "2.0.0" + test "changing the gems.rb works when spring calls into itself" do + FileUtils.mv(app.gemfile, app.gems_rb) + FileUtils.mv(app.gemfile_lock, app.gems_locked) + + File.write(app.path("script.rb"), <<-RUBY.strip_heredoc) + gemfile = Rails.root.join("gems.rb") + File.write(gemfile, "\#{gemfile.read}gem 'text'\\n") + Bundler.with_clean_env do + system(#{app.env.inspect}, "bundle install") + end + output = `\#{Rails.root.join('bin/rails')} runner 'require "text"; puts "done";'` + exit output.include? "done\n" + RUBY + + assert_success [%(bin/rails runner 'load Rails.root.join("script.rb")'), timeout: 60] + end + end + test "changing the environment between runs" do File.write(app.application_config, "#{app.application_config.read}\nENV['BAR'] = 'bar'") diff --git a/lib/spring/test/application.rb b/lib/spring/test/application.rb index 9a00618e..010442b0 100644 --- a/lib/spring/test/application.rb +++ b/lib/spring/test/application.rb @@ -48,6 +48,18 @@ def gemfile path "Gemfile" end + def gemfile_lock + path "Gemfile.lock" + end + + def gems_rb + path "gems.rb" + end + + def gems_locked + path "gems.locked" + end + def gem_home path "../gems/#{RUBY_VERSION}" end