Skip to content

Add support for gems.rb and gems.locked, closes #524. #588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,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

Expand Down
6 changes: 5 additions & 1 deletion lib/spring/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions test/support/acceptance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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'")

Expand Down
12 changes: 12 additions & 0 deletions test/support/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down