Skip to content
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

Run without error if spring is in uninstalled group #684

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Next Release

* Skip spring without error if spring is not in installed bundler groups.

## 4.1.0

* * Fix bug which makes commands to freeze when the Rails application is writing to STDERR.
Expand Down
2 changes: 1 addition & 1 deletion lib/spring/client/binstub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Binstub < Command
if !defined?(Spring) && [nil, "development", "test"].include?(ENV["RAILS_ENV"])
require "bundler"

Bundler.locked_gems.specs.find { |spec| spec.name == "spring" }&.tap do |spring|
Bundler.definition.requested_specs.find { |spec| spec.name == "spring" }&.tap do |spring|
Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
gem "spring", spring.version
require "spring/binstub"
Expand Down
12 changes: 12 additions & 0 deletions test/support/acceptance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,12 @@ def assert_speedup(ratio = DEFAULT_SPEEDUP)

def without_gem(name)
gem_home = app.gem_home.join('gems')
spec_home = app.gem_home.join('specifications')
FileUtils.mv(gem_home.join(name), app.root)
FileUtils.mv(spec_home.join("#{name}.gemspec"), app.root)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without moving the spec file, gem "spring", spring.version succeeds even though the gem code isn't there. The the next line raises a LoadError instead of a Gem::LoadError. That doesn't really matter for this solution but was an issue when trying to rescue only the Gem::LoadError. Anyway, I thought that this is more realistic for future specs.

yield
ensure
FileUtils.mv(app.root.join("#{name}.gemspec"), spec_home)
FileUtils.mv(app.root.join(name), gem_home)
end

Expand Down Expand Up @@ -283,6 +286,15 @@ def exec_name
end
end

test "binstub when spring gem is in uninstalled group" do
without_gem "spring-#{Spring::VERSION}" do
File.write(app.gemfile, app.gemfile.read.gsub(/(gem 'spring.*)/, '\1, group: :debug'))
app.run! "bundle config set without debug"
app.run! "bundle install", timeout: 300
assert_success "bin/rake -T", stdout: "rake db:migrate"
end
end

test "binstub when spring binary is missing" do
begin
File.rename(app.path("bin/spring"), app.path("bin/spring.bak"))
Expand Down