File tree Expand file tree Collapse file tree 2 files changed +32
-5
lines changed
Expand file tree Collapse file tree 2 files changed +32
-5
lines changed Original file line number Diff line number Diff line change @@ -195,15 +195,17 @@ def self.force_activate(gem)
195195 Bundler . reset!
196196
197197 builder = Bundler ::Dsl . new
198+
198199 if Bundler ::SharedHelpers . in_bundle?
199- if Bundler . definition . gemfiles . empty?
200+ if Bundler . locked_gems
200201 Bundler . locked_gems . specs . each { |spec | builder . gem spec . name , spec . version . to_s }
201- else
202+ elsif Bundler . definition . gemfiles . size > 0
202203 Bundler . definition . gemfiles . each { |gemfile | builder . eval_gemfile ( gemfile ) }
203204 end
204- builder . gem gem
205205 end
206206
207+ builder . gem gem
208+
207209 definition = builder . to_definition ( nil , true )
208210 definition . validate_runtime!
209211
Original file line number Diff line number Diff line change @@ -363,11 +363,36 @@ def my
363363 end
364364
365365 describe ".force_activate" do
366- context "when gem activation fails" do
366+ before do
367+ allow_any_instance_of ( Bundler ::Runtime ) . to receive ( :setup ) . and_raise ( Bundler ::GemNotFound )
368+ end
369+
370+ context "with bundle environment" do
367371 before do
368- allow_any_instance_of ( Bundler ::Runtime ) . to receive ( :setup ) . and_raise ( Bundler ::GemNotFound )
372+ code = <<-RUBY
373+ #!/usr/bin/env ruby
374+
375+ Gem::BUNDLED_GEMS.force_activate("csv")
376+ RUBY
377+ create_file ( "script.rb" , code )
378+ create_file ( "Gemfile" , "source 'https://rubygems.org'" )
379+ end
380+
381+ it "lockfile is available" do
382+ bundle "install"
383+ bundle "exec ./script.rb"
384+
385+ expect ( err ) . to include ( "gem install csv" )
369386 end
370387
388+ it "lockfile is not available" do
389+ bundle "exec ./script.rb"
390+
391+ expect ( err ) . to include ( "gem install csv" )
392+ end
393+ end
394+
395+ context "without bundle environment" do
371396 it "warns about installation requirement" do
372397 expect_any_instance_of ( Object ) . to receive ( :warn )
373398 Gem ::BUNDLED_GEMS . force_activate ( "csv" )
You can’t perform that action at this time.
0 commit comments