From 0cfe81f76cc30551a1a9e10cbcbc72e5fe5df500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Zalewski?= Date: Fri, 8 Sep 2017 16:54:47 +0200 Subject: [PATCH] Added support for gems.rb and gems.locked Support was added by using Gemfile file name detection from Bundler gem. --- CHANGELOG.md | 1 + lib/spring/configuration.rb | 2 +- lib/spring/test/acceptance_test.rb | 29 +++++++++++++++++++++++++++++ lib/spring/test/application.rb | 12 ++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de687af0..dad93707 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * Fix binstubs not being replaced when their quoting style was changed (#534) * Preserve comments right after the shebang line which might include magic comments such as `frozen_string_literal: true' +* Added support for `gems.rb` with Gemfile file name detection using Bundler method ## 2.0.2 diff --git a/lib/spring/configuration.rb b/lib/spring/configuration.rb index 103f0882..e370d55a 100644 --- a/lib/spring/configuration.rb +++ b/lib/spring/configuration.rb @@ -5,7 +5,7 @@ class << self attr_accessor :application_root, :quiet def gemfile - ENV['BUNDLE_GEMFILE'] || "Gemfile" + Bundler.default_gemfile end def after_fork_callbacks diff --git a/lib/spring/test/acceptance_test.rb b/lib/spring/test/acceptance_test.rb index c3da1ce7..9f2f2363 100644 --- a/lib/spring/test/acceptance_test.rb +++ b/lib/spring/test/acceptance_test.rb @@ -503,6 +503,18 @@ def exec_name assert_failure %(bin/rails runner 'require "sqlite3"'), stderr: "sqlite3" end + 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 + 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 +529,23 @@ def exec_name assert_success [%(bin/rails runner 'load Rails.root.join("script.rb")'), timeout: 60] end + 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 + 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 b174dd33..090d2570 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