Skip to content

Commit f656d34

Browse files
deivid-rodriguezhsbt
authored andcommitted
[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. ruby/rubygems@ed430883e0
1 parent c680880 commit f656d34

File tree

17 files changed

+199
-141
lines changed

17 files changed

+199
-141
lines changed

spec/bundler/cache/gems_spec.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@
291291
expect(cached_gem("platform_specific-1.0-java")).to exist
292292
end
293293

294-
simulate_new_machine
294+
pristine_system_gems :bundler
295295

296296
simulate_platform "x86-darwin-100" do
297297
install_gemfile <<-G
@@ -312,7 +312,8 @@
312312
path: cached_myrack.parent,
313313
rubygems_version: "1.3.2"
314314

315-
simulate_new_machine
315+
FileUtils.rm_rf default_bundle_path
316+
system_gems :bundler
316317

317318
FileUtils.rm bundled_app_lock
318319
bundle :install, raise_on_error: false
@@ -344,7 +345,8 @@
344345
c.checksum gem_repo1, "myrack", "1.0.0"
345346
end
346347

347-
simulate_new_machine
348+
FileUtils.rm_rf default_bundle_path
349+
system_gems :bundler
348350

349351
lockfile <<-L
350352
GEM
@@ -369,7 +371,7 @@
369371
setup_main_repo
370372
cached_gem("myrack-1.0.0").rmtree
371373
build_gem "myrack", "1.0.0", path: bundled_app("vendor/cache")
372-
simulate_new_machine
374+
pristine_system_gems :bundler
373375

374376
lockfile <<-L
375377
GEM

spec/bundler/cache/git_spec.rb

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
bundle "config set path vendor/bundle"
165165
bundle :install
166166

167-
simulate_new_machine
167+
pristine_system_gems :bundler
168168
with_path_as "" do
169169
bundle "config set deployment true"
170170
bundle "install --local"
@@ -181,10 +181,8 @@
181181
G
182182
bundle "config set cache_all true"
183183
bundle :cache, "all-platforms" => true
184-
FileUtils.rm_rf Dir.glob(default_bundle_path("bundler/gems/extensions/**/foo-1.0-*")).first.to_s
185-
FileUtils.rm_rf Dir.glob(default_bundle_path("bundler/gems/foo-1.0-*")).first.to_s
186184

187-
simulate_new_machine
185+
pristine_system_gems :bundler
188186
bundle "config set frozen true"
189187
bundle "install --local --verbose"
190188
expect(out).to_not include("Fetching")
@@ -200,12 +198,9 @@
200198
G
201199
bundle "config set cache_all true"
202200
bundle :cache, "all-platforms" => true
203-
FileUtils.rm_rf Dir.glob(default_bundle_path("bundler/gems/extensions/**/foo-1.0-*")).first.to_s
204-
FileUtils.rm_rf Dir.glob(default_bundle_path("bundler/gems/foo-1.0-*")).first.to_s
205201

206-
simulate_new_machine
202+
pristine_system_gems :bundler
207203
bundle "config set frozen true"
208-
FileUtils.rm_rf "#{default_bundle_path}/cache/bundler/git/foo-1.0-*"
209204
bundle "install --local --verbose"
210205
expect(out).to_not include("Fetching")
211206
expect(the_bundle).to include_gem "foo 1.0"
@@ -220,12 +215,9 @@
220215
G
221216
bundle "config set cache_all true"
222217
bundle :cache, "all-platforms" => true
223-
FileUtils.rm_rf Dir.glob(default_bundle_path("bundler/gems/extensions/**/foo-1.0-*")).first.to_s
224-
FileUtils.rm_rf Dir.glob(default_bundle_path("bundler/gems/foo-1.0-*")).first.to_s
225218

226-
simulate_new_machine
219+
pristine_system_gems :bundler
227220
bundle "config set frozen true"
228-
FileUtils.rm_rf "#{default_bundle_path}/cache/bundler/git/foo-1.0-*"
229221

230222
# Remove untracked files (including the empty refs dir in the cache)
231223
Dir.chdir(bundled_app) do
@@ -388,7 +380,7 @@
388380
bundle "config set cache_all true"
389381
bundle :cache, "all-platforms" => true, :install => false
390382

391-
simulate_new_machine
383+
pristine_system_gems :bundler
392384
with_path_as "" do
393385
bundle "config set deployment true"
394386
bundle :install, local: true

spec/bundler/commands/cache_spec.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@
356356
G
357357

358358
bundle :cache
359-
simulate_new_machine
359+
pristine_system_gems :bundler
360360
FileUtils.rm_rf gem_repo2
361361

362362
bundle "install --local"
@@ -371,7 +371,7 @@
371371
G
372372

373373
bundle :cache
374-
simulate_new_machine
374+
pristine_system_gems :bundler
375375
FileUtils.rm_rf gem_repo2
376376

377377
bundle "config set --local deployment true"
@@ -388,7 +388,7 @@
388388
G
389389

390390
bundle :cache
391-
simulate_new_machine
391+
pristine_system_gems :bundler
392392
FileUtils.rm_rf gem_repo2
393393

394394
bundle "config set --local cache_all_platforms true"
@@ -445,9 +445,8 @@
445445
bundle "config set path vendor/bundle"
446446
bundle :cache, artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s }
447447

