2018-11-02 19:07:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe "Bundler.load" do
|
|
|
|
describe "with a gemfile" do
|
|
|
|
before(:each) do
|
2020-06-03 14:46:03 -04:00
|
|
|
install_gemfile <<-G
|
2019-05-06 12:06:21 -04:00
|
|
|
source "#{file_uri_for(gem_repo1)}"
|
2018-11-02 19:07:56 -04:00
|
|
|
gem "rack"
|
|
|
|
G
|
2020-05-08 01:19:04 -04:00
|
|
|
allow(Bundler::SharedHelpers).to receive(:pwd).and_return(bundled_app)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "provides a list of the env dependencies" do
|
|
|
|
expect(Bundler.load.dependencies).to have_dep("rack", ">= 0")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "provides a list of the resolved gems" do
|
|
|
|
expect(Bundler.load.gems).to have_gem("rack-1.0.0", "bundler-#{Bundler::VERSION}")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "ignores blank BUNDLE_GEMFILEs" do
|
|
|
|
expect do
|
|
|
|
ENV["BUNDLE_GEMFILE"] = ""
|
|
|
|
Bundler.load
|
|
|
|
end.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "with a gems.rb file" do
|
|
|
|
before(:each) do
|
|
|
|
create_file "gems.rb", <<-G
|
2019-05-06 12:06:21 -04:00
|
|
|
source "#{file_uri_for(gem_repo1)}"
|
2018-11-02 19:07:56 -04:00
|
|
|
gem "rack"
|
|
|
|
G
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle :install
|
2020-05-08 01:19:04 -04:00
|
|
|
allow(Bundler::SharedHelpers).to receive(:pwd).and_return(bundled_app)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "provides a list of the env dependencies" do
|
|
|
|
expect(Bundler.load.dependencies).to have_dep("rack", ">= 0")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "provides a list of the resolved gems" do
|
|
|
|
expect(Bundler.load.gems).to have_gem("rack-1.0.0", "bundler-#{Bundler::VERSION}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "without a gemfile" do
|
|
|
|
it "raises an exception if the default gemfile is not found" do
|
|
|
|
expect do
|
|
|
|
Bundler.load
|
|
|
|
end.to raise_error(Bundler::GemfileNotFound, /could not locate gemfile/i)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "raises an exception if a specified gemfile is not found" do
|
|
|
|
expect do
|
|
|
|
ENV["BUNDLE_GEMFILE"] = "omg.rb"
|
|
|
|
Bundler.load
|
|
|
|
end.to raise_error(Bundler::GemfileNotFound, /omg\.rb/)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not find a Gemfile above the testing directory" do
|
2019-01-24 11:28:02 -05:00
|
|
|
bundler_gemfile = Pathname.new(__dir__).join("../../Gemfile")
|
2018-11-02 19:07:56 -04:00
|
|
|
unless File.exist?(bundler_gemfile)
|
|
|
|
FileUtils.touch(bundler_gemfile)
|
|
|
|
@remove_bundler_gemfile = true
|
|
|
|
end
|
|
|
|
begin
|
|
|
|
expect { Bundler.load }.to raise_error(Bundler::GemfileNotFound)
|
|
|
|
ensure
|
|
|
|
bundler_gemfile.rmtree if @remove_bundler_gemfile
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "when called twice" do
|
|
|
|
it "doesn't try to load the runtime twice" do
|
2020-06-03 14:46:03 -04:00
|
|
|
install_gemfile <<-G
|
2019-05-06 12:06:21 -04:00
|
|
|
source "#{file_uri_for(gem_repo1)}"
|
2018-11-02 19:07:56 -04:00
|
|
|
gem "rack"
|
|
|
|
gem "activesupport", :group => :test
|
|
|
|
G
|
|
|
|
|
2020-06-03 14:47:59 -04:00
|
|
|
ruby <<-RUBY
|
2019-11-11 03:57:45 -05:00
|
|
|
require "#{lib_dir}/bundler"
|
2018-11-02 19:07:56 -04:00
|
|
|
Bundler.setup :default
|
|
|
|
Bundler.require :default
|
|
|
|
puts RACK
|
|
|
|
begin
|
|
|
|
require "activesupport"
|
|
|
|
rescue LoadError
|
|
|
|
puts "no activesupport"
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
expect(out.split("\n")).to eq(["1.0.0", "no activesupport"])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "not hurting brittle rubygems" do
|
|
|
|
it "does not inject #source into the generated YAML of the gem specs" do
|
2020-06-03 14:46:03 -04:00
|
|
|
install_gemfile <<-G
|
2019-05-06 12:06:21 -04:00
|
|
|
source "#{file_uri_for(gem_repo1)}"
|
2018-11-02 19:07:56 -04:00
|
|
|
gem "activerecord"
|
|
|
|
G
|
2020-05-08 01:19:04 -04:00
|
|
|
allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
|
2018-11-02 19:07:56 -04:00
|
|
|
Bundler.load.specs.each do |spec|
|
|
|
|
expect(spec.to_yaml).not_to match(/^\s+source:/)
|
|
|
|
expect(spec.to_yaml).not_to match(/^\s+groups:/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|