2018-11-02 19:07:56 -04:00
# frozen_string_literal: true
RSpec . describe " bundler/inline # gemfile " do
def script ( code , options = { } )
2021-05-28 06:47:49 -04:00
requires = [ " #{ entrypoint } /inline " ]
2019-11-11 03:57:45 -05:00
requires . unshift " #{ spec_dir } /support/artifice/ " + options . delete ( :artifice ) if options . key? ( :artifice )
2018-11-02 19:07:56 -04:00
requires = requires . map { | r | " require ' #{ r } ' " } . join ( " \n " )
2019-12-14 05:49:16 -05:00
ruby ( " #{ requires } \n \n " + code , options )
2018-11-02 19:07:56 -04:00
end
before :each do
build_lib " one " , " 1.0.0 " do | s |
s . write " lib/baz.rb " , " puts 'baz' "
s . write " lib/qux.rb " , " puts 'qux' "
end
build_lib " two " , " 1.0.0 " do | s |
s . write " lib/two.rb " , " puts 'two' "
s . add_dependency " three " , " = 1.0.0 "
end
build_lib " three " , " 1.0.0 " do | s |
s . write " lib/three.rb " , " puts 'three' "
s . add_dependency " seven " , " = 1.0.0 "
end
build_lib " four " , " 1.0.0 " do | s |
s . write " lib/four.rb " , " puts 'four' "
end
build_lib " five " , " 1.0.0 " , :no_default = > true do | s |
s . write " lib/mofive.rb " , " puts 'five' "
end
build_lib " six " , " 1.0.0 " do | s |
s . write " lib/six.rb " , " puts 'six' "
end
build_lib " seven " , " 1.0.0 " do | s |
s . write " lib/seven.rb " , " puts 'seven' "
end
build_lib " eight " , " 1.0.0 " do | s |
s . write " lib/eight.rb " , " puts 'eight' "
end
end
it " requires the gems " do
script <<-RUBY
gemfile do
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
path " #{ lib_path } " do
gem " two "
end
end
RUBY
expect ( out ) . to eq ( " two " )
2020-06-03 12:43:17 -04:00
script <<-RUBY, :raise_on_error => false
2018-11-02 19:07:56 -04:00
gemfile do
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
path " #{ lib_path } " do
gem " eleven "
end
end
puts " success "
RUBY
2019-06-01 05:49:40 -04:00
expect ( err ) . to include " Could not find gem 'eleven' "
2018-11-02 19:07:56 -04:00
expect ( out ) . not_to include " success "
script <<-RUBY
gemfile ( true ) do
2019-05-06 12:06:21 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
gem " rack "
end
RUBY
expect ( out ) . to include ( " Rack's post install message " )
script <<-RUBY, :artifice => "endpoint"
gemfile ( true ) do
source " https://notaserver.com "
gem " activesupport " , :require = > true
end
RUBY
expect ( out ) . to include ( " Installing activesupport " )
2019-08-30 14:52:46 -04:00
err_lines = err . split ( " \n " )
2022-05-20 04:15:15 -04:00
err_lines . reject! { | line | line =~ / \ .rb: \ d+: warning: / } unless RUBY_VERSION < " 2.7 "
2019-08-30 14:52:46 -04:00
expect ( err_lines ) . to be_empty
2018-11-02 19:07:56 -04:00
end
it " lets me use my own ui object " do
script <<-RUBY, :artifice => "endpoint"
2021-05-28 06:47:49 -04:00
require '#{entrypoint}'
2018-11-02 19:07:56 -04:00
class MyBundlerUI < Bundler :: UI :: Silent
def confirm ( msg , newline = nil )
puts " CONFIRMED! "
end
end
gemfile ( true , :ui = > MyBundlerUI . new ) do
source " https://notaserver.com "
gem " activesupport " , :require = > true
end
RUBY
expect ( out ) . to eq ( " CONFIRMED! \n CONFIRMED! " )
end
2019-04-14 02:01:35 -04:00
it " has an option for quiet installation " do
script <<-RUBY, :artifice => "endpoint"
2021-05-28 06:47:49 -04:00
require '#{entrypoint}/inline'
2019-04-14 02:01:35 -04:00
gemfile ( true , :quiet = > true ) do
source " https://notaserver.com "
gem " activesupport " , :require = > true
end
RUBY
expect ( out ) . to be_empty
end
2018-11-02 19:07:56 -04:00
it " raises an exception if passed unknown arguments " do
2020-06-03 12:43:17 -04:00
script <<-RUBY, :raise_on_error => false
2018-11-02 19:07:56 -04:00
gemfile ( true , :arglebargle = > true ) do
path " #{ lib_path } "
gem " two "
end
puts " success "
RUBY
2019-06-01 05:49:40 -04:00
expect ( err ) . to include " Unknown options: arglebargle "
2018-11-02 19:07:56 -04:00
expect ( out ) . not_to include " success "
end
it " does not mutate the option argument " do
script <<-RUBY
2021-05-28 06:47:49 -04:00
require '#{entrypoint}'
2018-11-02 19:07:56 -04:00
options = { :ui = > Bundler :: UI :: Shell . new }
gemfile ( false , options ) do
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
path " #{ lib_path } " do
gem " two "
end
end
puts " OKAY " if options . key? ( :ui )
RUBY
expect ( out ) . to match ( " OKAY " )
end
it " installs quietly if necessary when the install option is not set " do
script <<-RUBY
gemfile do
2019-05-06 12:06:21 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
gem " rack "
end
puts RACK
RUBY
expect ( out ) . to eq ( " 1.0.0 " )
2019-06-01 05:49:40 -04:00
expect ( err ) . to be_empty
2018-11-02 19:07:56 -04:00
end
it " installs quietly from git if necessary when the install option is not set " do
build_git " foo " , " 1.0.0 "
baz_ref = build_git ( " baz " , " 2.0.0 " ) . ref_for ( " HEAD " )
script <<-RUBY
gemfile do
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
gem " foo " , :git = > #{lib_path("foo-1.0.0").to_s.dump}
gem " baz " , :git = > #{lib_path("baz-2.0.0").to_s.dump}, :ref => #{baz_ref.dump}
end
puts FOO
puts BAZ
RUBY
expect ( out ) . to eq ( " 1.0.0 \n 2.0.0 " )
2019-06-01 05:49:40 -04:00
expect ( err ) . to be_empty
2018-11-02 19:07:56 -04:00
end
it " allows calling gemfile twice " do
script <<-RUBY
gemfile do
path " #{ lib_path } " do
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
gem " two "
end
end
gemfile do
path " #{ lib_path } " do
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
gem " four "
end
end
RUBY
expect ( out ) . to eq ( " two \n four " )
2019-06-01 05:49:40 -04:00
expect ( err ) . to be_empty
2018-11-02 19:07:56 -04:00
end
it " installs inline gems when a Gemfile.lock is present " do
gemfile <<-G
source " https://notaserver.com "
gem " rake "
G
lockfile <<-G
GEM
remote : https : / / rubygems . org /
specs :
rake ( 11 . 3 . 0 )
PLATFORMS
ruby
DEPENDENCIES
rake
BUNDLED WITH
2021-05-28 06:47:49 -04:00
#{Bundler::VERSION}
2018-11-02 19:07:56 -04:00
G
2020-05-08 01:19:04 -04:00
script <<-RUBY
gemfile do
source " #{ file_uri_for ( gem_repo1 ) } "
gem " rack "
end
2018-11-02 19:07:56 -04:00
2020-05-08 01:19:04 -04:00
puts RACK
RUBY
2018-11-02 19:07:56 -04:00
2019-06-01 05:49:40 -04:00
expect ( err ) . to be_empty
end
2022-05-11 08:17:54 -04:00
it " does not leak Gemfile.lock versions to the installation output " do
gemfile <<-G
source " https://notaserver.com "
gem " rake "
G
lockfile <<-G
GEM
remote : https : / / rubygems . org /
specs :
rake ( 11 . 3 . 0 )
PLATFORMS
ruby
DEPENDENCIES
rake
BUNDLED WITH
#{Bundler::VERSION}
G
script <<-RUBY
gemfile ( true ) do
source " #{ file_uri_for ( gem_repo1 ) } "
gem " rake " , " ~> 13.0 "
end
RUBY
expect ( out ) . to include ( " Installing rake 13.0 " )
expect ( out ) . not_to include ( " was 11.3.0 " )
expect ( err ) . to be_empty
end
2019-06-01 05:49:40 -04:00
it " installs inline gems when frozen is set " do
script <<-RUBY, :env => { "BUNDLE_FROZEN" => "true" }
gemfile do
2019-05-06 12:06:21 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2019-06-01 05:49:40 -04:00
gem " rack "
end
puts RACK
RUBY
2019-04-14 02:01:35 -04:00
expect ( last_command . stderr ) . to be_empty
2018-11-02 19:07:56 -04:00
end
2021-04-14 23:47:04 -04:00
it " installs inline gems when deployment is set " do
script <<-RUBY, :env => { "BUNDLE_DEPLOYMENT" => "true" }
gemfile do
source " #{ file_uri_for ( gem_repo1 ) } "
gem " rack "
end
puts RACK
RUBY
expect ( last_command . stderr ) . to be_empty
end
2018-11-02 19:07:56 -04:00
it " installs inline gems when BUNDLE_GEMFILE is set to an empty string " do
ENV [ " BUNDLE_GEMFILE " ] = " "
2020-05-08 01:19:04 -04:00
script <<-RUBY
gemfile do
source " #{ file_uri_for ( gem_repo1 ) } "
gem " rack "
end
2018-11-02 19:07:56 -04:00
2020-05-08 01:19:04 -04:00
puts RACK
RUBY
2018-11-02 19:07:56 -04:00
2019-06-01 05:49:40 -04:00
expect ( err ) . to be_empty
2018-11-02 19:07:56 -04:00
end
it " installs inline gems when BUNDLE_BIN is set " do
ENV [ " BUNDLE_BIN " ] = " /usr/local/bundle/bin "
script <<-RUBY
gemfile do
2019-05-06 12:06:21 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
gem " rack " # has the rackup executable
end
puts RACK
RUBY
expect ( last_command ) . to be_success
2019-06-01 05:49:40 -04:00
expect ( out ) . to eq " 1.0.0 "
end
2019-05-01 20:00:21 -04:00
context " when BUNDLE_PATH is set " do
it " installs inline gems to the system path regardless " do
script <<-RUBY, :env => { "BUNDLE_PATH" => "./vendor/inline" }
gemfile ( true ) do
2021-04-21 07:54:29 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2019-05-01 20:00:21 -04:00
gem " rack "
end
RUBY
expect ( last_command ) . to be_success
expect ( system_gem_path ( " gems/rack-1.0.0 " ) ) . to exist
end
end
2019-06-01 05:49:40 -04:00
it " skips platform warnings " do
2022-01-31 11:45:12 -05:00
bundle " config set --local force_ruby_platform true "
2019-06-01 05:49:40 -04:00
script <<-RUBY
gemfile ( true ) do
2019-05-06 12:06:21 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2019-06-01 05:49:40 -04:00
gem " rack " , platform : :jruby
end
RUBY
expect ( err ) . to be_empty
2018-11-02 19:07:56 -04:00
end
2019-12-14 05:49:16 -05:00
2022-08-19 08:03:43 -04:00
it " still installs if the application has `bundle package` no_install config set " do
bundle " config set --local no_install true "
script <<-RUBY
gemfile do
source " #{ file_uri_for ( gem_repo1 ) } "
gem " rack "
end
RUBY
expect ( last_command ) . to be_success
expect ( system_gem_path ( " gems/rack-1.0.0 " ) ) . to exist
end
2019-12-14 05:49:16 -05:00
it " preserves previous BUNDLE_GEMFILE value " do
ENV [ " BUNDLE_GEMFILE " ] = " "
script <<-RUBY
gemfile do
source " #{ file_uri_for ( gem_repo1 ) } "
gem " rack "
end
puts " BUNDLE_GEMFILE is empty " if ENV [ " BUNDLE_GEMFILE " ] . empty?
system ( " #{ Gem . ruby } -w -e '42' " ) # this should see original value of BUNDLE_GEMFILE
exit $? . exitstatus
RUBY
expect ( last_command ) . to be_success
expect ( out ) . to include ( " BUNDLE_GEMFILE is empty " )
end
2020-01-08 02:11:52 -05:00
it " resets BUNDLE_GEMFILE to the empty string if it wasn't set previously " do
ENV [ " BUNDLE_GEMFILE " ] = nil
script <<-RUBY
gemfile do
source " #{ file_uri_for ( gem_repo1 ) } "
gem " rack "
end
puts " BUNDLE_GEMFILE is empty " if ENV [ " BUNDLE_GEMFILE " ] . empty?
system ( " #{ Gem . ruby } -w -e '42' " ) # this should see original value of BUNDLE_GEMFILE
exit $? . exitstatus
RUBY
expect ( last_command ) . to be_success
expect ( out ) . to include ( " BUNDLE_GEMFILE is empty " )
end
2020-10-15 00:20:25 -04:00
it " does not error out if library requires optional dependencies " do
Dir . mkdir tmp ( " path_without_gemfile " )
foo_code = << ~ RUBY
begin
gem " bar "
rescue LoadError
end
puts " WIN "
RUBY
build_lib " foo " , " 1.0.0 " do | s |
s . write " lib/foo.rb " , foo_code
end
script <<-RUBY, :dir => tmp("path_without_gemfile")
gemfile do
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo2 ) } "
2020-10-15 00:20:25 -04:00
path " #{ lib_path } " do
gem " foo " , require : false
end
end
require " foo "
RUBY
expect ( out ) . to eq ( " WIN " )
expect ( err ) . to be_empty
end
2020-12-08 02:36:29 -05:00
it " when requiring fileutils after does not show redefinition warnings " do
dependency_installer_loads_fileutils = ruby " require 'rubygems/dependency_installer'; puts $LOADED_FEATURES.grep(/fileutils/) " , :raise_on_error = > false
skip " does not work if rubygems/dependency_installer loads fileutils, which happens until rubygems 3.2.0 " unless dependency_installer_loads_fileutils . empty?
2021-10-27 17:46:14 -04:00
skip " pathname does not install cleanly on this ruby " if RUBY_VERSION < " 2.7.0 "
2020-12-08 02:36:29 -05:00
Dir . mkdir tmp ( " path_without_gemfile " )
default_fileutils_version = ruby " gem 'fileutils', '< 999999'; require 'fileutils'; puts FileUtils::VERSION " , :raise_on_error = > false
skip " fileutils isn't a default gem " if default_fileutils_version . empty?
realworld_system_gems " fileutils --version 1.4.1 "
2021-10-27 17:46:14 -04:00
realworld_system_gems " pathname --version 0.2.0 "
2020-12-08 02:36:29 -05:00
realworld_system_gems " timeout uri " # this spec uses net/http which requires these default gems
2022-09-06 00:46:21 -04:00
# on prerelease rubies, a required_rubygems_version constraint is added by RubyGems to the resolution, causing Molinillo to load the `set` gem
realworld_system_gems " set --version 1.0.3 " if Gem . ruby_version . prerelease?
2020-12-08 02:36:29 -05:00
script <<-RUBY, :dir => tmp("path_without_gemfile"), :env => { "BUNDLER_GEM_DEFAULT_DIR" => system_gem_path.to_s }
require " bundler/inline "
gemfile ( true ) do
source " #{ file_uri_for ( gem_repo2 ) } "
end
require " fileutils "
RUBY
expect ( err ) . to eq ( " The Gemfile specifies no dependencies " )
end
2018-11-02 19:07:56 -04:00
end