diff --git a/CHANGELOG.md b/CHANGELOG.md index 374791dd..e84138a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/lib/spring/client/binstub.rb b/lib/spring/client/binstub.rb index 1e2feac3..75b9aecf 100644 --- a/lib/spring/client/binstub.rb +++ b/lib/spring/client/binstub.rb @@ -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" diff --git a/test/support/acceptance_test.rb b/test/support/acceptance_test.rb index af2c36a0..dde78a39 100644 --- a/test/support/acceptance_test.rb +++ b/test/support/acceptance_test.rb @@ -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) yield ensure + FileUtils.mv(app.root.join("#{name}.gemspec"), spec_home) FileUtils.mv(app.root.join(name), gem_home) end @@ -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"))