2018-11-02 19:07:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.shared_examples "bundle install --standalone" do
|
|
|
|
shared_examples "common functionality" do
|
|
|
|
it "still makes the gems available to normal bundler" do
|
|
|
|
args = expected_gems.map {|k, v| "#{k} #{v}" }
|
|
|
|
expect(the_bundle).to include_gems(*args)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "generates a bundle/bundler/setup.rb" do
|
|
|
|
expect(bundled_app("bundle/bundler/setup.rb")).to exist
|
|
|
|
end
|
|
|
|
|
|
|
|
it "makes the gems available without bundler" do
|
|
|
|
testrb = String.new <<-RUBY
|
|
|
|
$:.unshift File.expand_path("bundle")
|
|
|
|
require "bundler/setup"
|
|
|
|
|
|
|
|
RUBY
|
|
|
|
expected_gems.each do |k, _|
|
|
|
|
testrb << "\nrequire \"#{k}\""
|
|
|
|
testrb << "\nputs #{k.upcase}"
|
|
|
|
end
|
2020-05-15 08:31:12 -04:00
|
|
|
ruby testrb
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
expect(out).to eq(expected_gems.values.join("\n"))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "works on a different system" do
|
2020-05-08 01:19:04 -04:00
|
|
|
begin
|
|
|
|
FileUtils.mv(bundled_app, "#{bundled_app}2")
|
|
|
|
rescue Errno::ENOTEMPTY
|
|
|
|
puts "Couldn't rename test app since the target folder has these files: #{Dir.glob("#{bundled_app}2/*")}"
|
|
|
|
raise
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
testrb = String.new <<-RUBY
|
|
|
|
$:.unshift File.expand_path("bundle")
|
|
|
|
require "bundler/setup"
|
|
|
|
|
|
|
|
RUBY
|
|
|
|
expected_gems.each do |k, _|
|
|
|
|
testrb << "\nrequire \"#{k}\""
|
|
|
|
testrb << "\nputs #{k.upcase}"
|
|
|
|
end
|
2020-05-15 08:31:12 -04:00
|
|
|
ruby testrb, :dir => "#{bundled_app}2"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
expect(out).to eq(expected_gems.values.join("\n"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "with simple gems" do
|
|
|
|
before do
|
|
|
|
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 "rails"
|
|
|
|
G
|
2021-01-03 20:11:34 -05:00
|
|
|
bundle "config set --local path #{bundled_app("bundle")}"
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle :install, :standalone => true, :dir => cwd
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:expected_gems) do
|
|
|
|
{
|
|
|
|
"actionpack" => "2.3.2",
|
|
|
|
"rails" => "2.3.2",
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples "common functionality"
|
|
|
|
end
|
|
|
|
|
2020-05-16 06:47:24 -04:00
|
|
|
describe "with gems with native extension", :ruby_repo do
|
2018-11-02 19:07:56 -04:00
|
|
|
before do
|
2021-01-03 20:11:34 -05:00
|
|
|
bundle "config set --local path #{bundled_app("bundle")}"
|
2020-05-29 06:46:16 -04:00
|
|
|
install_gemfile <<-G, :standalone => true, :dir => cwd
|
2019-05-06 12:06:21 -04:00
|
|
|
source "#{file_uri_for(gem_repo1)}"
|
2018-11-02 19:07:56 -04:00
|
|
|
gem "very_simple_binary"
|
|
|
|
G
|
|
|
|
end
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
it "generates a bundle/bundler/setup.rb with the proper paths" do
|
2018-11-02 19:07:56 -04:00
|
|
|
expected_path = bundled_app("bundle/bundler/setup.rb")
|
|
|
|
extension_line = File.read(expected_path).each_line.find {|line| line.include? "/extensions/" }.strip
|
2020-10-15 00:20:25 -04:00
|
|
|
expect(extension_line).to start_with '$:.unshift File.expand_path("#{path}/../#{ruby_engine}/#{ruby_version}/extensions/'
|
|
|
|
expect(extension_line).to end_with '/very_simple_binary-1.0")'
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "with gem that has an invalid gemspec" do
|
|
|
|
before do
|
|
|
|
build_git "bar", :gemspec => false do |s|
|
|
|
|
s.write "lib/bar/version.rb", %(BAR_VERSION = '1.0')
|
|
|
|
s.write "bar.gemspec", <<-G
|
|
|
|
lib = File.expand_path('../lib/', __FILE__)
|
|
|
|
$:.unshift lib unless $:.include?(lib)
|
|
|
|
require 'bar/version'
|
|
|
|
|
|
|
|
Gem::Specification.new do |s|
|
|
|
|
s.name = 'bar'
|
|
|
|
s.version = BAR_VERSION
|
|
|
|
s.summary = 'Bar'
|
|
|
|
s.files = Dir["lib/**/*.rb"]
|
|
|
|
s.author = 'Anonymous'
|
|
|
|
s.require_path = [1,2]
|
|
|
|
end
|
|
|
|
G
|
|
|
|
end
|
2021-01-03 20:11:34 -05:00
|
|
|
bundle "config set --local path #{bundled_app("bundle")}"
|
2020-06-03 12:43:17 -04:00
|
|
|
install_gemfile <<-G, :standalone => true, :dir => cwd, :raise_on_error => false
|
2018-11-02 19:07:56 -04:00
|
|
|
gem "bar", :git => "#{lib_path("bar-1.0")}"
|
|
|
|
G
|
|
|
|
end
|
|
|
|
|
|
|
|
it "outputs a helpful error message" do
|
2019-04-14 02:01:35 -04:00
|
|
|
expect(err).to include("You have one or more invalid gemspecs that need to be fixed.")
|
|
|
|
expect(err).to include("bar 1.0 has an invalid gemspec")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "with a combination of gems and git repos" do
|
|
|
|
before do
|
|
|
|
build_git "devise", "1.0"
|
|
|
|
|
|
|
|
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 "rails"
|
|
|
|
gem "devise", :git => "#{lib_path("devise-1.0")}"
|
|
|
|
G
|
2021-01-03 20:11:34 -05:00
|
|
|
bundle "config set --local path #{bundled_app("bundle")}"
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle :install, :standalone => true, :dir => cwd
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:expected_gems) do
|
|
|
|
{
|
|
|
|
"actionpack" => "2.3.2",
|
|
|
|
"devise" => "1.0",
|
|
|
|
"rails" => "2.3.2",
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples "common functionality"
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "with groups" do
|
|
|
|
before do
|
|
|
|
build_git "devise", "1.0"
|
|
|
|
|
|
|
|
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 "rails"
|
|
|
|
|
|
|
|
group :test do
|
|
|
|
gem "rspec"
|
|
|
|
gem "rack-test"
|
|
|
|
end
|
|
|
|
G
|
2021-01-03 20:11:34 -05:00
|
|
|
bundle "config set --local path #{bundled_app("bundle")}"
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle :install, :standalone => true, :dir => cwd
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:expected_gems) do
|
|
|
|
{
|
|
|
|
"actionpack" => "2.3.2",
|
|
|
|
"rails" => "2.3.2",
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples "common functionality"
|
|
|
|
|
|
|
|
it "allows creating a standalone file with limited groups" do
|
2021-01-03 20:11:34 -05:00
|
|
|
bundle "config set --local path #{bundled_app("bundle")}"
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle :install, :standalone => "default", :dir => cwd
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2020-05-15 08:31:12 -04:00
|
|
|
load_error_ruby <<-RUBY, "spec"
|
2020-05-08 01:19:04 -04:00
|
|
|
$:.unshift File.expand_path("bundle")
|
|
|
|
require "bundler/setup"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
require "actionpack"
|
|
|
|
puts ACTIONPACK
|
|
|
|
require "spec"
|
|
|
|
RUBY
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-06-01 05:49:40 -04:00
|
|
|
expect(out).to eq("2.3.2")
|
|
|
|
expect(err).to eq("ZOMG LOAD ERROR")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2020-05-29 06:27:15 -04:00
|
|
|
it "allows `without` configuration to limit the groups used in a standalone" do
|
2021-01-03 20:11:34 -05:00
|
|
|
bundle "config set --local path #{bundled_app("bundle")}"
|
|
|
|
bundle "config set --local without test"
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle :install, :standalone => true, :dir => cwd
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2020-05-15 08:31:12 -04:00
|
|
|
load_error_ruby <<-RUBY, "spec"
|
2020-05-08 01:19:04 -04:00
|
|
|
$:.unshift File.expand_path("bundle")
|
|
|
|
require "bundler/setup"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
require "actionpack"
|
|
|
|
puts ACTIONPACK
|
|
|
|
require "spec"
|
|
|
|
RUBY
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-06-01 05:49:40 -04:00
|
|
|
expect(out).to eq("2.3.2")
|
|
|
|
expect(err).to eq("ZOMG LOAD ERROR")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2020-05-29 06:27:15 -04:00
|
|
|
it "allows `path` configuration to change the location of the standalone bundle" do
|
2021-01-03 20:11:34 -05:00
|
|
|
bundle "config set --local path path/to/bundle"
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle "install", :standalone => true, :dir => cwd
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2020-05-15 08:31:12 -04:00
|
|
|
ruby <<-RUBY
|
2020-05-08 01:19:04 -04:00
|
|
|
$:.unshift File.expand_path("path/to/bundle")
|
|
|
|
require "bundler/setup"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
require "actionpack"
|
|
|
|
puts ACTIONPACK
|
|
|
|
RUBY
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-06-01 05:49:40 -04:00
|
|
|
expect(out).to eq("2.3.2")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2020-05-29 06:27:15 -04:00
|
|
|
it "allows `without` to limit the groups used in a standalone" do
|
2021-01-03 20:11:34 -05:00
|
|
|
bundle "config set --local without test"
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle :install, :dir => cwd
|
2021-01-03 20:11:34 -05:00
|
|
|
bundle "config set --local path #{bundled_app("bundle")}"
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle :install, :standalone => true, :dir => cwd
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2020-05-15 08:31:12 -04:00
|
|
|
load_error_ruby <<-RUBY, "spec"
|
2020-05-08 01:19:04 -04:00
|
|
|
$:.unshift File.expand_path("bundle")
|
|
|
|
require "bundler/setup"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
require "actionpack"
|
|
|
|
puts ACTIONPACK
|
|
|
|
require "spec"
|
|
|
|
RUBY
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-06-01 05:49:40 -04:00
|
|
|
expect(out).to eq("2.3.2")
|
|
|
|
expect(err).to eq("ZOMG LOAD ERROR")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "with gemcutter's dependency API" do
|
|
|
|
let(:source_uri) { "http://localgemserver.test" }
|
|
|
|
|
|
|
|
describe "simple gems" do
|
|
|
|
before do
|
|
|
|
gemfile <<-G
|
|
|
|
source "#{source_uri}"
|
|
|
|
gem "rails"
|
|
|
|
G
|
2021-01-03 20:11:34 -05:00
|
|
|
bundle "config set --local path #{bundled_app("bundle")}"
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle :install, :standalone => true, :artifice => "endpoint", :dir => cwd
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:expected_gems) do
|
|
|
|
{
|
|
|
|
"actionpack" => "2.3.2",
|
|
|
|
"rails" => "2.3.2",
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples "common functionality"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-04 08:10:58 -05:00
|
|
|
describe "with --binstubs", :bundler => "< 3" do
|
2018-11-02 19:07:56 -04:00
|
|
|
before do
|
|
|
|
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 "rails"
|
|
|
|
G
|
2021-01-03 20:11:34 -05:00
|
|
|
bundle "config set --local path #{bundled_app("bundle")}"
|
2020-06-03 14:45:36 -04:00
|
|
|
bundle :install, :standalone => true, :binstubs => true, :dir => cwd
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:expected_gems) do
|
|
|
|
{
|
|
|
|
"actionpack" => "2.3.2",
|
|
|
|
"rails" => "2.3.2",
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples "common functionality"
|
|
|
|
|
|
|
|
it "creates stubs that use the standalone load path" do
|
2020-05-08 01:19:04 -04:00
|
|
|
expect(sys_exec("bin/rails -v").chomp).to eql "2.3.2"
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "creates stubs that can be executed from anywhere" do
|
|
|
|
require "tmpdir"
|
2020-06-03 14:46:35 -04:00
|
|
|
sys_exec(%(#{bundled_app("bin/rails")} -v), :dir => Dir.tmpdir)
|
2020-05-08 01:19:04 -04:00
|
|
|
expect(out).to eq("2.3.2")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "creates stubs that can be symlinked" do
|
2020-05-08 01:19:04 -04:00
|
|
|
skip "symlinks unsupported" if Gem.win_platform?
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
symlink_dir = tmp("symlink")
|
|
|
|
FileUtils.mkdir_p(symlink_dir)
|
|
|
|
symlink = File.join(symlink_dir, "rails")
|
|
|
|
|
|
|
|
File.symlink(bundled_app("bin/rails"), symlink)
|
2020-06-03 14:46:35 -04:00
|
|
|
sys_exec("#{symlink} -v")
|
2018-11-02 19:07:56 -04:00
|
|
|
expect(out).to eq("2.3.2")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "creates stubs with the correct load path" do
|
|
|
|
extension_line = File.read(bundled_app("bin/rails")).each_line.find {|line| line.include? "$:.unshift" }.strip
|
|
|
|
expect(extension_line).to eq %($:.unshift File.expand_path "../../bundle", path.realpath)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.describe "bundle install --standalone" do
|
2020-05-08 01:19:04 -04:00
|
|
|
let(:cwd) { bundled_app }
|
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
include_examples("bundle install --standalone")
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.describe "bundle install --standalone run in a subdirectory" do
|
2020-05-08 01:19:04 -04:00
|
|
|
let(:cwd) { bundled_app("bob").tap(&:mkpath) }
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
include_examples("bundle install --standalone")
|
|
|
|
end
|