mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
[rubygems/rubygems] Refactor specs to not try to remove folders that don't exist
This has the following benefits:
* Avoid duplicated work in some specs that first build a repo, and then
overwrite it with a completely different set of gems.
* Reduce RSpec nesting and improve readability.
* The change also made surfaces several specs that were incorrect since
they were unintentionally not testing the right thing.
ed430883e0
This commit is contained in:
parent
c68088038f
commit
f656d34f10
17 changed files with 214 additions and 156 deletions
10
spec/bundler/cache/gems_spec.rb
vendored
10
spec/bundler/cache/gems_spec.rb
vendored
|
@ -291,7 +291,7 @@ RSpec.describe "bundle cache" do
|
|||
expect(cached_gem("platform_specific-1.0-java")).to exist
|
||||
end
|
||||
|
||||
simulate_new_machine
|
||||
pristine_system_gems :bundler
|
||||
|
||||
simulate_platform "x86-darwin-100" do
|
||||
install_gemfile <<-G
|
||||
|
@ -312,7 +312,8 @@ RSpec.describe "bundle cache" do
|
|||
path: cached_myrack.parent,
|
||||
rubygems_version: "1.3.2"
|
||||
|
||||
simulate_new_machine
|
||||
FileUtils.rm_rf default_bundle_path
|
||||
system_gems :bundler
|
||||
|
||||
FileUtils.rm bundled_app_lock
|
||||
bundle :install, raise_on_error: false
|
||||
|
@ -344,7 +345,8 @@ RSpec.describe "bundle cache" do
|
|||
c.checksum gem_repo1, "myrack", "1.0.0"
|
||||
end
|
||||
|
||||
simulate_new_machine
|
||||
FileUtils.rm_rf default_bundle_path
|
||||
system_gems :bundler
|
||||
|
||||
lockfile <<-L
|
||||
GEM
|
||||
|
@ -369,7 +371,7 @@ RSpec.describe "bundle cache" do
|
|||
setup_main_repo
|
||||
cached_gem("myrack-1.0.0").rmtree
|
||||
build_gem "myrack", "1.0.0", path: bundled_app("vendor/cache")
|
||||
simulate_new_machine
|
||||
pristine_system_gems :bundler
|
||||
|
||||
lockfile <<-L
|
||||
GEM
|
||||
|
|
18
spec/bundler/cache/git_spec.rb
vendored
18
spec/bundler/cache/git_spec.rb
vendored
|
@ -164,7 +164,7 @@ RSpec.describe "bundle cache with git" do
|
|||
bundle "config set path vendor/bundle"
|
||||
bundle :install
|
||||
|
||||
simulate_new_machine
|
||||
pristine_system_gems :bundler
|
||||
with_path_as "" do
|
||||
bundle "config set deployment true"
|
||||
bundle "install --local"
|
||||
|
@ -181,10 +181,8 @@ RSpec.describe "bundle cache with git" do
|
|||
G
|
||||
bundle "config set cache_all true"
|
||||
bundle :cache, "all-platforms" => true
|
||||
FileUtils.rm_rf Dir.glob(default_bundle_path("bundler/gems/extensions/**/foo-1.0-*")).first.to_s
|
||||
FileUtils.rm_rf Dir.glob(default_bundle_path("bundler/gems/foo-1.0-*")).first.to_s
|
||||
|
||||
simulate_new_machine
|
||||
pristine_system_gems :bundler
|
||||
bundle "config set frozen true"
|
||||
bundle "install --local --verbose"
|
||||
expect(out).to_not include("Fetching")
|
||||
|
@ -200,12 +198,9 @@ RSpec.describe "bundle cache with git" do
|
|||
G
|
||||
bundle "config set cache_all true"
|
||||
bundle :cache, "all-platforms" => true
|
||||
FileUtils.rm_rf Dir.glob(default_bundle_path("bundler/gems/extensions/**/foo-1.0-*")).first.to_s
|
||||
FileUtils.rm_rf Dir.glob(default_bundle_path("bundler/gems/foo-1.0-*")).first.to_s
|
||||
|
||||
simulate_new_machine
|
||||
pristine_system_gems :bundler
|
||||
bundle "config set frozen true"
|
||||
FileUtils.rm_rf "#{default_bundle_path}/cache/bundler/git/foo-1.0-*"
|
||||
bundle "install --local --verbose"
|
||||
expect(out).to_not include("Fetching")
|
||||
expect(the_bundle).to include_gem "foo 1.0"
|
||||
|
@ -220,12 +215,9 @@ RSpec.describe "bundle cache with git" do
|
|||
G
|
||||
bundle "config set cache_all true"
|
||||
bundle :cache, "all-platforms" => true
|
||||
FileUtils.rm_rf Dir.glob(default_bundle_path("bundler/gems/extensions/**/foo-1.0-*")).first.to_s
|
||||
FileUtils.rm_rf Dir.glob(default_bundle_path("bundler/gems/foo-1.0-*")).first.to_s
|
||||
|
||||
simulate_new_machine
|
||||
pristine_system_gems :bundler
|
||||
bundle "config set frozen true"
|
||||
FileUtils.rm_rf "#{default_bundle_path}/cache/bundler/git/foo-1.0-*"
|
||||
|
||||
# Remove untracked files (including the empty refs dir in the cache)
|
||||
Dir.chdir(bundled_app) do
|
||||
|
@ -388,7 +380,7 @@ RSpec.describe "bundle cache with git" do
|
|||
bundle "config set cache_all true"
|
||||
bundle :cache, "all-platforms" => true, :install => false
|
||||
|
||||
simulate_new_machine
|
||||
pristine_system_gems :bundler
|
||||
with_path_as "" do
|
||||
bundle "config set deployment true"
|
||||
bundle :install, local: true
|
||||
|
|
|
@ -356,7 +356,7 @@ RSpec.describe "bundle install with gem sources" do
|
|||
G
|
||||
|
||||
bundle :cache
|
||||
simulate_new_machine
|
||||
pristine_system_gems :bundler
|
||||
FileUtils.rm_rf gem_repo2
|
||||
|
||||
bundle "install --local"
|
||||
|
@ -371,7 +371,7 @@ RSpec.describe "bundle install with gem sources" do
|
|||
G
|
||||
|
||||
bundle :cache
|
||||
simulate_new_machine
|
||||
pristine_system_gems :bundler
|
||||
FileUtils.rm_rf gem_repo2
|
||||
|
||||
bundle "config set --local deployment true"
|
||||
|
@ -388,7 +388,7 @@ RSpec.describe "bundle install with gem sources" do
|
|||
G
|
||||
|
||||
bundle :cache
|
||||
simulate_new_machine
|
||||
pristine_system_gems :bundler
|
||||
FileUtils.rm_rf gem_repo2
|
||||
|
||||
bundle "config set --local cache_all_platforms true"
|
||||
|
@ -445,9 +445,8 @@ RSpec.describe "bundle install with gem sources" do
|
|||
bundle "config set path vendor/bundle"
|
||||
bundle :cache, artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s }
|
||||
|
||||
build_repo4 do
|
||||
# simulate removal of all remote gems
|
||||
end
|
||||
# simulate removal of all remote gems
|
||||
empty_repo4
|
||||
|
||||
# delete compact index cache
|
||||
FileUtils.rm_rf home(".bundle/cache/compact_index")
|
||||
|
@ -483,7 +482,7 @@ RSpec.describe "bundle install with gem sources" do
|
|||
bundle :cache
|
||||
end
|
||||
|
||||
simulate_new_machine
|
||||
pristine_system_gems :bundler
|
||||
|
||||
bundle "config set --local force_ruby_platform true"
|
||||
|
||||
|
|
|
@ -328,7 +328,8 @@ RSpec.describe "bundle check" do
|
|||
end
|
||||
|
||||
it "shows what is missing with the current Gemfile if it is not satisfied" do
|
||||
simulate_new_machine
|
||||
FileUtils.rm_rf default_bundle_path
|
||||
system_gems :bundler
|
||||
bundle :check, raise_on_error: false
|
||||
expect(err).to match(/The following gems are missing/)
|
||||
expect(err).to include("* myrack (1.0")
|
||||
|
|
|
@ -1550,88 +1550,94 @@ RSpec.describe "bundle install with gem sources" do
|
|||
end
|
||||
|
||||
context "with --prefer-local flag" do
|
||||
before do
|
||||
build_repo4 do
|
||||
build_gem "foo", "1.0.1"
|
||||
build_gem "foo", "1.0.0"
|
||||
build_gem "bar", "1.0.0"
|
||||
context "and gems available locally" do
|
||||
before do
|
||||
build_repo4 do
|
||||
build_gem "foo", "1.0.1"
|
||||
build_gem "foo", "1.0.0"
|
||||
build_gem "bar", "1.0.0"
|
||||
|
||||
build_gem "a", "1.0.0" do |s|
|
||||
s.add_dependency "foo", "~> 1.0.0"
|
||||
build_gem "a", "1.0.0" do |s|
|
||||
s.add_dependency "foo", "~> 1.0.0"
|
||||
end
|
||||
|
||||
build_gem "b", "1.0.0" do |s|
|
||||
s.add_dependency "foo", "~> 1.0.1"
|
||||
end
|
||||
end
|
||||
|
||||
build_gem "b", "1.0.0" do |s|
|
||||
s.add_dependency "foo", "~> 1.0.1"
|
||||
system_gems "foo-1.0.0", path: default_bundle_path, gem_repo: gem_repo4
|
||||
end
|
||||
|
||||
it "fetches remote sources when not available locally" do
|
||||
install_gemfile <<-G, "prefer-local": true, verbose: true
|
||||
source "https://gem.repo4"
|
||||
|
||||
gem "foo"
|
||||
gem "bar"
|
||||
G
|
||||
|
||||
expect(out).to include("Using foo 1.0.0").and include("Fetching bar 1.0.0").and include("Installing bar 1.0.0")
|
||||
expect(last_command).to be_success
|
||||
end
|
||||
|
||||
it "fetches remote sources when local version does not match requirements" do
|
||||
install_gemfile <<-G, "prefer-local": true, verbose: true
|
||||
source "https://gem.repo4"
|
||||
|
||||
gem "foo", "1.0.1"
|
||||
gem "bar"
|
||||
G
|
||||
|
||||
expect(out).to include("Fetching foo 1.0.1").and include("Installing foo 1.0.1").and include("Fetching bar 1.0.0").and include("Installing bar 1.0.0")
|
||||
expect(last_command).to be_success
|
||||
end
|
||||
|
||||
it "uses the locally available version for sub-dependencies when possible" do
|
||||
install_gemfile <<-G, "prefer-local": true, verbose: true
|
||||
source "https://gem.repo4"
|
||||
|
||||
gem "a"
|
||||
G
|
||||
|
||||
expect(out).to include("Using foo 1.0.0").and include("Fetching a 1.0.0").and include("Installing a 1.0.0")
|
||||
expect(last_command).to be_success
|
||||
end
|
||||
|
||||
it "fetches remote sources for sub-dependencies when the locally available version does not satisfy the requirement" do
|
||||
install_gemfile <<-G, "prefer-local": true, verbose: true
|
||||
source "https://gem.repo4"
|
||||
|
||||
gem "b"
|
||||
G
|
||||
|
||||
expect(out).to include("Fetching foo 1.0.1").and include("Installing foo 1.0.1").and include("Fetching b 1.0.0").and include("Installing b 1.0.0")
|
||||
expect(last_command).to be_success
|
||||
end
|
||||
end
|
||||
|
||||
context "and no gems available locally" do
|
||||
before do
|
||||
build_repo4 do
|
||||
build_gem "myreline", "0.3.8"
|
||||
build_gem "debug", "0.2.1"
|
||||
|
||||
build_gem "debug", "1.10.0" do |s|
|
||||
s.add_dependency "myreline"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
system_gems "foo-1.0.0", path: default_bundle_path, gem_repo: gem_repo4
|
||||
end
|
||||
it "resolves to the latest version if no gems are available locally" do
|
||||
install_gemfile <<~G, "prefer-local": true, verbose: true
|
||||
source "https://gem.repo4"
|
||||
|
||||
it "fetches remote sources when not available locally" do
|
||||
install_gemfile <<-G, "prefer-local": true, verbose: true
|
||||
source "https://gem.repo4"
|
||||
gem "debug"
|
||||
G
|
||||
|
||||
gem "foo"
|
||||
gem "bar"
|
||||
G
|
||||
|
||||
expect(out).to include("Using foo 1.0.0").and include("Fetching bar 1.0.0").and include("Installing bar 1.0.0")
|
||||
expect(last_command).to be_success
|
||||
end
|
||||
|
||||
it "fetches remote sources when local version does not match requirements" do
|
||||
install_gemfile <<-G, "prefer-local": true, verbose: true
|
||||
source "https://gem.repo4"
|
||||
|
||||
gem "foo", "1.0.1"
|
||||
gem "bar"
|
||||
G
|
||||
|
||||
expect(out).to include("Fetching foo 1.0.1").and include("Installing foo 1.0.1").and include("Fetching bar 1.0.0").and include("Installing bar 1.0.0")
|
||||
expect(last_command).to be_success
|
||||
end
|
||||
|
||||
it "uses the locally available version for sub-dependencies when possible" do
|
||||
install_gemfile <<-G, "prefer-local": true, verbose: true
|
||||
source "https://gem.repo4"
|
||||
|
||||
gem "a"
|
||||
G
|
||||
|
||||
expect(out).to include("Using foo 1.0.0").and include("Fetching a 1.0.0").and include("Installing a 1.0.0")
|
||||
expect(last_command).to be_success
|
||||
end
|
||||
|
||||
it "fetches remote sources for sub-dependencies when the locally available version does not satisfy the requirement" do
|
||||
install_gemfile <<-G, "prefer-local": true, verbose: true
|
||||
source "https://gem.repo4"
|
||||
|
||||
gem "b"
|
||||
G
|
||||
|
||||
expect(out).to include("Fetching foo 1.0.1").and include("Installing foo 1.0.1").and include("Fetching b 1.0.0").and include("Installing b 1.0.0")
|
||||
expect(last_command).to be_success
|
||||
end
|
||||
|
||||
it "resolves to the latest version if no gems are available locally" do
|
||||
build_repo4 do
|
||||
build_gem "myreline", "0.3.8"
|
||||
build_gem "debug", "0.2.1"
|
||||
|
||||
build_gem "debug", "1.10.0" do |s|
|
||||
s.add_dependency "myreline"
|
||||
end
|
||||
expect(out).to include("Fetching debug 1.10.0").and include("Installing debug 1.10.0").and include("Fetching myreline 0.3.8").and include("Installing myreline 0.3.8")
|
||||
expect(last_command).to be_success
|
||||
end
|
||||
|
||||
install_gemfile <<~G, "prefer-local": true, verbose: true
|
||||
source "https://gem.repo4"
|
||||
|
||||
gem "debug"
|
||||
G
|
||||
|
||||
expect(out).to include("Fetching debug 1.10.0").and include("Installing debug 1.10.0").and include("Fetching myreline 0.3.8").and include("Installing myreline 0.3.8")
|
||||
expect(last_command).to be_success
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ RSpec.describe "bundle lock" do
|
|||
L
|
||||
end
|
||||
|
||||
before :each do
|
||||
let(:gemfile_with_rails_weakling_and_foo_from_repo4) do
|
||||
build_repo4 do
|
||||
FileUtils.cp rake_path, "#{gem_repo4}/gems/"
|
||||
|
||||
|
@ -143,12 +143,16 @@ RSpec.describe "bundle lock" do
|
|||
end
|
||||
|
||||
it "prints a lockfile when there is no existing lockfile with --print" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
bundle "lock --print"
|
||||
|
||||
expect(out).to eq(expected_lockfile.chomp)
|
||||
end
|
||||
|
||||
it "prints a lockfile when there is an existing lockfile with --print" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
lockfile expected_lockfile
|
||||
|
||||
bundle "lock --print"
|
||||
|
@ -157,6 +161,8 @@ RSpec.describe "bundle lock" do
|
|||
end
|
||||
|
||||
it "prints a lockfile when there is an existing checksums lockfile with --print" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
lockfile expected_lockfile
|
||||
|
||||
bundle "lock --print"
|
||||
|
@ -165,12 +171,16 @@ RSpec.describe "bundle lock" do
|
|||
end
|
||||
|
||||
it "writes a lockfile when there is no existing lockfile" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
bundle "lock"
|
||||
|
||||
expect(read_lockfile).to eq(expected_lockfile)
|
||||
end
|
||||
|
||||
it "prints a lockfile without fetching new checksums if the existing lockfile had no checksums" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
lockfile expected_lockfile
|
||||
|
||||
bundle "lock --print"
|
||||
|
@ -179,6 +189,8 @@ RSpec.describe "bundle lock" do
|
|||
end
|
||||
|
||||
it "touches the lockfile when there is an existing lockfile that does not need changes" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
lockfile expected_lockfile
|
||||
|
||||
expect do
|
||||
|
@ -187,6 +199,8 @@ RSpec.describe "bundle lock" do
|
|||
end
|
||||
|
||||
it "does not touch lockfile with --print" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
lockfile expected_lockfile
|
||||
|
||||
expect do
|
||||
|
@ -195,6 +209,8 @@ RSpec.describe "bundle lock" do
|
|||
end
|
||||
|
||||
it "writes a lockfile when there is an outdated lockfile using --update" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
lockfile outdated_lockfile
|
||||
|
||||
bundle "lock --update"
|
||||
|
@ -203,6 +219,8 @@ RSpec.describe "bundle lock" do
|
|||
end
|
||||
|
||||
it "prints an updated lockfile when there is an outdated lockfile using --print --update" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
lockfile outdated_lockfile
|
||||
|
||||
bundle "lock --print --update"
|
||||
|
@ -211,6 +229,8 @@ RSpec.describe "bundle lock" do
|
|||
end
|
||||
|
||||
it "emits info messages to stderr when updating an outdated lockfile using --print --update" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
lockfile outdated_lockfile
|
||||
|
||||
bundle "lock --print --update"
|
||||
|
@ -222,6 +242,8 @@ RSpec.describe "bundle lock" do
|
|||
end
|
||||
|
||||
it "writes a lockfile when there is an outdated lockfile and bundle is frozen" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
lockfile outdated_lockfile
|
||||
|
||||
bundle "lock --update", env: { "BUNDLE_FROZEN" => "true" }
|
||||
|
@ -230,12 +252,16 @@ RSpec.describe "bundle lock" do
|
|||
end
|
||||
|
||||
it "does not fetch remote specs when using the --local option" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
bundle "lock --update --local", raise_on_error: false
|
||||
|
||||
expect(err).to match(/locally installed gems/)
|
||||
end
|
||||
|
||||
it "does not fetch remote checksums with --local" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
lockfile expected_lockfile
|
||||
|
||||
bundle "lock --print --local"
|
||||
|
@ -244,6 +270,8 @@ RSpec.describe "bundle lock" do
|
|||
end
|
||||
|
||||
it "works with --gemfile flag" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
gemfile "CustomGemfile", <<-G
|
||||
source "https://gem.repo4"
|
||||
gem "foo"
|
||||
|
@ -275,6 +303,8 @@ RSpec.describe "bundle lock" do
|
|||
end
|
||||
|
||||
it "writes to a custom location using --lockfile" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
bundle "lock --lockfile=lock"
|
||||
|
||||
expect(out).to match(/Writing lockfile to.+lock/)
|
||||
|
@ -283,6 +313,8 @@ RSpec.describe "bundle lock" do
|
|||
end
|
||||
|
||||
it "writes to custom location using --lockfile when a default lockfile is present" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
bundle "install"
|
||||
bundle "lock --lockfile=lock"
|
||||
|
||||
|
@ -338,6 +370,8 @@ RSpec.describe "bundle lock" do
|
|||
end
|
||||
|
||||
it "update specific gems using --update" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
checksums = checksums_section_when_enabled do |c|
|
||||
c.checksum gem_repo4, "actionmailer", "2.3.1"
|
||||
c.checksum gem_repo4, "actionpack", "2.3.1"
|
||||
|
@ -515,6 +549,8 @@ RSpec.describe "bundle lock" do
|
|||
end
|
||||
|
||||
it "preserves unknown checksum algorithms" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
lockfile expected_lockfile.gsub(/(sha256=[a-f0-9]+)$/, "constant=true,\\1,xyz=123")
|
||||
|
||||
previous_lockfile = read_lockfile
|
||||
|
@ -525,6 +561,8 @@ RSpec.describe "bundle lock" do
|
|||
end
|
||||
|
||||
it "does not unlock git sources when only uri shape changes" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
build_git("foo")
|
||||
|
||||
install_gemfile <<-G
|
||||
|
@ -543,6 +581,8 @@ RSpec.describe "bundle lock" do
|
|||
end
|
||||
|
||||
it "updates specific gems using --update using the locked revision of unrelated git gems for resolving" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
ref = build_git("foo").ref_for("HEAD")
|
||||
|
||||
gemfile <<-G
|
||||
|
@ -581,6 +621,8 @@ RSpec.describe "bundle lock" do
|
|||
end
|
||||
|
||||
it "errors when updating a missing specific gems using --update" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
lockfile expected_lockfile
|
||||
|
||||
bundle "lock --update blahblah", raise_on_error: false
|
||||
|
@ -590,6 +632,8 @@ RSpec.describe "bundle lock" do
|
|||
end
|
||||
|
||||
it "can lock without downloading gems" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
gemfile <<-G
|
||||
source "https://gem.repo1"
|
||||
|
||||
|
@ -762,6 +806,8 @@ RSpec.describe "bundle lock" do
|
|||
end
|
||||
|
||||
it "supports adding new platforms when there's no previous lockfile" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
bundle "lock --add-platform java x86-mingw32 --verbose"
|
||||
expect(out).to include("Resolving dependencies because there's no lockfile")
|
||||
|
||||
|
@ -770,6 +816,8 @@ RSpec.describe "bundle lock" do
|
|||
end
|
||||
|
||||
it "supports adding new platforms when a previous lockfile exists" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
bundle "lock"
|
||||
bundle "lock --add-platform java x86-mingw32 --verbose"
|
||||
expect(out).to include("Found changes from the lockfile, re-resolving dependencies because you are adding a new platform to your lockfile")
|
||||
|
@ -835,6 +883,8 @@ RSpec.describe "bundle lock" do
|
|||
end
|
||||
|
||||
it "supports adding new platforms with force_ruby_platform = true" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
lockfile <<-L
|
||||
GEM
|
||||
remote: https://gem.repo1/
|
||||
|
@ -858,6 +908,8 @@ RSpec.describe "bundle lock" do
|
|||
end
|
||||
|
||||
it "supports adding the `ruby` platform" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
bundle "lock --add-platform ruby"
|
||||
|
||||
allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
|
||||
|
@ -865,12 +917,16 @@ RSpec.describe "bundle lock" do
|
|||
end
|
||||
|
||||
it "fails when adding an unknown platform" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
bundle "lock --add-platform foobarbaz", raise_on_error: false
|
||||
expect(err).to include("The platform `foobarbaz` is unknown to RubyGems and can't be added to the lockfile")
|
||||
expect(last_command).to be_failure
|
||||
end
|
||||
|
||||
it "allows removing platforms" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
bundle "lock --add-platform java x86-mingw32"
|
||||
|
||||
allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
|
||||
|
@ -944,6 +1000,8 @@ RSpec.describe "bundle lock" do
|
|||
end
|
||||
|
||||
it "errors when removing all platforms" do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
bundle "lock --remove-platform #{local_platform}", raise_on_error: false
|
||||
expect(err).to include("Removing all platforms from the bundle is not allowed")
|
||||
end
|
||||
|
@ -1378,6 +1436,8 @@ RSpec.describe "bundle lock" do
|
|||
|
||||
context "when an update is available" do
|
||||
before do
|
||||
gemfile_with_rails_weakling_and_foo_from_repo4
|
||||
|
||||
update_repo4 do
|
||||
build_gem "foo", "2.0"
|
||||
end
|
||||
|
|
|
@ -974,7 +974,7 @@ RSpec.describe "bundle outdated" do
|
|||
gem "terranova", '8'
|
||||
G
|
||||
|
||||
simulate_new_machine
|
||||
pristine_system_gems :bundler
|
||||
|
||||
update_git "foo", path: lib_path("foo")
|
||||
update_repo2 do
|
||||
|
|
|
@ -88,7 +88,7 @@ RSpec.describe "install in deployment or frozen mode" do
|
|||
|
||||
it "still works if you are not in the app directory and specify --gemfile" do
|
||||
bundle "install"
|
||||
simulate_new_machine
|
||||
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
|
||||
|
@ -547,7 +547,7 @@ RSpec.describe "install in deployment or frozen mode" do
|
|||
bundle "install --local"
|
||||
expect(out).to include("Updating files in vendor/cache")
|
||||
|
||||
simulate_new_machine
|
||||
pristine_system_gems :bundler
|
||||
bundle "config set --local deployment true"
|
||||
bundle "install --verbose"
|
||||
expect(out).not_to include("but the lockfile can't be updated because frozen mode is set")
|
||||
|
|
|
@ -31,14 +31,13 @@ RSpec.describe "bundle install with git sources" do
|
|||
end
|
||||
|
||||
it "does not write to cache on bundler/setup" do
|
||||
cache_path = default_bundle_path("cache")
|
||||
FileUtils.rm_rf(cache_path)
|
||||
FileUtils.rm_rf(default_cache_path)
|
||||
ruby "require 'bundler/setup'"
|
||||
expect(cache_path).not_to exist
|
||||
expect(default_cache_path).not_to exist
|
||||
end
|
||||
|
||||
it "caches the git repo globally and properly uses the cached repo on the next invocation" do
|
||||
simulate_new_machine
|
||||
pristine_system_gems :bundler
|
||||
bundle "config set global_gem_cache true"
|
||||
bundle :install
|
||||
expect(Dir["#{home}/.bundle/cache/git/foo-1.0-*"]).to have_attributes size: 1
|
||||
|
@ -1218,7 +1217,7 @@ RSpec.describe "bundle install with git sources" do
|
|||
gem "valim", "= 1.0", :git => "#{lib_path("valim")}"
|
||||
G
|
||||
|
||||
simulate_new_machine
|
||||
pristine_system_gems :bundler
|
||||
|
||||
bundle "config set --local deployment true"
|
||||
bundle :install
|
||||
|
@ -1605,7 +1604,7 @@ In Gemfile:
|
|||
G
|
||||
bundle "config set --global path vendor/bundle"
|
||||
bundle :install
|
||||
simulate_new_machine
|
||||
pristine_system_gems :bundler
|
||||
|
||||
bundle "install", env: { "PATH" => "" }
|
||||
expect(out).to_not include("You need to install git to be able to use gems from git repositories.")
|
||||
|
|
|
@ -7,12 +7,8 @@ RSpec.describe "bundle install with a lockfile present" do
|
|||
gem "myrack", "1.0.0"
|
||||
G
|
||||
|
||||
subject do
|
||||
install_gemfile(gf)
|
||||
end
|
||||
|
||||
it "touches the lockfile on install even when nothing has changed" do
|
||||
subject
|
||||
install_gemfile(gf)
|
||||
expect { bundle :install }.to change { bundled_app_lock.mtime }
|
||||
end
|
||||
|
||||
|
@ -22,31 +18,24 @@ RSpec.describe "bundle install with a lockfile present" do
|
|||
context "with plugins disabled" do
|
||||
before do
|
||||
bundle "config set plugins false"
|
||||
subject
|
||||
end
|
||||
|
||||
it "does not evaluate the gemfile twice" do
|
||||
it "does not evaluate the gemfile twice when the gem is already installed" do
|
||||
install_gemfile(gf)
|
||||
bundle :install
|
||||
|
||||
with_env_vars("BUNDLER_SPEC_NO_APPEND" => "1") { expect(the_bundle).to include_gem "myrack 1.0.0" }
|
||||
|
||||
# The first eval is from the initial install, we're testing that the
|
||||
# second install doesn't double-eval
|
||||
expect(bundled_app("evals").read.lines.to_a.size).to eq(2)
|
||||
end
|
||||
|
||||
context "when the gem is not installed" do
|
||||
before { FileUtils.rm_rf bundled_app(".bundle") }
|
||||
it "does not evaluate the gemfile twice when the gem is not installed" do
|
||||
gemfile(gf)
|
||||
bundle :install
|
||||
|
||||
it "does not evaluate the gemfile twice" do
|
||||
bundle :install
|
||||
with_env_vars("BUNDLER_SPEC_NO_APPEND" => "1") { expect(the_bundle).to include_gem "myrack 1.0.0" }
|
||||
|
||||
with_env_vars("BUNDLER_SPEC_NO_APPEND" => "1") { expect(the_bundle).to include_gem "myrack 1.0.0" }
|
||||
|
||||
# The first eval is from the initial install, we're testing that the
|
||||
# second install doesn't double-eval
|
||||
expect(bundled_app("evals").read.lines.to_a.size).to eq(2)
|
||||
end
|
||||
expect(bundled_app("evals").read.lines.to_a.size).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -161,7 +161,7 @@ RSpec.describe "bundle install across platforms" do
|
|||
|
||||
expect(the_bundle).to include_gems "nokogiri 1.4.2 java", "weakling 0.0.3"
|
||||
|
||||
simulate_new_machine
|
||||
pristine_system_gems :bundler
|
||||
bundle "config set --local force_ruby_platform true"
|
||||
bundle "install"
|
||||
|
||||
|
|
|
@ -51,12 +51,14 @@ RSpec.describe "global gem caching" do
|
|||
|
||||
describe "when the same gem from different sources is installed" do
|
||||
it "should use the appropriate one from the global cache" do
|
||||
bundle "config path.system true"
|
||||
|
||||
install_gemfile <<-G, artifice: "compact_index"
|
||||
source "#{source}"
|
||||
gem "myrack"
|
||||
G
|
||||
|
||||
simulate_new_machine
|
||||
pristine_system_gems :bundler
|
||||
expect(the_bundle).not_to include_gems "myrack 1.0.0"
|
||||
expect(source_global_cache("myrack-1.0.0.gem")).to exist
|
||||
# myrack 1.0.0 is not installed and it is in the global cache
|
||||
|
@ -66,7 +68,7 @@ RSpec.describe "global gem caching" do
|
|||
gem "myrack", "0.9.1"
|
||||
G
|
||||
|
||||
simulate_new_machine
|
||||
pristine_system_gems :bundler
|
||||
expect(the_bundle).not_to include_gems "myrack 0.9.1"
|
||||
expect(source2_global_cache("myrack-0.9.1.gem")).to exist
|
||||
# myrack 0.9.1 is not installed and it is in the global cache
|
||||
|
@ -80,7 +82,7 @@ RSpec.describe "global gem caching" do
|
|||
# myrack 1.0.0 is installed and myrack 0.9.1 is not
|
||||
expect(the_bundle).to include_gems "myrack 1.0.0"
|
||||
expect(the_bundle).not_to include_gems "myrack 0.9.1"
|
||||
simulate_new_machine
|
||||
pristine_system_gems :bundler
|
||||
|
||||
gemfile <<-G
|
||||
source "#{source2}"
|
||||
|
@ -94,13 +96,15 @@ RSpec.describe "global gem caching" do
|
|||
end
|
||||
|
||||
it "should not install if the wrong source is provided" do
|
||||
bundle "config path.system true"
|
||||
|
||||
gemfile <<-G
|
||||
source "#{source}"
|
||||
gem "myrack"
|
||||
G
|
||||
|
||||
bundle :install, artifice: "compact_index"
|
||||
simulate_new_machine
|
||||
pristine_system_gems :bundler
|
||||
expect(the_bundle).not_to include_gems "myrack 1.0.0"
|
||||
expect(source_global_cache("myrack-1.0.0.gem")).to exist
|
||||
# myrack 1.0.0 is not installed and it is in the global cache
|
||||
|
@ -111,7 +115,7 @@ RSpec.describe "global gem caching" do
|
|||
G
|
||||
|
||||
bundle :install, artifice: "compact_index"
|
||||
simulate_new_machine
|
||||
pristine_system_gems :bundler
|
||||
expect(the_bundle).not_to include_gems "myrack 0.9.1"
|
||||
expect(source2_global_cache("myrack-0.9.1.gem")).to exist
|
||||
# myrack 0.9.1 is not installed and it is in the global cache
|
||||
|
@ -150,6 +154,8 @@ RSpec.describe "global gem caching" do
|
|||
|
||||
describe "when installing gems from a different directory" do
|
||||
it "uses the global cache as a source" do
|
||||
bundle "config path.system true"
|
||||
|
||||
install_gemfile <<-G, artifice: "compact_index"
|
||||
source "#{source}"
|
||||
gem "myrack"
|
||||
|
@ -161,7 +167,7 @@ RSpec.describe "global gem caching" do
|
|||
expect(the_bundle).to include_gems "activesupport 2.3.5"
|
||||
expect(source_global_cache("myrack-1.0.0.gem")).to exist
|
||||
expect(source_global_cache("activesupport-2.3.5.gem")).to exist
|
||||
simulate_new_machine
|
||||
pristine_system_gems :bundler
|
||||
# Both gems are now only in the global cache
|
||||
expect(the_bundle).not_to include_gems "myrack 1.0.0"
|
||||
expect(the_bundle).not_to include_gems "activesupport 2.3.5"
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
RSpec.context "when installing a bundle that includes yanked gems" do
|
||||
before(:each) do
|
||||
it "throws an error when the original gem version is yanked" do
|
||||
build_repo4 do
|
||||
build_gem "foo", "9.0.0"
|
||||
end
|
||||
end
|
||||
|
||||
it "throws an error when the original gem version is yanked" do
|
||||
lockfile <<-L
|
||||
GEM
|
||||
remote: https://gem.repo4
|
||||
|
@ -116,6 +114,10 @@ RSpec.context "when installing a bundle that includes yanked gems" do
|
|||
end
|
||||
|
||||
it "throws the original error when only the Gemfile specifies a gem version that doesn't exist" do
|
||||
build_repo4 do
|
||||
build_gem "foo", "9.0.0"
|
||||
end
|
||||
|
||||
bundle "config set force_ruby_platform true"
|
||||
|
||||
install_gemfile <<-G, raise_on_error: false
|
||||
|
|
|
@ -458,9 +458,8 @@ RSpec.describe "Bundler.setup" do
|
|||
end
|
||||
|
||||
it "works even when the cache directory has been deleted" do
|
||||
bundle "config set --local path vendor/bundle"
|
||||
bundle :install
|
||||
FileUtils.rm_rf vendored_gems("cache")
|
||||
FileUtils.rm_rf default_cache_path
|
||||
expect(the_bundle).to include_gems "myrack 1.0.0"
|
||||
end
|
||||
|
||||
|
|
|
@ -187,32 +187,37 @@ module Spec
|
|||
end
|
||||
|
||||
def build_repo2(**kwargs, &blk)
|
||||
FileUtils.rm_rf gem_repo2
|
||||
FileUtils.cp_r gem_repo1, gem_repo2
|
||||
FileUtils.cp_r gem_repo1, gem_repo2, remove_destination: true
|
||||
update_repo2(**kwargs, &blk) if block_given?
|
||||
end
|
||||
|
||||
# A repo that has no pre-installed gems included. (The caller completely
|
||||
# determines the contents with the block.)
|
||||
def build_repo3(**kwargs, &blk)
|
||||
build_empty_repo gem_repo3, **kwargs, &blk
|
||||
raise "gem_repo3 already exists -- use update_repo3 instead" if File.exist?(gem_repo3)
|
||||
build_repo gem_repo3, **kwargs, &blk
|
||||
end
|
||||
|
||||
# Like build_repo3, this is a repo that has no pre-installed gems included.
|
||||
# We have two different methods for situations where two different empty
|
||||
# sources are needed.
|
||||
def build_repo4(**kwargs, &blk)
|
||||
build_empty_repo gem_repo4, **kwargs, &blk
|
||||
end
|
||||
|
||||
def update_repo4(&blk)
|
||||
update_repo(gem_repo4, &blk)
|
||||
raise "gem_repo4 already exists -- use update_repo4 instead" if File.exist?(gem_repo4)
|
||||
build_repo gem_repo4, **kwargs, &blk
|
||||
end
|
||||
|
||||
def update_repo2(**kwargs, &blk)
|
||||
update_repo(gem_repo2, **kwargs, &blk)
|
||||
end
|
||||
|
||||
def update_repo3(&blk)
|
||||
update_repo(gem_repo3, &blk)
|
||||
end
|
||||
|
||||
def update_repo4(&blk)
|
||||
update_repo(gem_repo4, &blk)
|
||||
end
|
||||
|
||||
def build_security_repo
|
||||
build_repo security_repo do
|
||||
build_gem "myrack"
|
||||
|
@ -273,7 +278,6 @@ module Spec
|
|||
|
||||
def check_test_gems!
|
||||
if rake_path.nil?
|
||||
FileUtils.rm_rf(base_system_gems)
|
||||
Spec::Rubygems.install_test_deps
|
||||
end
|
||||
|
||||
|
@ -352,11 +356,6 @@ module Spec
|
|||
|
||||
private
|
||||
|
||||
def build_empty_repo(gem_repo, **kwargs, &blk)
|
||||
FileUtils.rm_rf gem_repo
|
||||
build_repo(gem_repo, **kwargs, &blk)
|
||||
end
|
||||
|
||||
def build_with(builder, name, args, &blk)
|
||||
@_build_path ||= nil
|
||||
@_build_repo ||= nil
|
||||
|
|
|
@ -414,7 +414,6 @@ module Spec
|
|||
def cache_gems(*gems, gem_repo: gem_repo1)
|
||||
gems = gems.flatten
|
||||
|
||||
FileUtils.rm_rf("#{bundled_app}/vendor/cache")
|
||||
FileUtils.mkdir_p("#{bundled_app}/vendor/cache")
|
||||
|
||||
gems.each do |g|
|
||||
|
@ -549,6 +548,12 @@ module Spec
|
|||
128 + signal_number
|
||||
end
|
||||
|
||||
def empty_repo4
|
||||
FileUtils.rm_r gem_repo4
|
||||
|
||||
build_repo4 {}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def allowed_rubygems_warning?(text, extra_allowed_warning)
|
||||
|
|
|
@ -62,8 +62,7 @@ module Spec
|
|||
source = Path.tmp_root("1")
|
||||
destination = Path.tmp_root(n.to_s)
|
||||
|
||||
FileUtils.rm_rf destination
|
||||
FileUtils.cp_r source, destination
|
||||
FileUtils.cp_r source, destination, remove_destination: true
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue