Skip to content

Commit 647b8c3

Browse files
authored
Merge pull request #588 from remomueller/unify-method-to-detect-gemfile-name
Add support for gems.rb and gems.locked, closes #524.
2 parents ee68785 + 8a3297f commit 647b8c3

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
* Preserve comments right after the shebang line which might include magic comments such as `frozen_string_literal: true`
77
* Fix binstub failures when Bundler's `BUNDLE_APP_CONFIG` environment variable is present (#545)
88
* Properly suspend and resume on ctrl-z TSTP and CONT (#361)
9+
* Added support for `gems.rb` with Gemfile file name detection using Bundler
10+
method (#524)
11+
12+
*Michał Zalewski*, *JuPlutonic*
913

1014
## 2.0.2
1115

lib/spring/configuration.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ class << self
55
attr_accessor :application_root, :quiet
66

77
def gemfile
8-
ENV['BUNDLE_GEMFILE'] || "Gemfile"
8+
if /\s1.9.[0-9]/ === Bundler.ruby_scope.gsub(/[\/\s]+/,'')
9+
ENV["BUNDLE_GEMFILE"] || "Gemfile"
10+
else
11+
Bundler.default_gemfile
12+
end
913
end
1014

1115
def after_fork_callbacks

test/support/acceptance_test.rb

+33
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,20 @@ def exec_name
503503
assert_failure %(bin/rails runner 'require "sqlite3"'), stderr: "sqlite3"
504504
end
505505

506+
if RUBY_VERSION >= "2.0.0"
507+
test "changing the gems.rb works" do
508+
FileUtils.mv(app.gemfile, app.gems_rb)
509+
FileUtils.mv(app.gemfile_lock, app.gems_locked)
510+
511+
assert_success %(bin/rails runner 'require "sqlite3"')
512+
513+
File.write(app.gems_rb, app.gems_rb.read.sub(%{gem 'sqlite3'}, %{# gem 'sqlite3'}))
514+
app.await_reload
515+
516+
assert_failure %(bin/rails runner 'require "sqlite3"'), stderr: "sqlite3"
517+
end
518+
end
519+
506520
test "changing the Gemfile works when Spring calls into itself" do
507521
File.write(app.path("script.rb"), <<-RUBY.strip_heredoc)
508522
gemfile = Rails.root.join("Gemfile")
@@ -517,6 +531,25 @@ def exec_name
517531
assert_success [%(bin/rails runner 'load Rails.root.join("script.rb")'), timeout: 60]
518532
end
519533

534+
if RUBY_VERSION >= "2.0.0"
535+
test "changing the gems.rb works when spring calls into itself" do
536+
FileUtils.mv(app.gemfile, app.gems_rb)
537+
FileUtils.mv(app.gemfile_lock, app.gems_locked)
538+
539+
File.write(app.path("script.rb"), <<-RUBY.strip_heredoc)
540+
gemfile = Rails.root.join("gems.rb")
541+
File.write(gemfile, "\#{gemfile.read}gem 'text'\\n")
542+
Bundler.with_clean_env do
543+
system(#{app.env.inspect}, "bundle install")
544+
end
545+
output = `\#{Rails.root.join('bin/rails')} runner 'require "text"; puts "done";'`
546+
exit output.include? "done\n"
547+
RUBY
548+
549+
assert_success [%(bin/rails runner 'load Rails.root.join("script.rb")'), timeout: 60]
550+
end
551+
end
552+
520553
test "changing the environment between runs" do
521554
File.write(app.application_config, "#{app.application_config.read}\nENV['BAR'] = 'bar'")
522555

test/support/application.rb

+12
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ def gemfile
4848
path "Gemfile"
4949
end
5050

51+
def gemfile_lock
52+
path "Gemfile.lock"
53+
end
54+
55+
def gems_rb
56+
path "gems.rb"
57+
end
58+
59+
def gems_locked
60+
path "gems.locked"
61+
end
62+
5163
def gem_home
5264
path "../gems/#{RUBY_VERSION}"
5365
end

0 commit comments

Comments
 (0)