2018-11-02 19:07:56 -04:00
# frozen_string_literal: true
2020-06-06 12:27:42 -04:00
RSpec . describe " install in deployment or frozen mode " 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 " rack "
G
end
2019-01-04 08:10:58 -05:00
context " with CLI flags " , :bundler = > " < 3 " do
2018-11-02 19:07:56 -04:00
it " fails without a lockfile and says that --deployment requires a lock " do
2020-06-03 12:43:17 -04:00
bundle " install --deployment " , :raise_on_error = > false
2019-04-14 02:01:35 -04:00
expect ( err ) . to include ( " The --deployment flag requires a Gemfile.lock " )
2018-11-02 19:07:56 -04:00
end
it " fails without a lockfile and says that --frozen requires a lock " do
2020-06-03 12:43:17 -04:00
bundle " install --frozen " , :raise_on_error = > false
2019-04-14 02:01:35 -04:00
expect ( err ) . to include ( " The --frozen flag requires a Gemfile.lock " )
2018-11-02 19:07:56 -04:00
end
it " disallows --deployment --system " do
2020-06-03 12:43:17 -04:00
bundle " install --deployment --system " , :raise_on_error = > false
2019-04-14 02:01:35 -04:00
expect ( err ) . to include ( " You have specified both --deployment " )
expect ( err ) . to include ( " Please choose only one option " )
2018-11-02 19:07:56 -04:00
expect ( exitstatus ) . to eq ( 15 ) if exitstatus
end
it " disallows --deployment --path --system " do
2020-06-03 12:43:17 -04:00
bundle " install --deployment --path . --system " , :raise_on_error = > false
2019-04-14 02:01:35 -04:00
expect ( err ) . to include ( " You have specified both --path " )
expect ( err ) . to include ( " as well as --system " )
expect ( err ) . to include ( " Please choose only one option " )
2018-11-02 19:07:56 -04:00
expect ( exitstatus ) . to eq ( 15 ) if exitstatus
end
2020-01-08 02:11:52 -05:00
it " doesn't mess up a subsequent `bundle install` after you try to deploy without a lock " do
2020-06-03 12:43:17 -04:00
bundle " install --deployment " , :raise_on_error = > false
2020-06-03 14:45:36 -04:00
bundle :install
2018-11-02 19:07:56 -04:00
expect ( the_bundle ) . to include_gems " rack 1.0 "
end
end
it " still works if you are not in the app directory and specify --gemfile " do
2020-06-03 14:45:36 -04:00
bundle " install "
2020-05-08 01:19:04 -04:00
simulate_new_machine
2020-05-29 06:46:16 -04:00
bundle " config --local deployment true "
bundle " config --local path vendor/bundle "
2020-06-03 14:45:36 -04:00
bundle " install --gemfile #{ tmp } /bundled_app/Gemfile " , :dir = > tmp
2018-11-02 19:07:56 -04:00
expect ( the_bundle ) . to include_gems " rack 1.0 "
end
it " works if you exclude a group with a git gem " do
build_git " foo "
gemfile <<-G
group :test do
gem " foo " , :git = > " #{ lib_path ( " foo-1.0 " ) } "
end
G
2020-06-03 14:45:36 -04:00
bundle :install
2020-05-29 06:46:16 -04:00
bundle " config --local deployment true "
bundle " config --local without test "
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 " works when you bundle exec bundle " do
2020-05-08 01:19:04 -04:00
skip " doesn't find bundle " if Gem . win_platform?
2020-06-03 14:45:36 -04:00
bundle :install
2020-06-06 12:27:42 -04:00
bundle " config --local deployment true "
bundle :install
2020-06-03 14:45:36 -04:00
bundle " exec bundle check " , :env = > { " PATH " = > path }
2018-11-02 19:07:56 -04:00
end
it " works when using path gems from the same path and the version is specified " do
build_lib " foo " , :path = > lib_path ( " nested/foo " )
build_lib " bar " , :path = > lib_path ( " nested/bar " )
gemfile <<-G
gem " foo " , " 1.0 " , :path = > " #{ lib_path ( " nested " ) } "
gem " bar " , :path = > " #{ lib_path ( " nested " ) } "
G
2020-06-03 14:45:36 -04:00
bundle :install
2020-05-29 06:46:16 -04:00
bundle " config --local deployment true "
2020-06-03 14:45:36 -04:00
bundle :install
2018-11-02 19:07:56 -04:00
end
it " works when there are credentials in the source URL " do
install_gemfile ( <<-G, :artifice => "endpoint_strict_basic_authentication", :quiet => true)
source " http://user:pass@localgemserver.test/ "
gem " rack-obama " , " >= 1.0 "
G
2020-05-29 06:46:16 -04:00
bundle " config --local deployment true "
2020-06-03 14:45:36 -04:00
bundle :install , :artifice = > " endpoint_strict_basic_authentication "
2018-11-02 19:07:56 -04:00
end
it " works with sources given by a block " 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 ) } " do
2018-11-02 19:07:56 -04:00
gem " rack "
end
G
2020-05-29 06:46:16 -04:00
bundle " config --local deployment true "
2020-06-03 14:45:36 -04:00
bundle :install
2018-11-02 19:07:56 -04:00
expect ( the_bundle ) . to include_gems " rack 1.0 "
end
2020-01-08 02:11:52 -05:00
context " when replacing a host with the same host with credentials " do
before do
2020-05-29 06:46:16 -04:00
bundle " config --local path vendor/bundle "
2020-06-03 14:45:36 -04:00
bundle " install "
2020-01-08 02:11:52 -05:00
gemfile <<-G
source " http://user_name:password@localgemserver.test/ "
gem " rack "
G
lockfile <<-G
GEM
remote : http : / / localgemserver . test /
specs :
rack ( 1 . 0 . 0 )
PLATFORMS
#{local}
DEPENDENCIES
rack
G
2020-06-03 14:45:36 -04:00
bundle " config set --local deployment true "
2020-01-08 02:11:52 -05:00
end
it " prevents the replace by default " do
2020-06-03 12:43:17 -04:00
bundle :install , :raise_on_error = > false
2020-01-08 02:11:52 -05:00
expect ( err ) . to match ( / The list of sources changed / )
end
context " when allow_deployment_source_credential_changes is true " do
2020-06-03 14:45:36 -04:00
before { bundle " config set allow_deployment_source_credential_changes true " }
2020-01-08 02:11:52 -05:00
it " allows the replace " do
2020-06-03 14:45:36 -04:00
bundle :install
2020-01-08 02:11:52 -05:00
expect ( out ) . to match ( / Bundle complete! / )
end
end
context " when allow_deployment_source_credential_changes is false " do
2020-06-03 14:45:36 -04:00
before { bundle " config set allow_deployment_source_credential_changes false " }
2020-01-08 02:11:52 -05:00
it " prevents the replace " do
2020-06-03 12:43:17 -04:00
bundle :install , :raise_on_error = > false
2020-01-08 02:11:52 -05:00
expect ( err ) . to match ( / The list of sources changed / )
end
end
context " when BUNDLE_ALLOW_DEPLOYMENT_SOURCE_CREDENTIAL_CHANGES env var is true " do
before { ENV [ " BUNDLE_ALLOW_DEPLOYMENT_SOURCE_CREDENTIAL_CHANGES " ] = " true " }
it " allows the replace " do
bundle :install
expect ( out ) . to match ( / Bundle complete! / )
end
end
context " when BUNDLE_ALLOW_DEPLOYMENT_SOURCE_CREDENTIAL_CHANGES env var is false " do
before { ENV [ " BUNDLE_ALLOW_DEPLOYMENT_SOURCE_CREDENTIAL_CHANGES " ] = " false " }
it " prevents the replace " do
2020-06-03 12:43:17 -04:00
bundle :install , :raise_on_error = > false
2020-01-08 02:11:52 -05:00
expect ( err ) . to match ( / The list of sources changed / )
end
end
end
2018-11-02 19:07:56 -04:00
describe " with an existing lockfile " do
before do
2020-06-03 14:45:36 -04:00
bundle " install "
2020-01-08 02:11:52 -05:00
end
it " installs gems by default to vendor/bundle " , :bundler = > " < 3 " do
2020-06-03 14:45:36 -04:00
bundle " install --deployment "
2020-01-08 02:11:52 -05:00
expect ( out ) . to include ( " vendor/bundle " )
end
it " installs gems to custom path if specified " , :bundler = > " < 3 " do
2020-06-03 14:45:36 -04:00
bundle " install --path vendor/bundle2 --deployment "
2020-01-08 02:11:52 -05:00
expect ( out ) . to include ( " vendor/bundle2 " )
2018-11-02 19:07:56 -04:00
end
2019-01-04 08:10:58 -05:00
it " works with the --deployment flag if you didn't change anything " , :bundler = > " < 3 " do
2020-06-03 14:45:36 -04:00
bundle " install --deployment "
2018-11-02 19:07:56 -04:00
end
2019-01-04 08:10:58 -05:00
it " works with the --frozen flag if you didn't change anything " , :bundler = > " < 3 " do
2020-06-03 14:45:36 -04:00
bundle " install --frozen "
2018-11-02 19:07:56 -04:00
end
it " works with BUNDLE_FROZEN if you didn't change anything " do
2020-06-03 14:45:36 -04:00
bundle :install , :env = > { " BUNDLE_FROZEN " = > " true " }
2018-11-02 19:07:56 -04:00
end
it " explodes with the --deployment flag if you make a change and don't check in the lockfile " 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 "
gem " rack-obama "
G
2020-05-29 06:46:16 -04:00
bundle " config --local deployment true "
2020-06-03 12:43:17 -04:00
bundle :install , :raise_on_error = > false
2019-04-14 02:01:35 -04:00
expect ( err ) . to include ( " deployment mode " )
expect ( err ) . to include ( " You have added to the Gemfile " )
expect ( err ) . to include ( " * rack-obama " )
expect ( err ) . not_to include ( " You have deleted from the Gemfile " )
expect ( err ) . not_to include ( " You have changed in the Gemfile " )
2018-11-02 19:07:56 -04:00
end
it " works if a path gem is missing but is in a without group " do
build_lib " path_gem "
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 " rake "
gem " path_gem " , :path = > " #{ lib_path ( " path_gem-1.0 " ) } " , :group = > :development
G
expect ( the_bundle ) . to include_gems " path_gem 1.0 "
FileUtils . rm_r lib_path ( " path_gem-1.0 " )
2020-05-29 06:46:16 -04:00
bundle " config --local path .bundle "
bundle " config --local without development "
bundle " config --local deployment true "
2020-06-03 14:45:36 -04:00
bundle :install , :env = > { " DEBUG " = > " 1 " }
2020-06-03 14:48:46 -04:00
run " puts :WIN "
2018-11-02 19:07:56 -04:00
expect ( out ) . to eq ( " WIN " )
end
it " explodes if a path gem is missing " do
build_lib " path_gem "
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 " rake "
gem " path_gem " , :path = > " #{ lib_path ( " path_gem-1.0 " ) } " , :group = > :development
G
expect ( the_bundle ) . to include_gems " path_gem 1.0 "
FileUtils . rm_r lib_path ( " path_gem-1.0 " )
2020-05-29 06:46:16 -04:00
bundle " config --local path .bundle "
bundle " config --local deployment true "
2020-06-03 12:43:17 -04:00
bundle :install , :raise_on_error = > false
2019-04-14 02:01:35 -04:00
expect ( err ) . to include ( " The path ` #{ lib_path ( " path_gem-1.0 " ) } ` does not exist. " )
2018-11-02 19:07:56 -04:00
end
2019-01-04 08:10:58 -05:00
it " can have --frozen set via an environment variable " , :bundler = > " < 3 " do
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 "
gem " rack-obama "
G
ENV [ " BUNDLE_FROZEN " ] = " 1 "
2020-06-03 12:43:17 -04:00
bundle " install " , :raise_on_error = > false
2019-04-14 02:01:35 -04:00
expect ( err ) . to include ( " deployment mode " )
expect ( err ) . to include ( " You have added to the Gemfile " )
expect ( err ) . to include ( " * rack-obama " )
expect ( err ) . not_to include ( " You have deleted from the Gemfile " )
expect ( err ) . not_to include ( " You have changed in the Gemfile " )
2018-11-02 19:07:56 -04:00
end
it " can have --deployment set via an environment variable " 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 "
gem " rack-obama "
G
ENV [ " BUNDLE_DEPLOYMENT " ] = " true "
2020-06-03 12:43:17 -04:00
bundle " install " , :raise_on_error = > false
2019-04-14 02:01:35 -04:00
expect ( err ) . to include ( " deployment mode " )
expect ( err ) . to include ( " You have added to the Gemfile " )
expect ( err ) . to include ( " * rack-obama " )
expect ( err ) . not_to include ( " You have deleted from the Gemfile " )
expect ( err ) . not_to include ( " You have changed in the Gemfile " )
2018-11-02 19:07:56 -04:00
end
2020-05-29 06:27:15 -04:00
it " installs gems by default to vendor/bundle when deployment mode is set via an environment variable " , :bundler = > " < 3 " do
2020-01-08 02:11:52 -05:00
ENV [ " BUNDLE_DEPLOYMENT " ] = " true "
bundle " install "
expect ( out ) . to include ( " vendor/bundle " )
end
it " installs gems to custom path when deployment mode is set via an environment variable " , :bundler = > " < 3 " do
ENV [ " BUNDLE_DEPLOYMENT " ] = " true "
ENV [ " BUNDLE_PATH " ] = " vendor/bundle2 "
bundle " install "
expect ( out ) . to include ( " vendor/bundle2 " )
end
2018-11-02 19:07:56 -04:00
it " can have --frozen set to false via an environment variable " 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 "
gem " rack-obama "
G
ENV [ " BUNDLE_FROZEN " ] = " false "
ENV [ " BUNDLE_DEPLOYMENT " ] = " false "
bundle " install "
expect ( out ) . not_to include ( " deployment mode " )
expect ( out ) . not_to include ( " You have added to the Gemfile " )
expect ( out ) . not_to include ( " * rack-obama " )
end
it " explodes if you remove a gem and don't check in the lockfile " 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 " activesupport "
G
2020-05-29 06:46:16 -04:00
bundle " config --local deployment true "
2020-06-03 12:43:17 -04:00
bundle :install , :raise_on_error = > false
2019-04-14 02:01:35 -04:00
expect ( err ) . to include ( " deployment mode " )
expect ( err ) . to include ( " You have added to the Gemfile: \n * activesupport \n \n " )
expect ( err ) . to include ( " You have deleted from the Gemfile: \n * rack " )
expect ( err ) . not_to include ( " You have changed in the Gemfile " )
2018-11-02 19:07:56 -04:00
end
it " explodes if you add a source " 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 " , :git = > " git://hubz.com "
G
2020-05-29 06:46:16 -04:00
bundle " config --local deployment true "
2020-06-03 12:43:17 -04:00
bundle :install , :raise_on_error = > false
2019-04-14 02:01:35 -04:00
expect ( err ) . to include ( " deployment mode " )
expect ( err ) . to include ( " You have added to the Gemfile: \n * source: git://hubz.com (at master) " )
expect ( err ) . not_to include ( " You have changed in the Gemfile " )
2018-11-02 19:07:56 -04:00
end
it " explodes if you unpin a source " do
build_git " rack "
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 " , :git = > " #{ lib_path ( " rack-1.0 " ) } "
G
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-29 06:46:16 -04:00
bundle " config --local deployment true "
2020-06-03 12:43:17 -04:00
bundle :install , :raise_on_error = > false
2019-04-14 02:01:35 -04:00
expect ( err ) . to include ( " deployment mode " )
expect ( err ) . to include ( " You have deleted from the Gemfile: \n * source: #{ lib_path ( " rack-1.0 " ) } (at master@ #{ revision_for ( lib_path ( " rack-1.0 " ) ) [ 0 .. 6 ] } " )
expect ( err ) . not_to include ( " You have added to the Gemfile " )
expect ( err ) . not_to include ( " You have changed in the Gemfile " )
2018-11-02 19:07:56 -04:00
end
it " explodes if you unpin a source, leaving it pinned somewhere else " do
build_lib " foo " , :path = > lib_path ( " rack/foo " )
build_git " rack " , :path = > lib_path ( " rack " )
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 " , :git = > " #{ lib_path ( " rack " ) } "
gem " foo " , :git = > " #{ lib_path ( " rack " ) } "
G
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 " foo " , :git = > " #{ lib_path ( " rack " ) } "
G
2020-05-29 06:46:16 -04:00
bundle " config --local deployment true "
2020-06-03 12:43:17 -04:00
bundle :install , :raise_on_error = > false
2019-04-14 02:01:35 -04:00
expect ( err ) . to include ( " deployment mode " )
expect ( err ) . to include ( " You have changed in the Gemfile: \n * rack from `no specified source` to ` #{ lib_path ( " rack " ) } (at master@ #{ revision_for ( lib_path ( " rack " ) ) [ 0 .. 6 ] } )` " )
expect ( err ) . not_to include ( " You have added to the Gemfile " )
expect ( err ) . not_to include ( " You have deleted from the Gemfile " )
2018-11-02 19:07:56 -04:00
end
it " remembers that the bundle is frozen at runtime " do
2020-06-03 14:45:36 -04:00
bundle :lock
2018-11-02 19:07:56 -04:00
2020-06-03 14:45:36 -04:00
bundle " config set --local deployment true "
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 " , " 1.0.0 "
gem " rack-obama "
G
expect ( the_bundle ) . not_to include_gems " rack 1.0.0 "
2019-06-01 05:49:40 -04:00
expect ( err ) . to include strip_whitespace ( <<-E).strip
2018-11-02 19:07:56 -04:00
The dependencies in your gemfile changed
You have added to the Gemfile :
* rack ( = 1 . 0 . 0 )
* rack - obama
You have deleted from the Gemfile :
* rack
E
end
end
context " with path in Gemfile and packed " do
it " works fine after bundle package and bundle install --local " do
build_lib " foo " , :path = > lib_path ( " foo " )
2020-06-03 14:46:03 -04:00
install_gemfile <<-G
2018-11-02 19:07:56 -04:00
gem " foo " , :path = > " #{ lib_path ( " foo " ) } "
G
2020-06-03 14:45:36 -04:00
bundle :install
2018-11-02 19:07:56 -04:00
expect ( the_bundle ) . to include_gems " foo 1.0 "
2019-07-23 11:32:33 -04:00
bundle " config set cache_all true "
2020-06-03 14:45:36 -04:00
bundle :cache
2018-11-02 19:07:56 -04:00
expect ( bundled_app ( " vendor/cache/foo " ) ) . to be_directory
2020-06-03 14:45:36 -04:00
bundle " install --local "
2018-11-02 19:07:56 -04:00
expect ( out ) . to include ( " Updating files in vendor/cache " )
simulate_new_machine
2020-06-03 14:45:36 -04:00
bundle " config set --local deployment true "
bundle " install --verbose "
2018-11-02 19:07:56 -04:00
expect ( out ) . not_to include ( " You are trying to install in deployment mode after changing your Gemfile " )
expect ( out ) . not_to include ( " You have added to the Gemfile " )
expect ( out ) . not_to include ( " You have deleted from the Gemfile " )
expect ( out ) . to include ( " vendor/cache/foo " )
expect ( the_bundle ) . to include_gems " foo 1.0 "
end
end
end