Refactor bundled condition
This commit is contained in:
parent
598b0e8b72
commit
b47a04eb91
Notes:
git
2025-04-10 08:29:55 +00:00
@ -195,15 +195,17 @@ module Gem::BUNDLED_GEMS # :nodoc:
|
||||
Bundler.reset!
|
||||
|
||||
builder = Bundler::Dsl.new
|
||||
|
||||
if Bundler::SharedHelpers.in_bundle?
|
||||
if Bundler.definition.gemfiles.empty?
|
||||
if Bundler.locked_gems
|
||||
Bundler.locked_gems.specs.each{|spec| builder.gem spec.name, spec.version.to_s }
|
||||
else
|
||||
elsif Bundler.definition.gemfiles.size > 0
|
||||
Bundler.definition.gemfiles.each{|gemfile| builder.eval_gemfile(gemfile) }
|
||||
end
|
||||
builder.gem gem
|
||||
end
|
||||
|
||||
builder.gem gem
|
||||
|
||||
definition = builder.to_definition(nil, true)
|
||||
definition.validate_runtime!
|
||||
|
||||
|
@ -363,11 +363,36 @@ RSpec.describe "bundled_gems.rb" do
|
||||
end
|
||||
|
||||
describe ".force_activate" do
|
||||
context "when gem activation fails" do
|
||||
before do
|
||||
allow_any_instance_of(Bundler::Runtime).to receive(:setup).and_raise(Bundler::GemNotFound)
|
||||
end
|
||||
|
||||
context "with bundle environment" do
|
||||
before do
|
||||
allow_any_instance_of(Bundler::Runtime).to receive(:setup).and_raise(Bundler::GemNotFound)
|
||||
code = <<-RUBY
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
Gem::BUNDLED_GEMS.force_activate("csv")
|
||||
RUBY
|
||||
create_file("script.rb", code)
|
||||
create_file("Gemfile", "source 'https://rubygems.org'")
|
||||
end
|
||||
|
||||
it "lockfile is available" do
|
||||
bundle "install"
|
||||
bundle "exec ./script.rb"
|
||||
|
||||
expect(err).to include("gem install csv")
|
||||
end
|
||||
|
||||
it "lockfile is not available" do
|
||||
bundle "exec ./script.rb"
|
||||
|
||||
expect(err).to include("gem install csv")
|
||||
end
|
||||
end
|
||||
|
||||
context "without bundle environment" do
|
||||
it "warns about installation requirement" do
|
||||
expect_any_instance_of(Object).to receive(:warn)
|
||||
Gem::BUNDLED_GEMS.force_activate("csv")
|
||||
|
Loading…
x
Reference in New Issue
Block a user