Skip to content

Commit 290d5f5

Browse files
committed
Add test for file updater vendoring
1 parent 0af9bb8 commit 290d5f5

File tree

9 files changed

+113
-2
lines changed

9 files changed

+113
-2
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
/tmp
55
/pkg
66
/dependabot-*.gem
7+
!bundler/spec/fixtures/projects/**/Gemfile.lock
78
Gemfile.lock
89
vendor
10+
!bundler/spec/fixtures/vendored_gems/vendor
911
.DS_Store
1012
*.pyc
1113
*git.store
@@ -19,4 +21,4 @@ vendor
1921
/npm_and_yarn/helpers/install-dir
2022
/dry-run
2123
**/bin/helper
22-
/.core-bash_history
24+
/.core-bash_history

bundler/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
/tmp
44
/dependabot-*.gem
55
Gemfile.lock
6+
!spec/fixtures/projects/**/Gemfile.lock
7+
!spec/fixtures/projects/**/vendor

bundler/spec/dependabot/bundler/file_updater_spec.rb

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
credentials: [{
2020
"type" => "git_source",
2121
"host" => "github.com"
22-
}]
22+
}],
23+
repo_contents_path: repo_contents_path
2324
)
2425
end
2526
let(:dependencies) { [dependency] }
@@ -63,6 +64,7 @@
6364
[{ file: "Gemfile", requirement: "~> 1.4.0", groups: [], source: nil }]
6465
end
6566
let(:tmp_path) { Dependabot::SharedHelpers::BUMP_TMP_DIR_PATH }
67+
let(:repo_contents_path) { nil }
6668

6769
before { Dir.mkdir(tmp_path) unless Dir.exist?(tmp_path) }
6870

@@ -1540,5 +1542,48 @@
15401542
expect { updater }.to raise_error(/Gemfile must be provided/)
15411543
end
15421544
end
1545+
1546+
context "vendoring" do
1547+
let(:repo_contents_path) { build_tmp_repo("vendored_gems") }
1548+
1549+
before do
1550+
stub_request(:get, "https://rubygems.org/gems/business-1.5.0.gem").
1551+
to_return(
1552+
status: 200,
1553+
body: fixture("ruby", "gems", "business-1.5.0.gem")
1554+
)
1555+
end
1556+
1557+
after do
1558+
FileUtils.remove_entry repo_contents_path
1559+
end
1560+
1561+
it "vendors the new dependency" do
1562+
expect(updater.updated_dependency_files.map(&:name)).to match_array(
1563+
[
1564+
"vendor/cache/business-1.4.0.gem",
1565+
"vendor/cache/business-1.5.0.gem",
1566+
"Gemfile",
1567+
"Gemfile.lock"
1568+
]
1569+
)
1570+
end
1571+
1572+
it "base64 encodes vendored gems" do
1573+
file = updater.updated_dependency_files.find do |f|
1574+
f.name == "vendor/cache/business-1.5.0.gem"
1575+
end
1576+
1577+
expect(file.content_encoding).to eq("base64")
1578+
end
1579+
1580+
it "deletes the old vendored gem" do
1581+
file = updater.updated_dependency_files.find do |f|
1582+
f.name == "vendor/cache/business-1.4.0.gem"
1583+
end
1584+
1585+
expect(file.deleted?).to eq true
1586+
end
1587+
end
15431588
end
15441589
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
gem "business", "~> 1.4.0"
6+
gem "statesman", "~> 1.2.0"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
business (1.4.0)
5+
statesman (1.2.1)
6+
7+
PLATFORMS
8+
ruby
9+
10+
DEPENDENCIES
11+
business (~> 1.4.0)
12+
statesman (~> 1.2.0)
13+
14+
BUNDLED WITH
15+
1.10.6
Binary file not shown.
Binary file not shown.
Binary file not shown.

common/spec/spec_helper.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,47 @@ def fixture(*name)
3636
File.read(File.join("spec", "fixtures", File.join(*name)))
3737
end
3838

39+
# Creates a temporary directory and copies in any files from the specified
40+
# project path. The project path will typically contain a dependency file and a
41+
# lockfile, but it may also include a vendor directory. A git repo will be
42+
# initialized in the tmp directory.
43+
#
44+
# @param project [String] the project directory, located in
45+
# "spec/fixtures/projects"
46+
# @return [String] the path to the new temp repo.
47+
def build_tmp_repo(project)
48+
project_path = File.expand_path(File.join("spec/fixtures/projects", project))
49+
50+
tmp_dir = Dependabot::SharedHelpers::BUMP_TMP_DIR_PATH
51+
prefix = Dependabot::SharedHelpers::BUMP_TMP_FILE_PREFIX
52+
Dir.mkdir(tmp_dir) unless Dir.exist?(tmp_dir)
53+
dir = Dir.mktmpdir(prefix, tmp_dir)
54+
path = Pathname.new(dir).expand_path
55+
FileUtils.mkpath(path)
56+
57+
FileUtils.cp_r("#{project_path}/.", path)
58+
59+
Dir.chdir(path) do
60+
Dependabot::SharedHelpers.run_shell_command(
61+
<<~CMD
62+
git config --global user.name || \
63+
git config --global user.email no-reply@github.com
64+
CMD
65+
)
66+
Dependabot::SharedHelpers.run_shell_command(
67+
<<~CMD
68+
git config --global user.name || \
69+
git config --global user.name dependabot-ci
70+
CMD
71+
)
72+
Dependabot::SharedHelpers.run_shell_command("git init")
73+
Dependabot::SharedHelpers.run_shell_command("git add --all")
74+
Dependabot::SharedHelpers.run_shell_command("git commit -m 'Init'")
75+
end
76+
77+
path
78+
end
79+
3980
def capture_stderr
4081
previous_stderr = $stderr
4182
$stderr = StringIO.new

0 commit comments

Comments
 (0)