Skip to content

Commit

Permalink
Add support for gems.rb and gems.locked, closes #524.
Browse files Browse the repository at this point in the history
  • Loading branch information
remomueller committed Mar 29, 2019
1 parent e7a36af commit 8f5bf41
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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 lib/spring/test/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 lib/spring/test/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

0 comments on commit 8f5bf41

Please sign in to comment.