1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560
|
# frozen_string_literal: true
RSpec.describe "install in deployment or frozen mode" do
before do
gemfile <<-G
source "https://gem.repo1"
gem "myrack"
G
end
context "with CLI flags", bundler: "< 3" do
it "fails without a lockfile and says that --deployment requires a lock" do
bundle "install --deployment", raise_on_error: false
expect(err).to include("The --deployment flag requires a lockfile")
end
it "fails without a lockfile and says that --frozen requires a lock" do
bundle "install --frozen", raise_on_error: false
expect(err).to include("The --frozen flag requires a lockfile")
end
it "disallows --deployment --system" do
bundle "install --deployment --system", raise_on_error: false
expect(err).to include("You have specified both --deployment")
expect(err).to include("Please choose only one option")
expect(exitstatus).to eq(15)
end
it "disallows --deployment --path --system" do
bundle "install --deployment --path . --system", raise_on_error: false
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")
expect(exitstatus).to eq(15)
end
it "doesn't mess up a subsequent `bundle install` after you try to deploy without a lock" do
bundle "install --deployment", raise_on_error: false
bundle :install
expect(the_bundle).to include_gems "myrack 1.0"
end
it "installs gems by default to vendor/bundle" do
bundle :lock
bundle "install --deployment"
expect(out).to include("vendor/bundle")
end
it "installs gems to custom path if specified" do
bundle :lock
bundle "install --path vendor/bundle2 --deployment"
expect(out).to include("vendor/bundle2")
end
it "works with the --frozen flag" do
bundle :lock
bundle "install --frozen"
end
it "explodes with the --deployment flag if you make a change and don't check in the lockfile" do
bundle :lock
gemfile <<-G
source "https://gem.repo1"
gem "myrack"
gem "myrack-obama"
G
bundle "install --deployment", raise_on_error: false
expect(err).to include("frozen mode")
expect(err).to include("You have added to the Gemfile")
expect(err).to include("* myrack-obama")
expect(err).not_to include("You have deleted from the Gemfile")
expect(err).not_to include("You have changed in the Gemfile")
end
end
it "fails without a lockfile and says that deployment requires a lock" do
bundle "config deployment true"
bundle "install", raise_on_error: false
expect(err).to include("The deployment setting requires a lockfile")
end
it "fails without a lockfile and says that frozen requires a lock" do
bundle "config frozen true"
bundle "install", raise_on_error: false
expect(err).to include("The frozen setting requires a lockfile")
end
it "still works if you are not in the app directory and specify --gemfile" do
bundle "install"
pristine_system_gems :bundler
bundle "config set --local deployment true"
bundle "config set --local path vendor/bundle"
bundle "install --gemfile #{tmp}/bundled_app/Gemfile", dir: tmp
expect(the_bundle).to include_gems "myrack 1.0"
end
it "works if you exclude a group with a git gem" do
build_git "foo"
gemfile <<-G
source "https://gem.repo1"
group :test do
gem "foo", :git => "#{lib_path("foo-1.0")}"
end
G
bundle :install
bundle "config set --local deployment true"
bundle "config set --local without test"
bundle :install
end
it "works when you bundle exec bundle" do
skip "doesn't find bundle" if Gem.win_platform?
bundle :install
bundle "config set --local deployment true"
bundle :install
bundle "exec bundle check", env: { "PATH" => path }
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
source "https://gem.repo1"
gem "foo", "1.0", :path => "#{lib_path("nested")}"
gem "bar", :path => "#{lib_path("nested")}"
G
bundle :install
bundle "config set --local deployment true"
bundle :install
end
it "works when path gems are specified twice" do
build_lib "foo", path: lib_path("nested/foo")
gemfile <<-G
source "https://gem.repo1"
gem "foo", :path => "#{lib_path("nested/foo")}"
gem "foo", :path => "#{lib_path("nested/foo")}"
G
bundle :install
bundle "config set --local deployment true"
bundle :install
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 "myrack-obama", ">= 1.0"
G
bundle "config set --local deployment true"
bundle :install, artifice: "endpoint_strict_basic_authentication"
end
it "works with sources given by a block" do
install_gemfile <<-G
source "https://gem.repo1"
source "https://gem.repo1" do
gem "myrack"
end
G
bundle "config set --local deployment true"
bundle :install
expect(the_bundle).to include_gems "myrack 1.0"
end
context "when replacing a host with the same host with credentials" do
before do
bundle "config set --local path vendor/bundle"
bundle "install"
gemfile <<-G
source "http://user_name:password@localgemserver.test/"
gem "myrack"
G
lockfile <<-G
GEM
remote: http://localgemserver.test/
specs:
myrack (1.0.0)
PLATFORMS
#{generic_local_platform}
DEPENDENCIES
myrack
G
bundle "config set --local deployment true"
end
it "allows the replace" do
bundle :install
expect(out).to match(/Bundle complete!/)
end
end
describe "with an existing lockfile" do
before do
bundle "install"
end
it "installs gems by default to vendor/bundle" do
bundle "config set deployment true"
expect do
bundle "install"
end.not_to change { bundled_app_lock.mtime }
expect(out).to include("vendor/bundle")
end
it "installs gems to custom path if specified" do
bundle "config set path vendor/bundle2"
bundle "config set deployment true"
bundle "install"
expect(out).to include("vendor/bundle2")
end
it "installs gems to custom path if specified, even when configured through ENV" do
bundle "config set deployment true"
bundle "install", env: { "BUNDLE_PATH" => "vendor/bundle2" }
expect(out).to include("vendor/bundle2")
end
it "works with the `frozen` setting" do
bundle "config set frozen true"
expect do
bundle "install"
end.not_to change { bundled_app_lock.mtime }
end
it "works with BUNDLE_FROZEN if you didn't change anything" do
expect do
bundle :install, env: { "BUNDLE_FROZEN" => "true" }
end.not_to change { bundled_app_lock.mtime }
end
it "explodes with the `deployment` setting if you make a change and don't check in the lockfile" do
gemfile <<-G
source "https://gem.repo1"
gem "myrack"
gem "myrack-obama"
G
bundle "config set --local deployment true"
bundle :install, raise_on_error: false
expect(err).to include("frozen mode")
expect(err).to include("You have added to the Gemfile")
expect(err).to include("* myrack-obama")
expect(err).not_to include("You have deleted from the Gemfile")
expect(err).not_to include("You have changed in the Gemfile")
end
it "works if a path gem is missing but is in a without group" do
build_lib "path_gem"
install_gemfile <<-G
source "https://gem.repo1"
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")
bundle "config set --local path .bundle"
bundle "config set --local without development"
bundle "config set --local deployment true"
bundle :install, env: { "DEBUG" => "1" }
run "puts :WIN"
expect(out).to eq("WIN")
end
it "works if a gem is missing, but it's on a different platform" do
build_repo2
install_gemfile <<-G
source "https://gem.repo2"
source "https://gem.repo1" do
gem "rake", platform: :#{not_local_tag}
end
G
bundle :install, env: { "BUNDLE_FROZEN" => "true" }
expect(last_command).to be_success
end
it "shows a good error if a gem is missing from the lockfile" do
build_repo4 do
build_gem "foo"
build_gem "bar"
end
gemfile <<-G
source "https://gem.repo4"
gem "foo"
gem "bar"
G
lockfile <<~L
GEM
remote: https://gem.repo4/
specs:
foo (1.0)
PLATFORMS
#{lockfile_platforms}
DEPENDENCIES
foo
bar
BUNDLED WITH
#{Bundler::VERSION}
L
bundle :install, env: { "BUNDLE_FROZEN" => "true" }, raise_on_error: false, artifice: "compact_index"
expect(err).to include("Your lockfile is missing \"bar\", but can't be updated because frozen mode is set")
end
it "explodes if a path gem is missing" do
build_lib "path_gem"
install_gemfile <<-G
source "https://gem.repo1"
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")
bundle "config set --local path .bundle"
bundle "config set --local deployment true"
bundle :install, raise_on_error: false
expect(err).to include("The path `#{lib_path("path_gem-1.0")}` does not exist.")
end
it "can have --frozen set via an environment variable" do
gemfile <<-G
source "https://gem.repo1"
gem "myrack"
gem "myrack-obama"
G
ENV["BUNDLE_FROZEN"] = "1"
bundle "install", raise_on_error: false
expect(err).to include("frozen mode")
expect(err).to include("You have added to the Gemfile")
expect(err).to include("* myrack-obama")
expect(err).not_to include("You have deleted from the Gemfile")
expect(err).not_to include("You have changed in the Gemfile")
end
it "can have --deployment set via an environment variable" do
gemfile <<-G
source "https://gem.repo1"
gem "myrack"
gem "myrack-obama"
G
ENV["BUNDLE_DEPLOYMENT"] = "true"
bundle "install", raise_on_error: false
expect(err).to include("frozen mode")
expect(err).to include("You have added to the Gemfile")
expect(err).to include("* myrack-obama")
expect(err).not_to include("You have deleted from the Gemfile")
expect(err).not_to include("You have changed in the Gemfile")
end
it "installs gems by default to vendor/bundle when deployment mode is set via an environment variable" do
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 " do
ENV["BUNDLE_DEPLOYMENT"] = "true"
ENV["BUNDLE_PATH"] = "vendor/bundle2"
bundle "install"
expect(out).to include("vendor/bundle2")
end
it "can have --frozen set to false via an environment variable" do
gemfile <<-G
source "https://gem.repo1"
gem "myrack"
gem "myrack-obama"
G
ENV["BUNDLE_FROZEN"] = "false"
ENV["BUNDLE_DEPLOYMENT"] = "false"
bundle "install"
expect(out).not_to include("frozen mode")
expect(out).not_to include("You have added to the Gemfile")
expect(out).not_to include("* myrack-obama")
end
it "explodes if you replace a gem and don't check in the lockfile" do
gemfile <<-G
source "https://gem.repo1"
gem "activesupport"
G
bundle "config set --local deployment true"
bundle :install, raise_on_error: false
expect(err).to include("frozen 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* myrack")
expect(err).not_to include("You have changed in the Gemfile")
end
it "explodes if you remove a gem and don't check in the lockfile" do
gemfile 'source "https://gem.repo1"'
bundle "config set --local deployment true"
bundle :install, raise_on_error: false
expect(err).to include("Some dependencies were deleted")
expect(err).to include("frozen mode")
expect(err).to include("You have deleted from the Gemfile:\n* myrack")
expect(err).not_to include("You have changed in the Gemfile")
end
it "explodes if you add a source" do
gemfile <<-G
source "https://gem.repo1"
gem "myrack", :git => "git://hubz.com"
G
bundle "config set --local deployment true"
bundle :install, raise_on_error: false
expect(err).to include("frozen mode")
expect(err).not_to include("You have added to the Gemfile")
expect(err).to include("You have changed in the Gemfile:\n* myrack from `no specified source` to `git://hubz.com`")
end
it "explodes if you change a source from git to the default" do
build_git "myrack"
install_gemfile <<-G
source "https://gem.repo1"
gem "myrack", :git => "#{lib_path("myrack-1.0")}"
G
gemfile <<-G
source "https://gem.repo1"
gem "myrack"
G
bundle "config set --local deployment true"
bundle :install, raise_on_error: false
expect(err).to include("frozen mode")
expect(err).not_to include("You have deleted from the Gemfile")
expect(err).not_to include("You have added to the Gemfile")
expect(err).to include("You have changed in the Gemfile:\n* myrack from `#{lib_path("myrack-1.0")}` to `no specified source`")
end
it "explodes if you change a source from git to the default, in presence of other git sources" do
build_lib "foo", path: lib_path("myrack/foo")
build_git "myrack", path: lib_path("myrack")
install_gemfile <<-G
source "https://gem.repo1"
gem "myrack", :git => "#{lib_path("myrack")}"
gem "foo", :git => "#{lib_path("myrack")}"
G
gemfile <<-G
source "https://gem.repo1"
gem "myrack"
gem "foo", :git => "#{lib_path("myrack")}"
G
bundle "config set --local deployment true"
bundle :install, raise_on_error: false
expect(err).to include("frozen mode")
expect(err).to include("You have changed in the Gemfile:\n* myrack from `#{lib_path("myrack")}` to `no specified source`")
expect(err).not_to include("You have added to the Gemfile")
expect(err).not_to include("You have deleted from the Gemfile")
end
it "explodes if you change a source from path to git" do
build_git "myrack", path: lib_path("myrack")
install_gemfile <<-G
source "https://gem.repo1"
gem "myrack", :path => "#{lib_path("myrack")}"
G
gemfile <<-G
source "https://gem.repo1"
gem "myrack", :git => "https:/my-git-repo-for-myrack"
G
bundle "config set --local frozen true"
bundle :install, raise_on_error: false
expect(err).to include("frozen mode")
expect(err).to include("You have changed in the Gemfile:\n* myrack from `#{lib_path("myrack")}` to `https:/my-git-repo-for-myrack`")
expect(err).not_to include("You have added to the Gemfile")
expect(err).not_to include("You have deleted from the Gemfile")
end
it "remembers that the bundle is frozen at runtime" do
bundle :lock
bundle "config set --local deployment true"
gemfile <<-G
source "https://gem.repo1"
gem "myrack", "1.0.0"
gem "myrack-obama"
G
run "require 'myrack'", raise_on_error: false
expect(err).to include <<~E.strip
The dependencies in your gemfile changed, but the lockfile can't be updated because frozen mode is set (Bundler::ProductionError)
You have added to the Gemfile:
* myrack (= 1.0.0)
* myrack-obama
You have deleted from the Gemfile:
* myrack
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")
install_gemfile <<-G
source "https://gem.repo1"
gem "foo", :path => "#{lib_path("foo")}"
G
bundle :install
expect(the_bundle).to include_gems "foo 1.0"
bundle "config set cache_all true"
bundle :cache
expect(bundled_app("vendor/cache/foo")).to be_directory
bundle "install --local"
expect(out).to include("Updating files in vendor/cache")
pristine_system_gems :bundler
bundle "config set --local deployment true"
bundle "install --verbose"
expect(out).not_to include("can't be updated because frozen mode is set")
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
|