2018-11-02 19:07:56 -04:00
# frozen_string_literal: true
RSpec . describe " bundle exec " do
let ( :system_gems_to_install ) { %w[ rack-1.0.0 rack-0.9.1 ] }
before :each do
2020-05-08 01:19:04 -04:00
system_gems ( system_gems_to_install , :path = > default_bundle_path )
2018-11-02 19:07:56 -04:00
end
2020-06-11 15:05:17 -04:00
it " works with --gemfile flag " do
2018-11-02 19:07:56 -04:00
create_file " CustomGemfile " , <<-G
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
gem " rack " , " 1.0.0 "
G
bundle " exec --gemfile CustomGemfile rackup "
expect ( out ) . to eq ( " 1.0.0 " )
end
2020-06-11 15:05:17 -04:00
it " activates the correct gem " do
2018-11-02 19:07:56 -04:00
gemfile <<-G
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
gem " rack " , " 0.9.1 "
G
bundle " exec rackup "
expect ( out ) . to eq ( " 0.9.1 " )
end
2021-07-13 07:58:08 -04:00
it " works and prints no warnings when HOME is not writable " do
gemfile <<-G
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2021-07-13 07:58:08 -04:00
gem " rack " , " 0.9.1 "
G
bundle " exec rackup " , :env = > { " HOME " = > " / " }
expect ( out ) . to eq ( " 0.9.1 " )
expect ( err ) . to be_empty
end
2020-06-11 15:05:17 -04:00
it " works when the bins are in ~/.bundle " do
2018-11-02 19:07:56 -04:00
install_gemfile <<-G
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
gem " rack "
G
bundle " exec rackup "
expect ( out ) . to eq ( " 1.0.0 " )
end
2020-06-11 15:05:17 -04:00
it " works when running from a random directory " do
2018-11-02 19:07:56 -04:00
install_gemfile <<-G
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
gem " rack "
G
2019-04-14 02:01:35 -04:00
bundle " exec 'cd #{ tmp ( " gems " ) } && rackup' "
2018-11-02 19:07:56 -04:00
2019-04-26 13:02:19 -04:00
expect ( out ) . to eq ( " 1.0.0 " )
2018-11-02 19:07:56 -04:00
end
it " works when exec'ing something else " do
2021-07-24 11:27:02 -04:00
install_gemfile " source \" #{ file_uri_for ( gem_repo1 ) } \" ; gem \" rack \" "
2018-11-02 19:07:56 -04:00
bundle " exec echo exec "
expect ( out ) . to eq ( " exec " )
end
it " works when exec'ing to ruby " do
2021-07-24 11:27:02 -04:00
install_gemfile " source \" #{ file_uri_for ( gem_repo1 ) } \" ; gem \" rack \" "
2019-04-14 02:01:35 -04:00
bundle " exec ruby -e 'puts %{hi}' "
2018-11-02 19:07:56 -04:00
expect ( out ) . to eq ( " hi " )
end
2019-12-14 05:49:16 -05:00
it " works when exec'ing to rubygems " do
2021-07-24 11:27:02 -04:00
install_gemfile " source \" #{ file_uri_for ( gem_repo1 ) } \" ; gem \" rack \" "
2019-12-14 07:19:28 -05:00
bundle " exec #{ gem_cmd } --version "
2019-12-14 05:49:16 -05:00
expect ( out ) . to eq ( Gem :: VERSION )
end
2019-12-18 00:53:19 -05:00
it " works when exec'ing to rubygems through sh -c " do
2021-07-24 11:27:02 -04:00
install_gemfile " source \" #{ file_uri_for ( gem_repo1 ) } \" ; gem \" rack \" "
2019-12-18 00:53:19 -05:00
bundle " exec sh -c ' #{ gem_cmd } --version' "
expect ( out ) . to eq ( Gem :: VERSION )
end
2020-12-22 18:45:19 -05:00
it " works when exec'ing back to bundler with a lockfile that doesn't include the current platform " do
install_gemfile <<-G
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2020-12-22 18:45:19 -05:00
gem " rack " , " 0.9.1 "
G
# simulate lockfile generated with old version not including specific platform
lockfile <<-L
GEM
2021-07-24 11:27:02 -04:00
remote : #{file_uri_for(gem_repo1)}/
2020-12-22 18:45:19 -05:00
specs :
rack ( 0 . 9 . 1 )
PLATFORMS
RUBY
DEPENDENCIES
rack ( = 0 . 9 . 1 )
BUNDLED WITH
2 . 1 . 4
L
bundle " exec bundle cache " , :env = > { " BUNDLER_VERSION " = > Bundler :: VERSION }
expect ( out ) . to include ( " Updating files in vendor/cache " )
end
2020-06-14 15:03:42 -04:00
it " respects custom process title when loading through ruby " do
2020-12-08 02:36:29 -05:00
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
2020-05-08 01:19:04 -04:00
Fix some bundler specs (#2380)
* These seem to consistenly pass already
* Show actual command when running `make test-bundler`
Current the setup command that installs the necessary gems for testing
bundler was printed, but not the actual command that runs the tests.
That was a bit confusing.
* Borrow trick from setproctitle specs
* A title that long doesn't get set sometimes
No idea why, but the test doesn't need that the title is that long.
* Fix most gem helper spec ruby-core failures
* Fix the rest of the gem helper failures
* Fix version spec by improving the assertion
* Remove unnecessary `BUNDLE_RUBY` environment var
We can use `RUBY` when necessary, and `BUNDLE_RUBY` is not a good name
because bundler considers `BUNDLE_*` variables as settings.
* Rename `BUNDLE_GEM` to `GEM_COMMAND`
This is more descriptive I think, and also friendlier for bundler
because `BUNDLE_` env variables are interpreted by bundler as settings,
and this is not a bundler setting.
This fixes one bundler spec failure in config specs against ruby-core.
* Fix quality spec when run in core
Use the proper path helper.
* Fix dummy lib builder to never load default gems
If a dummy library is named as a default gem, when requiring the library
from its executable, the default gem would be loaded when running from
core, because in core all default gems share path with bundler, and thus
they are always in the $LOAD_PATH. We fix the issue by loading lib
relatively inside dummy lib executables.
* More exact assertions
Sometimes I have the problem that I do some "print debugging" inside
specs, and suddently the spec passes. This happens when the assertion is
too relaxed, and the things I print make it match, specially when they
are simple strings like "1.0" than can be easily be part of gem paths
that I print for debugging.
I fix this by making a more exact assertion.
* Detect the correct shebang when ENV["RUBY"] is set
* Relax assertion
So that the spec passes even if another paths containing "ext" are in
the load path. This works to fix a ruby-core issue, but it's a better
assertion in general. We just want to know that the extension path was
added.
* Use folder structure independent path helper
It should fix this spec for ruby-core.
* Fix the last failing spec on ruby-core
* Skip `bundle open <default_gem>` spec when no default gems
2019-08-19 20:46:31 -04:00
script_that_changes_its_own_title_and_checks_if_picked_up_by_ps_unix_utility = << ~ 'RUBY'
2020-06-14 15:03:42 -04:00
Process . setproctitle ( " 1-2-3-4-5-6-7 " )
Fix some bundler specs (#2380)
* These seem to consistenly pass already
* Show actual command when running `make test-bundler`
Current the setup command that installs the necessary gems for testing
bundler was printed, but not the actual command that runs the tests.
That was a bit confusing.
* Borrow trick from setproctitle specs
* A title that long doesn't get set sometimes
No idea why, but the test doesn't need that the title is that long.
* Fix most gem helper spec ruby-core failures
* Fix the rest of the gem helper failures
* Fix version spec by improving the assertion
* Remove unnecessary `BUNDLE_RUBY` environment var
We can use `RUBY` when necessary, and `BUNDLE_RUBY` is not a good name
because bundler considers `BUNDLE_*` variables as settings.
* Rename `BUNDLE_GEM` to `GEM_COMMAND`
This is more descriptive I think, and also friendlier for bundler
because `BUNDLE_` env variables are interpreted by bundler as settings,
and this is not a bundler setting.
This fixes one bundler spec failure in config specs against ruby-core.
* Fix quality spec when run in core
Use the proper path helper.
* Fix dummy lib builder to never load default gems
If a dummy library is named as a default gem, when requiring the library
from its executable, the default gem would be loaded when running from
core, because in core all default gems share path with bundler, and thus
they are always in the $LOAD_PATH. We fix the issue by loading lib
relatively inside dummy lib executables.
* More exact assertions
Sometimes I have the problem that I do some "print debugging" inside
specs, and suddently the spec passes. This happens when the assertion is
too relaxed, and the things I print make it match, specially when they
are simple strings like "1.0" than can be easily be part of gem paths
that I print for debugging.
I fix this by making a more exact assertion.
* Detect the correct shebang when ENV["RUBY"] is set
* Relax assertion
So that the spec passes even if another paths containing "ext" are in
the load path. This works to fix a ruby-core issue, but it's a better
assertion in general. We just want to know that the extension path was
added.
* Use folder structure independent path helper
It should fix this spec for ruby-core.
* Fix the last failing spec on ruby-core
* Skip `bundle open <default_gem>` spec when no default gems
2019-08-19 20:46:31 -04:00
puts ` ps -ocommand= -p #{ $$ } `
2019-06-01 05:49:40 -04:00
RUBY
2021-07-24 11:27:02 -04:00
create_file " Gemfile " , " source \" #{ file_uri_for ( gem_repo1 ) } \" "
2019-06-01 05:49:40 -04:00
create_file " a.rb " , script_that_changes_its_own_title_and_checks_if_picked_up_by_ps_unix_utility
bundle " exec ruby a.rb "
2020-06-14 15:03:42 -04:00
expect ( out ) . to eq ( " 1-2-3-4-5-6-7 " )
2019-06-01 05:49:40 -04:00
end
2018-11-02 19:07:56 -04:00
it " accepts --verbose " do
2021-07-24 11:27:02 -04:00
install_gemfile " source \" #{ file_uri_for ( gem_repo1 ) } \" ; gem \" rack \" "
2018-11-02 19:07:56 -04:00
bundle " exec --verbose echo foobar "
expect ( out ) . to eq ( " foobar " )
end
it " passes --verbose to command if it is given after the command " do
2021-07-24 11:27:02 -04:00
install_gemfile " source \" #{ file_uri_for ( gem_repo1 ) } \" ; gem \" rack \" "
2018-11-02 19:07:56 -04:00
bundle " exec echo --verbose "
expect ( out ) . to eq ( " --verbose " )
end
it " handles --keep-file-descriptors " do
2020-12-08 02:36:29 -05:00
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
2020-05-08 01:19:04 -04:00
2018-11-02 19:07:56 -04:00
require " tempfile "
command = Tempfile . new ( " io-test " )
command . sync = true
command . write <<-G
if ARGV [ 0 ]
IO . for_fd ( ARGV [ 0 ] . to_i )
else
require 'tempfile'
io = Tempfile . new ( " io-test-fd " )
2019-11-11 03:57:45 -05:00
args = %W[ #{ Gem . ruby } -I #{ lib_dir } #{ bindir . join ( " bundle " ) } exec --keep-file-descriptors #{ Gem . ruby } #{ command . path } \# {io.to_i} ]
2019-04-14 02:01:35 -04:00
args << { io . to_i = > io }
2018-11-02 19:07:56 -04:00
exec ( * args )
end
G
2021-07-24 11:27:02 -04:00
install_gemfile " source \" #{ file_uri_for ( gem_repo1 ) } \" "
2019-04-14 02:01:35 -04:00
sys_exec " #{ Gem . ruby } #{ command . path } "
2018-11-02 19:07:56 -04:00
2019-12-14 05:49:16 -05:00
expect ( out ) . to be_empty
2019-06-01 05:49:40 -04:00
expect ( err ) . to be_empty
2018-11-02 19:07:56 -04:00
end
it " accepts --keep-file-descriptors " do
2021-07-24 11:27:02 -04:00
install_gemfile " source \" #{ file_uri_for ( gem_repo1 ) } \" "
2018-11-02 19:07:56 -04:00
bundle " exec --keep-file-descriptors echo foobar "
2019-06-01 05:49:40 -04:00
expect ( err ) . to be_empty
2018-11-02 19:07:56 -04:00
end
it " can run a command named --verbose " do
2020-12-08 02:36:29 -05:00
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
2020-05-08 01:19:04 -04:00
2021-07-24 11:27:02 -04:00
install_gemfile " source \" #{ file_uri_for ( gem_repo1 ) } \" ; gem \" rack \" "
2020-05-08 01:19:04 -04:00
File . open ( bundled_app ( " --verbose " ) , " w " ) do | f |
2018-11-02 19:07:56 -04:00
f . puts " # !/bin/sh "
f . puts " echo foobar "
end
2020-05-08 01:19:04 -04:00
File . chmod ( 0 o744 , bundled_app ( " --verbose " ) )
2018-11-02 19:07:56 -04:00
with_path_as ( " . " ) do
bundle " exec -- --verbose "
end
expect ( out ) . to eq ( " foobar " )
end
it " handles different versions in different bundles " do
build_repo2 do
build_gem " rack_two " , " 1.0.0 " do | s |
s . executables = " rackup "
end
end
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 " , " 0.9.1 "
G
2020-05-08 01:19:04 -04:00
install_gemfile bundled_app2 ( " Gemfile " ) , <<-G, :dir => bundled_app2
source " #{ file_uri_for ( gem_repo2 ) } "
gem " rack_two " , " 1.0.0 "
G
2018-11-02 19:07:56 -04:00
2020-06-03 14:45:36 -04:00
bundle " exec rackup "
2018-11-02 19:07:56 -04:00
expect ( out ) . to eq ( " 0.9.1 " )
2020-06-03 14:45:36 -04:00
bundle " exec rackup " , :dir = > bundled_app2
2020-05-08 01:19:04 -04:00
expect ( out ) . to eq ( " 1.0.0 " )
2018-11-02 19:07:56 -04:00
end
2019-04-14 02:01:35 -04:00
context " with default gems " do
let ( :system_gems_to_install ) { [ ] }
2020-06-03 12:43:17 -04:00
let ( :default_irb_version ) { ruby " gem 'irb', '< 999999'; require 'irb'; puts IRB::VERSION " , :raise_on_error = > false }
2019-04-14 02:01:35 -04:00
context " when not specified in Gemfile " do
before do
skip " irb isn't a default gem " if default_irb_version . empty?
2021-07-24 11:27:02 -04:00
install_gemfile " source \" #{ file_uri_for ( gem_repo1 ) } \" "
2019-04-14 02:01:35 -04:00
end
it " uses version provided by ruby " do
2020-06-03 14:45:36 -04:00
bundle " exec irb --version "
2019-04-14 02:01:35 -04:00
expect ( out ) . to include ( default_irb_version )
end
end
context " when specified in Gemfile directly " do
let ( :specified_irb_version ) { " 0.9.6 " }
before do
skip " irb isn't a default gem " if default_irb_version . empty?
build_repo2 do
build_gem " irb " , specified_irb_version do | s |
s . executables = " irb "
end
end
install_gemfile <<-G
2019-05-06 12:06:21 -04:00
source " #{ file_uri_for ( gem_repo2 ) } "
2019-04-14 02:01:35 -04:00
gem " irb " , " #{ specified_irb_version } "
G
end
it " uses version specified " do
2020-06-03 14:45:36 -04:00
bundle " exec irb --version "
2019-04-14 02:01:35 -04:00
Fix some bundler specs (#2380)
* These seem to consistenly pass already
* Show actual command when running `make test-bundler`
Current the setup command that installs the necessary gems for testing
bundler was printed, but not the actual command that runs the tests.
That was a bit confusing.
* Borrow trick from setproctitle specs
* A title that long doesn't get set sometimes
No idea why, but the test doesn't need that the title is that long.
* Fix most gem helper spec ruby-core failures
* Fix the rest of the gem helper failures
* Fix version spec by improving the assertion
* Remove unnecessary `BUNDLE_RUBY` environment var
We can use `RUBY` when necessary, and `BUNDLE_RUBY` is not a good name
because bundler considers `BUNDLE_*` variables as settings.
* Rename `BUNDLE_GEM` to `GEM_COMMAND`
This is more descriptive I think, and also friendlier for bundler
because `BUNDLE_` env variables are interpreted by bundler as settings,
and this is not a bundler setting.
This fixes one bundler spec failure in config specs against ruby-core.
* Fix quality spec when run in core
Use the proper path helper.
* Fix dummy lib builder to never load default gems
If a dummy library is named as a default gem, when requiring the library
from its executable, the default gem would be loaded when running from
core, because in core all default gems share path with bundler, and thus
they are always in the $LOAD_PATH. We fix the issue by loading lib
relatively inside dummy lib executables.
* More exact assertions
Sometimes I have the problem that I do some "print debugging" inside
specs, and suddently the spec passes. This happens when the assertion is
too relaxed, and the things I print make it match, specially when they
are simple strings like "1.0" than can be easily be part of gem paths
that I print for debugging.
I fix this by making a more exact assertion.
* Detect the correct shebang when ENV["RUBY"] is set
* Relax assertion
So that the spec passes even if another paths containing "ext" are in
the load path. This works to fix a ruby-core issue, but it's a better
assertion in general. We just want to know that the extension path was
added.
* Use folder structure independent path helper
It should fix this spec for ruby-core.
* Fix the last failing spec on ruby-core
* Skip `bundle open <default_gem>` spec when no default gems
2019-08-19 20:46:31 -04:00
expect ( out ) . to eq ( specified_irb_version )
2019-06-01 05:49:40 -04:00
expect ( err ) . to be_empty
2019-04-14 02:01:35 -04:00
end
end
context " when specified in Gemfile indirectly " do
let ( :indirect_irb_version ) { " 0.9.6 " }
before do
skip " irb isn't a default gem " if default_irb_version . empty?
build_repo2 do
build_gem " irb " , indirect_irb_version do | s |
s . executables = " irb "
end
build_gem " gem_depending_on_old_irb " do | s |
s . add_dependency " irb " , indirect_irb_version
end
end
install_gemfile <<-G
2019-05-06 12:06:21 -04:00
source " #{ file_uri_for ( gem_repo2 ) } "
2019-04-14 02:01:35 -04:00
gem " gem_depending_on_old_irb "
G
2020-06-03 14:45:36 -04:00
bundle " exec irb --version "
2019-04-14 02:01:35 -04:00
end
it " uses resolved version " do
Fix some bundler specs (#2380)
* These seem to consistenly pass already
* Show actual command when running `make test-bundler`
Current the setup command that installs the necessary gems for testing
bundler was printed, but not the actual command that runs the tests.
That was a bit confusing.
* Borrow trick from setproctitle specs
* A title that long doesn't get set sometimes
No idea why, but the test doesn't need that the title is that long.
* Fix most gem helper spec ruby-core failures
* Fix the rest of the gem helper failures
* Fix version spec by improving the assertion
* Remove unnecessary `BUNDLE_RUBY` environment var
We can use `RUBY` when necessary, and `BUNDLE_RUBY` is not a good name
because bundler considers `BUNDLE_*` variables as settings.
* Rename `BUNDLE_GEM` to `GEM_COMMAND`
This is more descriptive I think, and also friendlier for bundler
because `BUNDLE_` env variables are interpreted by bundler as settings,
and this is not a bundler setting.
This fixes one bundler spec failure in config specs against ruby-core.
* Fix quality spec when run in core
Use the proper path helper.
* Fix dummy lib builder to never load default gems
If a dummy library is named as a default gem, when requiring the library
from its executable, the default gem would be loaded when running from
core, because in core all default gems share path with bundler, and thus
they are always in the $LOAD_PATH. We fix the issue by loading lib
relatively inside dummy lib executables.
* More exact assertions
Sometimes I have the problem that I do some "print debugging" inside
specs, and suddently the spec passes. This happens when the assertion is
too relaxed, and the things I print make it match, specially when they
are simple strings like "1.0" than can be easily be part of gem paths
that I print for debugging.
I fix this by making a more exact assertion.
* Detect the correct shebang when ENV["RUBY"] is set
* Relax assertion
So that the spec passes even if another paths containing "ext" are in
the load path. This works to fix a ruby-core issue, but it's a better
assertion in general. We just want to know that the extension path was
added.
* Use folder structure independent path helper
It should fix this spec for ruby-core.
* Fix the last failing spec on ruby-core
* Skip `bundle open <default_gem>` spec when no default gems
2019-08-19 20:46:31 -04:00
expect ( out ) . to eq ( indirect_irb_version )
2019-06-01 05:49:40 -04:00
expect ( err ) . to be_empty
2019-04-14 02:01:35 -04:00
end
end
end
it " warns about executable conflicts " do
build_repo2 do
build_gem " rack_two " , " 1.0.0 " do | s |
s . executables = " rackup "
end
end
2022-02-27 20:32:28 -05:00
bundle " config set --global path.system true "
2019-04-14 02:01:35 -04:00
install_gemfile <<-G
2019-05-06 12:06:21 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2019-04-14 02:01:35 -04:00
gem " rack " , " 0.9.1 "
G
2020-05-08 01:19:04 -04:00
install_gemfile bundled_app2 ( " Gemfile " ) , <<-G, :dir => bundled_app2
source " #{ file_uri_for ( gem_repo2 ) } "
gem " rack_two " , " 1.0.0 "
G
2019-04-14 02:01:35 -04:00
2020-06-03 14:45:36 -04:00
bundle " exec rackup "
2019-04-14 02:01:35 -04:00
expect ( last_command . stderr ) . to eq (
" Bundler is using a binstub that was created for a different gem (rack). \n " \
" You should run `bundle binstub rack_two` to work around a system/bundle conflict. "
)
end
2020-06-11 15:05:17 -04:00
it " handles gems installed with --without " do
2021-01-03 20:11:34 -05:00
bundle " config set --local without middleware "
2020-05-29 06:46:16 -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 " # rack 0.9.1 and 1.0 exist
group :middleware do
gem " rack_middleware " # rack_middleware depends on rack 0.9.1
end
G
bundle " exec rackup "
expect ( out ) . to eq ( " 0.9.1 " )
expect ( the_bundle ) . not_to include_gems " rack_middleware 1.0 "
end
it " does not duplicate already exec'ed RUBYOPT " do
2020-12-08 02:36:29 -05:00
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
2020-05-08 01:19:04 -04:00
2018-11-02 19:07:56 -04:00
install_gemfile <<-G
2021-07-24 11:27:02 -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
bundler_setup_opt = " -r #{ lib_dir } /bundler/setup "
rubyopt = opt_add ( bundler_setup_opt , ENV [ " RUBYOPT " ] )
2018-11-02 19:07:56 -04:00
bundle " exec 'echo $RUBYOPT' "
2020-05-08 01:19:04 -04:00
expect ( out . split ( " " ) . count ( bundler_setup_opt ) ) . to eq ( 1 )
2018-11-02 19:07:56 -04:00
bundle " exec 'echo $RUBYOPT' " , :env = > { " RUBYOPT " = > rubyopt }
2020-05-08 01:19:04 -04:00
expect ( out . split ( " " ) . count ( bundler_setup_opt ) ) . to eq ( 1 )
2018-11-02 19:07:56 -04:00
end
it " does not duplicate already exec'ed RUBYLIB " do
2020-12-08 02:36:29 -05:00
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
2020-05-08 01:19:04 -04:00
2018-11-02 19:07:56 -04:00
install_gemfile <<-G
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
gem " rack "
G
rubylib = ENV [ " RUBYLIB " ]
2019-11-11 03:57:45 -05:00
rubylib = rubylib . to_s . split ( File :: PATH_SEPARATOR ) . unshift lib_dir . to_s
2018-11-02 19:07:56 -04:00
rubylib = rubylib . uniq . join ( File :: PATH_SEPARATOR )
bundle " exec 'echo $RUBYLIB' "
expect ( out ) . to include ( rubylib )
bundle " exec 'echo $RUBYLIB' " , :env = > { " RUBYLIB " = > rubylib }
expect ( out ) . to include ( rubylib )
end
it " errors nicely when the argument doesn't exist " do
install_gemfile <<-G
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
gem " rack "
G
2020-06-03 12:43:17 -04:00
bundle " exec foobarbaz " , :raise_on_error = > false
2020-06-24 13:53:16 -04:00
expect ( exitstatus ) . to eq ( 127 )
2019-04-14 02:01:35 -04:00
expect ( err ) . to include ( " bundler: command not found: foobarbaz " )
expect ( err ) . to include ( " Install missing gem executables with `bundle install` " )
2018-11-02 19:07:56 -04:00
end
it " errors nicely when the argument is not executable " do
install_gemfile <<-G
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
gem " rack "
G
bundle " exec touch foo "
2020-06-03 12:43:17 -04:00
bundle " exec ./foo " , :raise_on_error = > false
2020-06-24 13:53:16 -04:00
expect ( exitstatus ) . to eq ( 126 )
2019-04-14 02:01:35 -04:00
expect ( err ) . to include ( " bundler: not executable: ./foo " )
2018-11-02 19:07:56 -04:00
end
it " errors nicely when no arguments are passed " do
install_gemfile <<-G
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
gem " rack "
G
2020-06-03 12:43:17 -04:00
bundle " exec " , :raise_on_error = > false
2020-06-24 13:53:16 -04:00
expect ( exitstatus ) . to eq ( 128 )
2019-04-14 02:01:35 -04:00
expect ( err ) . to include ( " bundler: exec needs a command to run " )
2018-11-02 19:07:56 -04:00
end
2020-06-11 15:05:17 -04:00
it " raises a helpful error when exec'ing to something outside of the bundle " do
2020-06-03 14:45:36 -04:00
bundle " config set clean false " # want to keep the rackup binstub
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 ) } "
2020-12-08 02:36:29 -05:00
gem " foo "
2018-11-02 19:07:56 -04:00
G
[ true , false ] . each do | l |
2020-06-03 14:45:36 -04:00
bundle " config set disable_exec_load #{ l } "
2020-06-03 12:43:17 -04:00
bundle " exec rackup " , :raise_on_error = > false
2019-06-01 05:49:40 -04:00
expect ( err ) . to include " can't find executable rackup for gem rack. rack is not currently included in the bundle, perhaps you meant to add it to your Gemfile? "
2018-11-02 19:07:56 -04:00
end
end
describe " with help flags " do
each_prefix = proc do | string , & blk |
1 . upto ( string . length ) { | l | blk . call ( string [ 0 , l ] ) }
end
each_prefix . call ( " exec " ) do | exec |
describe " when #{ exec } is used " do
before ( :each ) do
2020-12-08 02:36:29 -05:00
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
2020-05-08 01:19:04 -04:00
2018-11-02 19:07:56 -04:00
install_gemfile <<-G
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
gem " rack "
G
create_file ( " print_args " , <<-'RUBY')
#!/usr/bin/env ruby
puts " args: #{ ARGV . inspect } "
RUBY
bundled_app ( " print_args " ) . chmod ( 0 o755 )
end
it " shows executable's man page when --help is after the executable " do
bundle " #{ exec } print_args --help "
expect ( out ) . to eq ( 'args: ["--help"]' )
end
it " shows executable's man page when --help is after the executable and an argument " do
bundle " #{ exec } print_args foo --help "
expect ( out ) . to eq ( 'args: ["foo", "--help"]' )
bundle " #{ exec } print_args foo bar --help "
expect ( out ) . to eq ( 'args: ["foo", "bar", "--help"]' )
bundle " #{ exec } print_args foo --help bar "
expect ( out ) . to eq ( 'args: ["foo", "--help", "bar"]' )
end
it " shows executable's man page when the executable has a - " do
FileUtils . mv ( bundled_app ( " print_args " ) , bundled_app ( " docker-template " ) )
bundle " #{ exec } docker-template build discourse --help "
expect ( out ) . to eq ( 'args: ["build", "discourse", "--help"]' )
end
it " shows executable's man page when --help is after another flag " do
bundle " #{ exec } print_args --bar --help "
expect ( out ) . to eq ( 'args: ["--bar", "--help"]' )
end
it " uses executable's original behavior for -h " do
bundle " #{ exec } print_args -h "
expect ( out ) . to eq ( 'args: ["-h"]' )
end
it " shows bundle-exec's man page when --help is between exec and the executable " do
with_fake_man do
bundle " #{ exec } --help cat "
end
2021-01-03 20:11:34 -05:00
expect ( out ) . to include ( %( [" #{ man_dir } /bundle-exec.1"] ) )
2018-11-02 19:07:56 -04:00
end
it " shows bundle-exec's man page when --help is before exec " do
with_fake_man do
bundle " --help #{ exec } "
end
2021-01-03 20:11:34 -05:00
expect ( out ) . to include ( %( [" #{ man_dir } /bundle-exec.1"] ) )
2018-11-02 19:07:56 -04:00
end
it " shows bundle-exec's man page when -h is before exec " do
with_fake_man do
bundle " -h #{ exec } "
end
2021-01-03 20:11:34 -05:00
expect ( out ) . to include ( %( [" #{ man_dir } /bundle-exec.1"] ) )
2018-11-02 19:07:56 -04:00
end
it " shows bundle-exec's man page when --help is after exec " do
with_fake_man do
bundle " #{ exec } --help "
end
2021-01-03 20:11:34 -05:00
expect ( out ) . to include ( %( [" #{ man_dir } /bundle-exec.1"] ) )
2018-11-02 19:07:56 -04:00
end
it " shows bundle-exec's man page when -h is after exec " do
with_fake_man do
bundle " #{ exec } -h "
end
2021-01-03 20:11:34 -05:00
expect ( out ) . to include ( %( [" #{ man_dir } /bundle-exec.1"] ) )
2018-11-02 19:07:56 -04:00
end
end
end
end
describe " with gem executables " do
2020-06-11 15:05:17 -04:00
describe " run from a random directory " do
2018-11-02 19:07:56 -04:00
before ( :each ) do
install_gemfile <<-G
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
gem " rack "
G
end
it " works when unlocked " do
2019-04-14 02:01:35 -04:00
bundle " exec 'cd #{ tmp ( " gems " ) } && rackup' "
2018-11-02 19:07:56 -04:00
expect ( out ) . to eq ( " 1.0.0 " )
end
it " works when locked " do
expect ( the_bundle ) . to be_locked
2019-04-14 02:01:35 -04:00
bundle " exec 'cd #{ tmp ( " gems " ) } && rackup' "
2019-04-26 13:02:19 -04:00
expect ( out ) . to eq ( " 1.0.0 " )
2018-11-02 19:07:56 -04:00
end
end
describe " from gems bundled via :path " do
before ( :each ) do
build_lib " fizz " , :path = > home ( " fizz " ) do | s |
s . executables = " fizz "
end
install_gemfile <<-G
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
gem " fizz " , :path = > " #{ File . expand_path ( home ( " fizz " ) ) } "
G
end
it " works when unlocked " do
bundle " exec fizz "
expect ( out ) . to eq ( " 1.0 " )
end
it " works when locked " do
expect ( the_bundle ) . to be_locked
bundle " exec fizz "
expect ( out ) . to eq ( " 1.0 " )
end
end
describe " from gems bundled via :git " do
before ( :each ) do
build_git " fizz_git " do | s |
s . executables = " fizz_git "
end
install_gemfile <<-G
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
gem " fizz_git " , :git = > " #{ lib_path ( " fizz_git-1.0 " ) } "
G
end
it " works when unlocked " do
bundle " exec fizz_git "
expect ( out ) . to eq ( " 1.0 " )
end
it " works when locked " do
expect ( the_bundle ) . to be_locked
bundle " exec fizz_git "
expect ( out ) . to eq ( " 1.0 " )
end
end
describe " from gems bundled via :git with no gemspec " do
before ( :each ) do
build_git " fizz_no_gemspec " , :gemspec = > false do | s |
s . executables = " fizz_no_gemspec "
end
install_gemfile <<-G
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
gem " fizz_no_gemspec " , " 1.0 " , :git = > " #{ lib_path ( " fizz_no_gemspec-1.0 " ) } "
G
end
it " works when unlocked " do
bundle " exec fizz_no_gemspec "
expect ( out ) . to eq ( " 1.0 " )
end
it " works when locked " do
expect ( the_bundle ) . to be_locked
bundle " exec fizz_no_gemspec "
expect ( out ) . to eq ( " 1.0 " )
end
end
end
it " performs an automatic bundle install " 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 " rack " , " 0.9.1 "
gem " foo "
G
2019-04-14 02:01:35 -04:00
bundle " config set auto_install 1 "
2018-11-02 19:07:56 -04:00
bundle " exec rackup "
expect ( out ) . to include ( " Installing foo 1.0 " )
end
2021-11-16 06:19:13 -05:00
it " loads the correct optparse when `auto_install` is set, and optparse is a dependency " do
if Gem . ruby_version > = Gem :: Version . new ( " 3.0.0 " ) && Gem . rubygems_version < Gem :: Version . new ( " 3.3.0.a " )
2021-12-14 07:14:58 -05:00
skip " optparse is a default gem, and rubygems loads it during install "
2021-11-16 06:19:13 -05:00
end
build_repo4 do
build_gem " fastlane " , " 2.192.0 " do | s |
s . executables = " fastlane "
2021-12-14 07:14:58 -05:00
s . add_dependency " optparse " , " ~> 999.999.999 "
2021-11-16 06:19:13 -05:00
end
2021-12-14 07:14:58 -05:00
build_gem " optparse " , " 999.999.998 "
build_gem " optparse " , " 999.999.999 "
2021-11-16 06:19:13 -05:00
end
2021-12-14 07:14:58 -05:00
system_gems " optparse-999.999.998 " , :gem_repo = > gem_repo4
2021-11-16 06:19:13 -05:00
bundle " config set auto_install 1 "
bundle " config set --local path vendor/bundle "
gemfile << ~ G
source " #{ file_uri_for ( gem_repo4 ) } "
gem " fastlane "
G
bundle " exec fastlane "
2021-12-14 07:14:58 -05:00
expect ( out ) . to include ( " Installing optparse 999.999.999 " )
2021-11-16 06:19:13 -05:00
expect ( out ) . to include ( " 2.192.0 " )
end
2019-04-14 02:05:27 -04:00
describe " with gems bundled via :path with invalid gemspecs " do
2019-04-14 02:01:35 -04:00
it " outputs the gemspec validation errors " do
2018-11-02 19:07:56 -04:00
build_lib " foo "
gemspec = lib_path ( " foo-1.0 " ) . join ( " foo.gemspec " ) . to_s
File . open ( gemspec , " w " ) do | f |
f . write <<-G
Gem :: Specification . new do | s |
s . name = 'foo'
s . version = '1.0'
s . summary = 'TODO: Add summary'
s . authors = 'Me'
end
G
end
2020-06-07 08:16:42 -04:00
gemfile <<-G
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
gem " foo " , :path = > " #{ lib_path ( " foo-1.0 " ) } "
G
2020-06-03 12:43:17 -04:00
bundle " exec irb " , :raise_on_error = > false
2018-11-02 19:07:56 -04:00
2019-06-01 05:49:40 -04:00
expect ( err ) . to match ( " The gemspec at #{ lib_path ( " foo-1.0 " ) . join ( " foo.gemspec " ) } is not valid " )
expect ( err ) . to match ( '"TODO" is not a summary' )
2018-11-02 19:07:56 -04:00
end
end
describe " with gems bundled for deployment " do
2020-06-11 15:05:17 -04:00
it " works when calling bundler from another script " do
2020-12-08 02:36:29 -05:00
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
2020-05-08 01:19:04 -04:00
2018-11-02 19:07:56 -04:00
gemfile <<-G
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
module Monkey
def bin_path ( a , b , c )
raise Gem :: GemNotFoundException . new ( 'Fail' )
end
end
Bundler . rubygems . extend ( Monkey )
G
2020-06-03 14:45:36 -04:00
bundle " config set path.system true "
bundle " install "
2020-05-15 08:31:12 -04:00
bundle " exec ruby -e '`bundle -v`; puts $?.success?' " , :env = > { " BUNDLER_VERSION " = > Bundler :: VERSION }
2018-11-02 19:07:56 -04:00
expect ( out ) . to match ( " true " )
end
end
context " `load`ing a ruby file instead of `exec`ing " do
let ( :path ) { bundled_app ( " ruby_executable " ) }
let ( :shebang ) { " # !/usr/bin/env ruby " }
let ( :executable ) { <<-RUBY.gsub(/^ */, "").strip }
#{shebang}
require " rack "
puts " EXEC: \# {caller.grep(/load/).empty? ? 'exec' : 'load'} "
puts " ARGS: \# {$0} \# {ARGV.join(' ')} "
puts " RACK: \# {RACK} "
process_title = ` ps -o args -p \# {Process.pid} ` . split ( " \n " , 2 ) . last . strip
puts " PROCESS: \# {process_title} "
RUBY
before do
2020-05-08 01:19:04 -04:00
bundled_app ( path ) . open ( " w " ) { | f | f << executable }
bundled_app ( path ) . chmod ( 0 o755 )
2018-11-02 19:07:56 -04:00
install_gemfile <<-G
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
gem " rack "
G
end
let ( :exec ) { " EXEC: load " }
let ( :args ) { " ARGS: #{ path } arg1 arg2 " }
let ( :rack ) { " RACK: 1.0.0 " }
let ( :process ) do
title = " PROCESS: #{ path } "
2019-04-14 02:01:35 -04:00
title += " arg1 arg2 "
2018-11-02 19:07:56 -04:00
title
end
let ( :exit_code ) { 0 }
let ( :expected ) { [ exec , args , rack , process ] . join ( " \n " ) }
let ( :expected_err ) { " " }
2020-06-03 12:43:17 -04:00
subject { bundle " exec #{ path } arg1 arg2 " , :raise_on_error = > false }
2018-11-02 19:07:56 -04:00
2021-02-01 10:17:16 -05:00
it " runs " do
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
2020-05-08 01:19:04 -04:00
2021-02-01 10:17:16 -05:00
subject
expect ( exitstatus ) . to eq ( exit_code )
expect ( err ) . to eq ( expected_err )
expect ( out ) . to eq ( expected )
2018-11-02 19:07:56 -04:00
end
context " the executable exits explicitly " do
let ( :executable ) { super ( ) << " \n exit #{ exit_code } \n puts 'POST_EXIT' \n " }
context " with exit 0 " do
2021-02-01 10:17:16 -05:00
it " runs " do
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
subject
expect ( exitstatus ) . to eq ( exit_code )
expect ( err ) . to eq ( expected_err )
expect ( out ) . to eq ( expected )
end
2018-11-02 19:07:56 -04:00
end
context " with exit 99 " do
let ( :exit_code ) { 99 }
2021-02-01 10:17:16 -05:00
it " runs " do
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
subject
expect ( exitstatus ) . to eq ( exit_code )
expect ( err ) . to eq ( expected_err )
expect ( out ) . to eq ( expected )
end
2018-11-02 19:07:56 -04:00
end
end
context " the executable exits by SignalException " do
let ( :executable ) do
ex = super ( )
ex << " \n "
ex << " raise SignalException, 'SIGTERM' \n "
ex
end
2019-04-14 02:01:35 -04:00
let ( :expected_err ) { " " }
2018-11-02 19:07:56 -04:00
let ( :exit_code ) do
2022-02-27 20:32:28 -05:00
exit_status_for_signal ( Signal . list [ " TERM " ] )
2018-11-02 19:07:56 -04:00
end
2021-02-01 10:17:16 -05:00
it " runs " do
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
subject
expect ( exitstatus ) . to eq ( exit_code )
expect ( err ) . to eq ( expected_err )
expect ( out ) . to eq ( expected )
end
2018-11-02 19:07:56 -04:00
end
2019-01-04 08:10:58 -05:00
context " the executable is empty " do
2018-11-02 19:07:56 -04:00
let ( :executable ) { " " }
let ( :exit_code ) { 0 }
let ( :expected_err ) { " #{ path } is empty " }
let ( :expected ) { " " }
2021-02-01 10:17:16 -05:00
it " runs " do
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
subject
expect ( exitstatus ) . to eq ( exit_code )
expect ( err ) . to eq ( expected_err )
expect ( out ) . to eq ( expected )
end
2018-11-02 19:07:56 -04:00
end
2019-01-04 08:10:58 -05:00
context " the executable raises " do
2018-11-02 19:07:56 -04:00
let ( :executable ) { super ( ) << " \n raise 'ERROR' " }
let ( :exit_code ) { 1 }
let ( :expected_err ) do
" bundler: failed to load command: #{ path } ( #{ path } ) " \
2020-12-08 02:36:29 -05:00
" \n #{ path } :10:in `<top (required)>': ERROR (RuntimeError) "
end
it " runs like a normally executed executable " do
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
subject
expect ( exitstatus ) . to eq ( exit_code )
expect ( err ) . to start_with ( expected_err )
expect ( out ) . to eq ( expected )
2018-11-02 19:07:56 -04:00
end
end
2019-01-04 08:10:58 -05:00
context " the executable raises an error without a backtrace " do
2018-11-02 19:07:56 -04:00
let ( :executable ) { super ( ) << " \n class Err < Exception \n def backtrace; end; \n end \n raise Err " }
let ( :exit_code ) { 1 }
2020-12-08 02:36:29 -05:00
let ( :expected_err ) { " bundler: failed to load command: #{ path } ( #{ path } ) \n #{ system_gem_path ( " bin/bundle " ) } : Err (Err) " }
2018-11-02 19:07:56 -04:00
let ( :expected ) { super ( ) }
2021-02-01 10:17:16 -05:00
it " runs " do
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
subject
expect ( exitstatus ) . to eq ( exit_code )
expect ( err ) . to eq ( expected_err )
expect ( out ) . to eq ( expected )
end
2018-11-02 19:07:56 -04:00
end
Fix some bundler specs (#2380)
* These seem to consistenly pass already
* Show actual command when running `make test-bundler`
Current the setup command that installs the necessary gems for testing
bundler was printed, but not the actual command that runs the tests.
That was a bit confusing.
* Borrow trick from setproctitle specs
* A title that long doesn't get set sometimes
No idea why, but the test doesn't need that the title is that long.
* Fix most gem helper spec ruby-core failures
* Fix the rest of the gem helper failures
* Fix version spec by improving the assertion
* Remove unnecessary `BUNDLE_RUBY` environment var
We can use `RUBY` when necessary, and `BUNDLE_RUBY` is not a good name
because bundler considers `BUNDLE_*` variables as settings.
* Rename `BUNDLE_GEM` to `GEM_COMMAND`
This is more descriptive I think, and also friendlier for bundler
because `BUNDLE_` env variables are interpreted by bundler as settings,
and this is not a bundler setting.
This fixes one bundler spec failure in config specs against ruby-core.
* Fix quality spec when run in core
Use the proper path helper.
* Fix dummy lib builder to never load default gems
If a dummy library is named as a default gem, when requiring the library
from its executable, the default gem would be loaded when running from
core, because in core all default gems share path with bundler, and thus
they are always in the $LOAD_PATH. We fix the issue by loading lib
relatively inside dummy lib executables.
* More exact assertions
Sometimes I have the problem that I do some "print debugging" inside
specs, and suddently the spec passes. This happens when the assertion is
too relaxed, and the things I print make it match, specially when they
are simple strings like "1.0" than can be easily be part of gem paths
that I print for debugging.
I fix this by making a more exact assertion.
* Detect the correct shebang when ENV["RUBY"] is set
* Relax assertion
So that the spec passes even if another paths containing "ext" are in
the load path. This works to fix a ruby-core issue, but it's a better
assertion in general. We just want to know that the extension path was
added.
* Use folder structure independent path helper
It should fix this spec for ruby-core.
* Fix the last failing spec on ruby-core
* Skip `bundle open <default_gem>` spec when no default gems
2019-08-19 20:46:31 -04:00
context " when the file uses the current ruby shebang " do
2018-11-02 19:07:56 -04:00
let ( :shebang ) { " # ! #{ Gem . ruby } " }
2021-02-01 10:17:16 -05:00
it " runs " do
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
subject
expect ( exitstatus ) . to eq ( exit_code )
expect ( err ) . to eq ( expected_err )
expect ( out ) . to eq ( expected )
end
2018-11-02 19:07:56 -04:00
end
2019-01-04 08:10:58 -05:00
context " when Bundler.setup fails " , :bundler = > " < 3 " do
2018-11-02 19:07:56 -04:00
before do
gemfile <<-G
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
gem 'rack' , '2'
G
ENV [ " BUNDLER_FORCE_TTY " ] = " true "
end
let ( :exit_code ) { Bundler :: GemNotFound . new . status_code }
2019-04-14 02:01:35 -04:00
let ( :expected ) { " " }
let ( :expected_err ) { <<-EOS.strip }
2021-07-31 08:10:59 -04:00
Could not find gem 'rack (= 2)' in locally installed gems .
2021-12-15 07:28:50 -05:00
The source contains the following gems matching 'rack' :
* rack - 0 . 9 . 1
* rack - 1 . 0 . 0
2021-07-26 09:21:18 -04:00
Run ` bundle install ` to install missing gems .
2018-11-02 19:07:56 -04:00
EOS
2021-02-01 10:17:16 -05:00
it " runs " do
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
subject
expect ( exitstatus ) . to eq ( exit_code )
expect ( err ) . to eq ( expected_err )
expect ( out ) . to eq ( expected )
end
2018-11-02 19:07:56 -04:00
end
2019-01-04 08:10:58 -05:00
context " when Bundler.setup fails " , :bundler = > " 3 " do
2018-11-02 19:07:56 -04:00
before do
gemfile <<-G
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
gem 'rack' , '2'
G
ENV [ " BUNDLER_FORCE_TTY " ] = " true "
end
let ( :exit_code ) { Bundler :: GemNotFound . new . status_code }
2019-04-14 02:01:35 -04:00
let ( :expected ) { " " }
let ( :expected_err ) { <<-EOS.strip }
2021-07-31 08:10:59 -04:00
Could not find gem 'rack (= 2)' in locally installed gems .
2021-12-15 07:28:50 -05:00
The source contains the following gems matching 'rack' :
* rack - 1 . 0 . 0
2021-07-26 09:21:18 -04:00
Run ` bundle install ` to install missing gems .
2018-11-02 19:07:56 -04:00
EOS
2021-02-01 10:17:16 -05:00
it " runs " do
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
subject
expect ( exitstatus ) . to eq ( exit_code )
expect ( err ) . to eq ( expected_err )
expect ( out ) . to eq ( expected )
end
2018-11-02 19:07:56 -04:00
end
context " when the executable exits non-zero via at_exit " do
let ( :executable ) { super ( ) + " \n \n at_exit { $! ? raise($!) : exit(1) } " }
let ( :exit_code ) { 1 }
2021-02-01 10:17:16 -05:00
it " runs " do
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
subject
expect ( exitstatus ) . to eq ( exit_code )
expect ( err ) . to eq ( expected_err )
expect ( out ) . to eq ( expected )
end
2018-11-02 19:07:56 -04:00
end
context " when disable_exec_load is set " do
let ( :exec ) { " EXEC: exec " }
let ( :process ) { " PROCESS: ruby #{ path } arg1 arg2 " }
before do
2019-04-14 02:01:35 -04:00
bundle " config set disable_exec_load true "
2018-11-02 19:07:56 -04:00
end
2021-02-01 10:17:16 -05:00
it " runs " do
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
subject
expect ( exitstatus ) . to eq ( exit_code )
expect ( err ) . to eq ( expected_err )
expect ( out ) . to eq ( expected )
end
2018-11-02 19:07:56 -04:00
end
context " regarding $0 and __FILE__ " do
let ( :executable ) { super ( ) + <<-'RUBY' }
puts " $0: #{ $0 . inspect } "
puts " __FILE__: #{ __FILE__ . inspect } "
RUBY
let ( :expected ) { super ( ) + <<-EOS.chomp }
$0 : #{path.to_s.inspect}
__FILE__ : #{path.to_s.inspect}
EOS
2021-02-01 10:17:16 -05:00
it " runs " do
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
subject
expect ( exitstatus ) . to eq ( exit_code )
expect ( err ) . to eq ( expected_err )
expect ( out ) . to eq ( expected )
end
2018-11-02 19:07:56 -04:00
context " when the path is relative " do
let ( :path ) { super ( ) . relative_path_from ( bundled_app ) }
2021-02-01 10:17:16 -05:00
it " runs " do
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
subject
expect ( exitstatus ) . to eq ( exit_code )
expect ( err ) . to eq ( expected_err )
expect ( out ) . to eq ( expected )
end
2018-11-02 19:07:56 -04:00
end
context " when the path is relative with a leading ./ " do
2020-05-08 01:19:04 -04:00
let ( :path ) { Pathname . new ( " ./ #{ super ( ) . relative_path_from ( bundled_app ) } " ) }
2018-11-02 19:07:56 -04:00
2019-04-14 02:01:35 -04:00
pending " relative paths with ./ have absolute __FILE__ "
2018-11-02 19:07:56 -04:00
end
end
context " signal handling " do
let ( :test_signals ) do
open3_reserved_signals = %w[ CHLD CLD PIPE ]
reserved_signals = %w[ SEGV BUS ILL FPE VTALRM KILL STOP EXIT ]
bundler_signals = %w[ INT ]
Signal . list . keys - ( bundler_signals + reserved_signals + open3_reserved_signals )
end
context " signals being trapped by bundler " do
let ( :executable ) { strip_whitespace <<-RUBY }
#{shebang}
begin
Thread . new do
puts 'Started' # For process sync
STDOUT . flush
sleep 1 # ignore quality_spec
raise " Didn't receive INT at all "
end . join
rescue Interrupt
puts " foo "
end
RUBY
2019-04-14 02:01:35 -04:00
it " receives the signal " do
2020-12-08 02:36:29 -05:00
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
2020-05-08 01:19:04 -04:00
2020-06-03 14:45:36 -04:00
bundle ( " exec #{ path } " ) do | _ , o , thr |
2018-11-02 19:07:56 -04:00
o . gets # Consumes 'Started' and ensures that thread has started
Process . kill ( " INT " , thr . pid )
end
expect ( out ) . to eq ( " foo " )
end
end
context " signals not being trapped by bunder " do
let ( :executable ) { strip_whitespace <<-RUBY }
#{shebang}
signals = #{test_signals.inspect}
result = signals . map do | sig |
Signal . trap ( sig , " IGNORE " )
end
puts result . select { | ret | ret == " IGNORE " } . count
RUBY
it " makes sure no unexpected signals are restored to DEFAULT " do
2020-12-08 02:36:29 -05:00
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
2020-05-08 01:19:04 -04:00
2018-11-02 19:07:56 -04:00
test_signals . each do | n |
Signal . trap ( n , " IGNORE " )
end
2020-06-03 14:45:36 -04:00
bundle ( " exec #{ path } " )
2018-11-02 19:07:56 -04:00
expect ( out ) . to eq ( test_signals . count . to_s )
end
end
end
end
context " nested bundle exec " do
2019-05-24 11:46:26 -04:00
context " when bundle in a local path " do
2018-11-02 19:07:56 -04:00
before do
2020-12-08 02:36:29 -05:00
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
2018-11-02 19:07:56 -04:00
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
2019-08-16 11:51:18 -04:00
bundle " config set path vendor/bundler "
2020-06-03 14:45:36 -04:00
bundle :install
2018-11-02 19:07:56 -04:00
end
2020-06-11 15:05:17 -04:00
it " correctly shells out " do
2018-11-02 19:07:56 -04:00
file = bundled_app ( " file_that_bundle_execs.rb " )
2020-05-08 01:19:04 -04:00
create_file ( file , <<-RUBY)
2018-11-02 19:07:56 -04:00
#!#{Gem.ruby}
2019-07-26 07:37:51 -04:00
puts ` bundle exec echo foo `
2020-05-08 01:19:04 -04:00
RUBY
2018-11-02 19:07:56 -04:00
file . chmod ( 0 o777 )
2020-06-03 14:45:36 -04:00
bundle " exec #{ file } " , :env = > { " PATH " = > path }
2018-11-02 19:07:56 -04:00
expect ( out ) . to eq ( " foo " )
end
end
2020-12-08 02:36:29 -05:00
context " when Kernel.require uses extra monkeypatches " do
before do
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
2021-07-24 11:27:02 -04:00
install_gemfile " source \" #{ file_uri_for ( gem_repo1 ) } \" "
2020-12-08 02:36:29 -05:00
end
it " does not undo the monkeypatches " do
karafka = bundled_app ( " bin/karafka " )
create_file ( karafka , << ~ RUBY )
#!#{Gem.ruby}
module Kernel
module_function
alias_method :require_before_extra_monkeypatches , :require
def require ( path )
puts " requiring \# {path} used the monkeypatch "
require_before_extra_monkeypatches ( path )
end
end
Bundler . setup ( :default )
require " foo "
RUBY
karafka . chmod ( 0 o777 )
foreman = bundled_app ( " bin/foreman " )
create_file ( foreman , << ~ RUBY )
#!#{Gem.ruby}
puts ` bundle exec bin/karafka `
RUBY
foreman . chmod ( 0 o777 )
bundle " exec #{ foreman } "
expect ( out ) . to eq ( " requiring foo used the monkeypatch " )
end
end
2020-12-14 18:32:54 -05:00
context " when gemfile and path are configured " , :ruby_repo do
before do
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
build_repo2 do
build_gem " rails " , " 6.1.0 " do | s |
s . executables = " rails "
end
end
bundle " config set path vendor/bundle "
bundle " config set gemfile gemfiles/rack_6_1.gemfile "
create_file ( bundled_app ( " gemfiles/rack_6_1.gemfile " ) , << ~ RUBY )
source " #{ file_uri_for ( gem_repo2 ) } "
gem " rails " , " 6.1.0 "
RUBY
# A Gemfile needs to be in the root to trick bundler's root resolution
2021-07-24 11:27:02 -04:00
create_file ( bundled_app ( " Gemfile " ) , " source \" #{ file_uri_for ( gem_repo1 ) } \" " )
2020-12-14 18:32:54 -05:00
bundle " install "
end
it " can still find gems after a nested subprocess " do
script = bundled_app ( " bin/myscript " )
create_file ( script , << ~ RUBY )
#!#{Gem.ruby}
puts ` bundle exec rails `
RUBY
script . chmod ( 0 o777 )
bundle " exec #{ script } "
expect ( err ) . to be_empty
expect ( out ) . to eq ( " 6.1.0 " )
end
end
2018-11-02 19:07:56 -04:00
context " with a system gem that shadows a default gem " do
let ( :openssl_version ) { " 99.9.9 " }
2020-06-03 12:43:17 -04:00
let ( :expected ) { ruby " gem 'openssl', '< 999999'; require 'openssl'; puts OpenSSL::VERSION " , :artifice = > nil , :raise_on_error = > false }
2018-11-02 19:07:56 -04:00
it " only leaves the default gem in the stdlib available " do
2020-12-08 02:36:29 -05:00
skip " https://github.com/rubygems/rubygems/issues/3351 " if Gem . win_platform?
2018-11-02 19:07:56 -04:00
skip " openssl isn't a default gem " if expected . empty?
2021-07-24 11:27:02 -04:00
install_gemfile " source \" #{ file_uri_for ( gem_repo1 ) } \" " # must happen before installing the broken system gem
2018-11-02 19:07:56 -04:00
build_repo4 do
build_gem " openssl " , openssl_version do | s |
2020-05-08 01:19:04 -04:00
s . write ( " lib/openssl.rb " , <<-RUBY)
2018-11-02 19:07:56 -04:00
raise " custom openssl should not be loaded, it's not in the gemfile! "
2020-05-08 01:19:04 -04:00
RUBY
2018-11-02 19:07:56 -04:00
end
end
2020-05-15 08:31:12 -04:00
system_gems ( " openssl- #{ openssl_version } " , :gem_repo = > gem_repo4 )
2018-11-02 19:07:56 -04:00
file = bundled_app ( " require_openssl.rb " )
2020-05-08 01:19:04 -04:00
create_file ( file , <<-RUBY)
2018-11-02 19:07:56 -04:00
#!/usr/bin/env ruby
require " openssl "
puts OpenSSL :: VERSION
warn Gem . loaded_specs . values . map ( & :full_name )
2020-05-08 01:19:04 -04:00
RUBY
2018-11-02 19:07:56 -04:00
file . chmod ( 0 o777 )
2020-05-15 08:31:12 -04:00
env = { " PATH " = > path }
2018-11-02 19:07:56 -04:00
aggregate_failures do
2020-06-03 14:45:36 -04:00
expect ( bundle ( " exec #{ file } " , :artifice = > nil , :env = > env ) ) . to eq ( expected )
expect ( bundle ( " exec bundle exec #{ file } " , :artifice = > nil , :env = > env ) ) . to eq ( expected )
expect ( bundle ( " exec ruby #{ file } " , :artifice = > nil , :env = > env ) ) . to eq ( expected )
2020-06-03 14:48:46 -04:00
expect ( run ( file . read , :artifice = > nil , :env = > env ) ) . to eq ( expected )
2018-11-02 19:07:56 -04:00
end
2020-05-15 08:31:12 -04:00
skip " ruby_core has openssl and rubygems in the same folder, and this test needs rubygems require but default openssl not in a directly added entry in $LOAD_PATH " if ruby_core?
2018-11-02 19:07:56 -04:00
# sanity check that we get the newer, custom version without bundler
2020-06-03 12:43:17 -04:00
sys_exec " #{ Gem . ruby } #{ file } " , :env = > env , :raise_on_error = > false
2019-06-01 05:49:40 -04:00
expect ( err ) . to include ( " custom openssl should not be loaded " )
2018-11-02 19:07:56 -04:00
end
end
2020-05-21 08:05:07 -04:00
2020-05-21 08:57:47 -04:00
context " with a git gem that includes extensions " , :ruby_repo do
2020-05-21 08:05:07 -04:00
before do
build_git " simple_git_binary " , & :add_c_extension
2020-06-03 14:45:36 -04:00
bundle " config set --local path .bundle "
2020-06-03 14:46:03 -04:00
install_gemfile <<-G
2021-07-24 11:27:02 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2020-05-21 08:05:07 -04:00
gem " simple_git_binary " , :git = > '#{lib_path("simple_git_binary-1.0")}'
G
end
it " allows calling bundle install " do
2020-06-03 14:45:36 -04:00
bundle " exec bundle install "
2020-05-21 08:05:07 -04:00
end
it " allows calling bundle install after removing gem.build_complete " do
FileUtils . rm_rf Dir [ bundled_app ( " .bundle/**/gem.build_complete " ) ]
2020-06-03 14:45:36 -04:00
bundle " exec #{ Gem . ruby } -S bundle install "
2020-05-21 08:05:07 -04:00
end
end
2018-11-02 19:07:56 -04:00
end
end