448-
build_repo4 do
449-
# simulate removal of all remote gems
450-
end
448+
# simulate removal of all remote gems
449+
empty_repo4
451450

452451
# delete compact index cache
453452
FileUtils.rm_rf home(".bundle/cache/compact_index")
@@ -483,7 +482,7 @@
483482
bundle :cache
484483
end
485484

486-
simulate_new_machine
485+
pristine_system_gems :bundler
487486

488487
bundle "config set --local force_ruby_platform true"
489488

spec/bundler/commands/check_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@
328328
end
329329

330330
it "shows what is missing with the current Gemfile if it is not satisfied" do
331-
simulate_new_machine
331+
FileUtils.rm_rf default_bundle_path
332+
system_gems :bundler
332333
bundle :check, raise_on_error: false
333334
expect(err).to match(/The following gems are missing/)
334335
expect(err).to include("* myrack (1.0")

spec/bundler/commands/install_spec.rb

Lines changed: 64 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,88 +1550,94 @@ def run
15501550
end
15511551

15521552
context "with --prefer-local flag" do
1553-
before do
1554-
build_repo4 do
1555-
build_gem "foo", "1.0.1"
1556-
build_gem "foo", "1.0.0"
1557-
build_gem "bar", "1.0.0"
1553+
context "and gems available locally" do
1554+
before do
1555+
build_repo4 do
1556+
build_gem "foo", "1.0.1"
1557+
build_gem "foo", "1.0.0"
1558+
build_gem "bar", "1.0.0"
15581559

1559-
build_gem "a", "1.0.0" do |s|
1560-
s.add_dependency "foo", "~> 1.0.0"
1561-
end
1560+
build_gem "a", "1.0.0" do |s|
1561+
s.add_dependency "foo", "~> 1.0.0"
1562+
end
15621563

1563-
build_gem "b", "1.0.0" do |s|
1564-
s.add_dependency "foo", "~> 1.0.1"
1564+
build_gem "b", "1.0.0" do |s|
1565+
s.add_dependency "foo", "~> 1.0.1"
1566+
end
15651567
end
1568+
1569+
system_gems "foo-1.0.0", path: default_bundle_path, gem_repo: gem_repo4
15661570
end
15671571

1568-
system_gems "foo-1.0.0", path: default_bundle_path, gem_repo: gem_repo4
1569-
end
1572+
it "fetches remote sources when not available locally" do
1573+
install_gemfile <<-G, "prefer-local": true, verbose: true
1574+
source "https://gem.repo4"
15701575
1571-
it "fetches remote sources when not available locally" do
1572-
install_gemfile <<-G, "prefer-local": true, verbose: true
1573-
source "https://gem.repo4"
1574-
1575-
gem "foo"
1576-
gem "bar"
1577-
G
1576+
gem "foo"
1577+
gem "bar"
1578+
G
15781579

