2018-11-02 19:07:56 -04:00
# frozen_string_literal: true
RSpec . describe " bundle check " do
it " returns success when the Gemfile is satisfied " do
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 " rails "
G
bundle :check
expect ( out ) . to include ( " The Gemfile's dependencies are satisfied " )
end
it " works with the --gemfile flag when not in the directory " do
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 " rails "
G
2020-05-08 01:19:04 -04:00
bundle " check --gemfile bundled_app/Gemfile " , :dir = > tmp
2018-11-02 19:07:56 -04:00
expect ( out ) . to include ( " The Gemfile's dependencies are satisfied " )
end
it " creates a Gemfile.lock by default if one does not exist " do
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 " rails "
G
2020-05-08 01:19:04 -04:00
FileUtils . rm ( bundled_app_lock )
2018-11-02 19:07:56 -04:00
bundle " check "
2020-05-08 01:19:04 -04:00
expect ( bundled_app_lock ) . to exist
2018-11-02 19:07:56 -04:00
end
it " does not create a Gemfile.lock if --dry-run was passed " do
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 " rails "
G
2020-05-08 01:19:04 -04:00
FileUtils . rm ( bundled_app_lock )
2018-11-02 19:07:56 -04:00
bundle " check --dry-run "
2020-05-08 01:19:04 -04:00
expect ( bundled_app_lock ) . not_to exist
2018-11-02 19:07:56 -04:00
end
it " prints a generic error if the missing gems are unresolvable " do
system_gems [ " rails-2.3.2 " ]
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
2020-06-03 12:43:17 -04:00
bundle :check , :raise_on_error = > false
2019-04-14 02:01:35 -04:00
expect ( err ) . to include ( " Bundler can't satisfy your Gemfile's dependencies. " )
2018-11-02 19:07:56 -04:00
end
it " prints a generic error if a Gemfile.lock does not exist and a toplevel dependency does not exist " 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
2020-06-03 12:43:17 -04:00
bundle :check , :raise_on_error = > false
2020-06-24 13:53:16 -04:00
expect ( exitstatus ) . to be > 0
2019-04-14 02:01:35 -04:00
expect ( err ) . to include ( " Bundler can't satisfy your Gemfile's dependencies. " )
2018-11-02 19:07:56 -04:00
end
it " prints a generic message if you changed your lockfile " do
2020-12-08 02:36:29 -05:00
build_repo2 do
build_gem " rails_pinned_to_old_activesupport " do | s |
s . add_dependency " activesupport " , " = 1.2.3 "
end
end
2018-11-02 19:07:56 -04:00
install_gemfile <<-G
2020-12-08 02:36:29 -05:00
source " #{ file_uri_for ( gem_repo2 ) } "
2018-11-02 19:07:56 -04:00
gem 'rails'
G
gemfile <<-G
2020-12-08 02:36:29 -05:00
source " #{ file_uri_for ( gem_repo2 ) } "
2018-11-02 19:07:56 -04:00
gem " rails "
2020-06-07 07:23:10 -04:00
gem " rails_pinned_to_old_activesupport "
2018-11-02 19:07:56 -04:00
G
2020-06-03 12:43:17 -04:00
bundle :check , :raise_on_error = > false
2019-04-14 02:01:35 -04:00
expect ( err ) . to include ( " Bundler can't satisfy your Gemfile's dependencies. " )
2018-11-02 19:07:56 -04:00
end
2019-01-04 08:10:58 -05:00
it " remembers --without option from install " , :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
group :foo do
gem " rack "
end
G
2020-06-03 14:45:36 -04:00
bundle " install --without foo "
bundle " check "
2018-11-02 19:07:56 -04:00
expect ( out ) . to include ( " The Gemfile's dependencies are satisfied " )
end
it " uses the without setting " do
2020-06-03 14:45:36 -04:00
bundle " config set without foo "
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
group :foo do
gem " rack "
end
G
2020-06-03 14:45:36 -04:00
bundle " check "
2018-11-02 19:07:56 -04:00
expect ( out ) . to include ( " The Gemfile's dependencies are satisfied " )
end
it " ensures that gems are actually installed and not just cached " 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 " , :group = > :foo
G
2021-01-03 20:11:34 -05:00
bundle " config set --local without foo "
2020-05-29 06:46:16 -04:00
bundle :install
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
2020-06-03 12:43:17 -04:00
bundle " check " , :raise_on_error = > false
2019-04-14 02:01:35 -04:00
expect ( err ) . to include ( " * rack (1.0.0) " )
2020-06-24 13:53:16 -04:00
expect ( exitstatus ) . to eq ( 1 )
2018-11-02 19:07:56 -04:00
end
it " ignores missing gems restricted to other platforms " 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 "
platforms : #{not_local_tag} do
gem " activesupport "
end
G
2020-05-08 01:19:04 -04:00
system_gems " rack-1.0.0 " , :path = > default_bundle_path
2018-11-02 19:07:56 -04:00
lockfile <<-G
GEM
2019-05-06 12:06:21 -04:00
remote : #{file_uri_for(gem_repo1)}/
2018-11-02 19:07:56 -04:00
specs :
activesupport ( 2 . 3 . 5 )
rack ( 1 . 0 . 0 )
PLATFORMS
#{local}
#{not_local}
DEPENDENCIES
rack
activesupport
G
bundle :check
expect ( out ) . to include ( " The Gemfile's dependencies are satisfied " )
end
it " works with env conditionals " 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 "
env :NOT_GOING_TO_BE_SET do
gem " activesupport "
end
G
2020-05-08 01:19:04 -04:00
system_gems " rack-1.0.0 " , :path = > default_bundle_path
2018-11-02 19:07:56 -04:00
lockfile <<-G
GEM
2019-05-06 12:06:21 -04:00
remote : #{file_uri_for(gem_repo1)}/
2018-11-02 19:07:56 -04:00
specs :
activesupport ( 2 . 3 . 5 )
rack ( 1 . 0 . 0 )
PLATFORMS
#{local}
#{not_local}
DEPENDENCIES
rack
activesupport
G
bundle :check
expect ( out ) . to include ( " The Gemfile's dependencies are satisfied " )
end
it " outputs an error when the default Gemfile is not found " do
2020-06-03 12:43:17 -04:00
bundle :check , :raise_on_error = > false
2020-06-24 13:53:16 -04:00
expect ( exitstatus ) . to eq ( 10 )
2019-04-14 02:01:35 -04:00
expect ( err ) . to include ( " Could not locate Gemfile " )
2018-11-02 19:07:56 -04:00
end
it " does not output fatal error message " do
2020-06-03 12:43:17 -04:00
bundle :check , :raise_on_error = > false
2020-06-24 13:53:16 -04:00
expect ( exitstatus ) . to eq ( 10 )
2019-04-14 02:01:35 -04:00
expect ( err ) . not_to include ( " Unfortunately, a fatal error has occurred. " )
2018-11-02 19:07:56 -04:00
end
it " fails when there's no lock file and frozen is set " do
2020-06-03 14:46:03 -04:00
install_gemfile <<-G
2019-05-06 12:06:21 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
gem " foo "
G
2021-01-03 20:11:34 -05:00
bundle " config set --local deployment true "
2020-06-03 14:45:36 -04:00
bundle " install "
2020-05-08 01:19:04 -04:00
FileUtils . rm ( bundled_app_lock )
2018-11-02 19:07:56 -04:00
2020-06-03 12:43:17 -04:00
bundle :check , :raise_on_error = > false
2018-11-02 19:07:56 -04:00
expect ( last_command ) . to be_failure
end
2019-01-04 08:10:58 -05:00
context " --path " , :bundler = > " < 3 " do
2019-08-16 08:30:39 -04:00
context " after installing gems in the proper directory " do
before do
gemfile <<-G
source " #{ file_uri_for ( gem_repo1 ) } "
gem " rails "
G
bundle " install --path vendor/bundle "
FileUtils . rm_rf ( bundled_app ( " .bundle " ) )
end
2018-11-02 19:07:56 -04:00
2019-08-16 08:30:39 -04:00
it " returns success " do
2020-06-03 14:45:36 -04:00
bundle " check --path vendor/bundle "
2019-08-16 08:30:39 -04:00
expect ( out ) . to include ( " The Gemfile's dependencies are satisfied " )
end
2018-11-02 19:07:56 -04:00
2019-08-16 08:30:39 -04:00
it " should write to .bundle/config " do
bundle " check --path vendor/bundle "
2020-06-03 14:45:36 -04:00
bundle " check "
2019-08-16 08:30:39 -04:00
end
2018-11-02 19:07:56 -04:00
end
2019-08-16 08:30:39 -04:00
context " after installing gems on a different directory " do
before do
install_gemfile <<-G
source " #{ file_uri_for ( gem_repo1 ) } "
gem " rails "
G
2018-11-02 19:07:56 -04:00
2020-06-03 12:43:17 -04:00
bundle " check --path vendor/bundle " , :raise_on_error = > false
2019-08-16 08:30:39 -04:00
end
2018-11-02 19:07:56 -04:00
2019-08-16 08:30:39 -04:00
it " returns false " do
2020-06-24 13:53:16 -04:00
expect ( exitstatus ) . to eq ( 1 )
2019-08-16 08:30:39 -04:00
expect ( err ) . to match ( / The following gems are missing / )
end
2018-11-02 19:07:56 -04:00
end
end
describe " when locked " do
before :each do
system_gems " rack-1.0.0 "
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 " , " 1.0 "
G
end
it " returns success when the Gemfile is satisfied " do
bundle :install
bundle :check
expect ( out ) . to include ( " The Gemfile's dependencies are satisfied " )
end
it " shows what is missing with the current Gemfile if it is not satisfied " do
simulate_new_machine
2020-06-03 12:43:17 -04:00
bundle :check , :raise_on_error = > false
2019-04-14 02:01:35 -04:00
expect ( err ) . to match ( / The following gems are missing / )
expect ( err ) . to include ( " * rack (1.0 " )
2018-11-02 19:07:56 -04:00
end
end
2021-07-13 07:58:08 -04:00
describe " when locked with multiple dependents with different requirements " do
before :each do
build_repo4 do
build_gem " depends_on_rack " do | s |
s . add_dependency " rack " , " >= 1.0 "
end
build_gem " also_depends_on_rack " do | s |
s . add_dependency " rack " , " ~> 1.0 "
end
build_gem " rack "
end
gemfile <<-G
source " #{ file_uri_for ( gem_repo4 ) } "
gem " depends_on_rack "
gem " also_depends_on_rack "
G
bundle " lock "
end
it " shows what is missing with the current Gemfile without duplications " do
bundle :check , :raise_on_error = > false
expect ( err ) . to match ( / The following gems are missing / )
expect ( err ) . to include ( " * rack (1.0 " ) . once
end
end
2021-05-28 06:47:49 -04:00
describe " when using only scoped rubygems sources " do
before do
gemfile << ~ G
source " #{ file_uri_for ( gem_repo1 ) } " do
gem " rack "
end
G
end
it " returns success when the Gemfile is satisfied " do
system_gems " rack-1.0.0 " , :path = > default_bundle_path
bundle :check
expect ( out ) . to include ( " The Gemfile's dependencies are satisfied " )
end
end
describe " when using only scoped rubygems sources with indirect dependencies " do
before do
build_repo4 do
build_gem " depends_on_rack " do | s |
s . add_dependency " rack "
end
build_gem " rack "
end
gemfile << ~ G
source " #{ file_uri_for ( gem_repo4 ) } " do
gem " depends_on_rack "
end
G
end
it " returns success when the Gemfile is satisfied and generates a correct lockfile " do
system_gems " depends_on_rack-1.0 " , " rack-1.0 " , :gem_repo = > gem_repo4 , :path = > default_bundle_path
bundle :check
expect ( out ) . to include ( " The Gemfile's dependencies are satisfied " )
expect ( lockfile ) . to eq << ~ L
GEM
specs :
GEM
remote : #{file_uri_for(gem_repo4)}/
specs :
depends_on_rack ( 1 . 0 )
rack
rack ( 1 . 0 )
PLATFORMS
#{lockfile_platforms}
DEPENDENCIES
depends_on_rack!
BUNDLED WITH
#{Bundler::VERSION}
L
end
end
2018-11-02 19:07:56 -04:00
describe " BUNDLED WITH " do
def lock_with ( bundler_version = nil )
lock = <<-L
GEM
2019-05-06 12:06:21 -04:00
remote : #{file_uri_for(gem_repo1)}/
2018-11-02 19:07:56 -04:00
specs :
rack ( 1 . 0 . 0 )
PLATFORMS
#{lockfile_platforms}
DEPENDENCIES
rack
L
if bundler_version
lock += " \n BUNDLED WITH \n #{ bundler_version } \n "
end
lock
end
before do
2020-12-14 18:32:54 -05:00
bundle " config set --local path vendor/bundle "
2018-11-02 19:07:56 -04:00
install_gemfile <<-G
2019-05-06 12:06:21 -04:00
source " #{ file_uri_for ( gem_repo1 ) } "
2018-11-02 19:07:56 -04:00
gem " rack "
G
end
context " is not present " do
it " does not change the lock " do
lockfile lock_with ( nil )
bundle :check
lockfile_should_be lock_with ( nil )
end
end
context " is newer " do
it " does not change the lock but warns " do
lockfile lock_with ( Bundler :: VERSION . succ )
2020-06-03 14:45:36 -04:00
bundle :check
2019-06-01 05:49:40 -04:00
expect ( err ) . to include ( " the running version of Bundler ( #{ Bundler :: VERSION } ) is older than the version that created the lockfile ( #{ Bundler :: VERSION . succ } ) " )
2018-11-02 19:07:56 -04:00
lockfile_should_be lock_with ( Bundler :: VERSION . succ )
end
end
context " is older " do
it " does not change the lock " do
2020-12-14 18:32:54 -05:00
system_gems " bundler-1.18.0 "
lockfile lock_with ( " 1.18.0 " )
bundle :check
lockfile_should_be lock_with ( " 1.18.0 " )
2018-11-02 19:07:56 -04:00
end
end
end
end