utils/git_spec: Add a test for last_revision_commit_of_files
- This method, called from `brew extract` in the case of extraction from third-party taps, was untested. This led to it breaking when we refactored some of it to appease Sorbet (see PR 7933). If I make the same (flawed) change here and run these tests, they fail. - There's a fair bit going on here, but most of it is setup for committing changes to more files, as we're testing operations on multiple files in a Homebrew repo. - I originally tried to write tests for `brew extract`, but that required _a lot_ of refactoring because those tests (and their helper methods) aren't designed for third-party taps - they rely on `CoreTap`. So testing the underlying method is a better solution.
This commit is contained in:
parent
e9932a601f
commit
981726c088
@ -9,35 +9,67 @@ describe Git do
|
||||
HOMEBREW_CACHE.cd do
|
||||
system git, "init"
|
||||
|
||||
File.open(file, "w") { |f| f.write("blah") }
|
||||
system git, "add", HOMEBREW_CACHE/file
|
||||
File.open("blah.rb", "w") { |f| f.write("blah") }
|
||||
system git, "add", HOMEBREW_CACHE/"blah.rb"
|
||||
system git, "commit", "-m", "'File added'"
|
||||
@h1 = `git rev-parse HEAD`
|
||||
|
||||
File.open(file, "w") { |f| f.write("brew") }
|
||||
system git, "add", HOMEBREW_CACHE/file
|
||||
File.open("blah.rb", "w") { |f| f.write("brew") }
|
||||
system git, "add", HOMEBREW_CACHE/"blah.rb"
|
||||
system git, "commit", "-m", "'written to File'"
|
||||
@h2 = `git rev-parse HEAD`
|
||||
|
||||
File.open("bleh.rb", "w") { |f| f.write("bleh") }
|
||||
system git, "add", HOMEBREW_CACHE/"bleh.rb"
|
||||
system git, "commit", "-m", "'File added'"
|
||||
@h3 = `git rev-parse HEAD`
|
||||
|
||||
File.open("bleh.rb", "w") { |f| f.write("blehbleh") }
|
||||
system git, "add", HOMEBREW_CACHE/"bleh.rb"
|
||||
system git, "commit", "-m", "'written to File'"
|
||||
end
|
||||
end
|
||||
|
||||
let(:file) { "blah.rb" }
|
||||
let(:hash1) { @h1[0..6] }
|
||||
let(:hash2) { @h2[0..6] }
|
||||
let(:file_hash1) { @h1[0..6] }
|
||||
let(:file_hash2) { @h2[0..6] }
|
||||
let(:files) { ["blah.rb", "bleh.rb"] }
|
||||
let(:files_hash1) { [@h3[0..6], ["bleh.rb"]] }
|
||||
let(:files_hash2) { [@h2[0..6], ["blah.rb"]] }
|
||||
|
||||
describe "#last_revision_commit_of_file" do
|
||||
it "gives last revision commit when before_commit is nil" do
|
||||
expect(
|
||||
described_class.last_revision_commit_of_file(HOMEBREW_CACHE, file),
|
||||
).to eq(hash1)
|
||||
).to eq(file_hash1)
|
||||
end
|
||||
|
||||
it "gives revision commit based on before_commit when it is not nil" do
|
||||
expect(
|
||||
described_class.last_revision_commit_of_file(HOMEBREW_CACHE,
|
||||
file,
|
||||
before_commit: hash2),
|
||||
).to eq(hash2)
|
||||
before_commit: file_hash2),
|
||||
).to eq(file_hash2)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#last_revision_commit_of_files" do
|
||||
context "when before_commit is nil" do
|
||||
it "gives last revision commit" do
|
||||
expect(
|
||||
described_class.last_revision_commit_of_files(HOMEBREW_CACHE, files),
|
||||
).to eq(files_hash1)
|
||||
end
|
||||
end
|
||||
|
||||
context "when before_commit is not nil" do
|
||||
it "gives last revision commit" do
|
||||
expect(
|
||||
described_class.last_revision_commit_of_files(HOMEBREW_CACHE,
|
||||
files,
|
||||
before_commit: file_hash2),
|
||||
).to eq(files_hash2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user