1579-
expect(out).to include("Using foo 1.0.0").and include("Fetching bar 1.0.0").and include("Installing bar 1.0.0")
1580-
expect(last_command).to be_success
1581-
end
1580+
expect(out).to include("Using foo 1.0.0").and include("Fetching bar 1.0.0").and include("Installing bar 1.0.0")
1581+
expect(last_command).to be_success
1582+
end
15821583

1583-
it "fetches remote sources when local version does not match requirements" do
1584-
install_gemfile <<-G, "prefer-local": true, verbose: true
1585-
source "https://gem.repo4"
1584+
it "fetches remote sources when local version does not match requirements" do
1585+
install_gemfile <<-G, "prefer-local": true, verbose: true
1586+
source "https://gem.repo4"
15861587
1587-
gem "foo", "1.0.1"
1588-
gem "bar"
1589-
G
1588+
gem "foo", "1.0.1"
1589+
gem "bar"
1590+
G
15901591

1591-
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")
1592-
expect(last_command).to be_success
1593-
end
1592+
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")
1593+
expect(last_command).to be_success
1594+
end
15941595

1595-
it "uses the locally available version for sub-dependencies when possible" do
1596-
install_gemfile <<-G, "prefer-local": true, verbose: true
1597-
source "https://gem.repo4"
1596+
it "uses the locally available version for sub-dependencies when possible" do
1597+
install_gemfile <<-G, "prefer-local": true, verbose: true
1598+
source "https://gem.repo4"
15981599
1599-
gem "a"
1600-
G
1600+
gem "a"
1601+
G
16011602

1602-
expect(out).to include("Using foo 1.0.0").and include("Fetching a 1.0.0").and include("Installing a 1.0.0")
1603-
expect(last_command).to be_success
1604-
end
1603+
expect(out).to include("Using foo 1.0.0").and include("Fetching a 1.0.0").and include("Installing a 1.0.0")
1604+
expect(last_command).to be_success
1605+
end
16051606

1606-
it "fetches remote sources for sub-dependencies when the locally available version does not satisfy the requirement" do
1607-
install_gemfile <<-G, "prefer-local": true, verbose: true
1608-
source "https://gem.repo4"
1607+
it "fetches remote sources for sub-dependencies when the locally available version does not satisfy the requirement" do
1608+
install_gemfile <<-G, "prefer-local": true, verbose: true
1609+
source "https://gem.repo4"
16091610
1610-
gem "b"
1611-
G
1611+
gem "b"
1612+
G
16121613

1613-
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")
1614-
expect(last_command).to be_success
1614+
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")
1615+
expect(last_command).to be_success
1616+
end
16151617
end
16161618

1617-
it "resolves to the latest version if no gems are available locally" do
1618-
build_repo4 do
1619-
build_gem "myreline", "0.3.8"
1620-
build_gem "debug", "0.2.1"
1619+
context "and no gems available locally" do
1620+
before do
1621+
build_repo4 do
1622+
build_gem "myreline", "0.3.8"
1623+
build_gem "debug", "0.2.1"
16211624

1622-
build_gem "debug", "1.10.0" do |s|
1623-
s.add_dependency "myreline"
1625+
build_gem "debug", "1.10.0" do |s|
1626+
s.add_dependency "myreline"
1627+
end
16241628
end
16251629
end
16261630

1627-
install_gemfile <<~G, "prefer-local": true, verbose: true
1628-
source "https://gem.repo4"
1631+
it "resolves to the latest version if no gems are available locally" do
1632+
install_gemfile <<~G, "prefer-local": true, verbose: true
1633+
source "https://gem.repo4"
16291634
1630-
gem "debug"
1631-
G
1635+
gem "debug"
1636+
G
16321637

1633-
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")
1634-
expect(last_command).to be_success
1638+
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")
1639+
expect(last_command).to be_success
1640+
end
16351641
end
16361642
end
16371643

0 commit comments

Comments
 (0)