Merge pull request #7997 from issyl0/git-test-last_revision_commit_of_files
utils/git_spec: Add a test for `last_revision_commit_of_files`
This commit is contained in:
commit
47826fd01d
@ -9,35 +9,67 @@ describe Git do
|
|||||||
HOMEBREW_CACHE.cd do
|
HOMEBREW_CACHE.cd do
|
||||||
system git, "init"
|
system git, "init"
|
||||||
|
|
||||||
File.open(file, "w") { |f| f.write("blah") }
|
File.open("README.md", "w") { |f| f.write("README") }
|
||||||
system git, "add", HOMEBREW_CACHE/file
|
system git, "add", HOMEBREW_CACHE/"README.md"
|
||||||
system git, "commit", "-m", "'File added'"
|
system git, "commit", "-m", "'File added'"
|
||||||
@h1 = `git rev-parse HEAD`
|
@h1 = `git rev-parse HEAD`
|
||||||
|
|
||||||
File.open(file, "w") { |f| f.write("brew") }
|
File.open("README.md", "w") { |f| f.write("# README") }
|
||||||
system git, "add", HOMEBREW_CACHE/file
|
system git, "add", HOMEBREW_CACHE/"README.md"
|
||||||
system git, "commit", "-m", "'written to File'"
|
system git, "commit", "-m", "'written to File'"
|
||||||
@h2 = `git rev-parse HEAD`
|
@h2 = `git rev-parse HEAD`
|
||||||
|
|
||||||
|
File.open("LICENSE.txt", "w") { |f| f.write("LICENCE") }
|
||||||
|
system git, "add", HOMEBREW_CACHE/"LICENSE.txt"
|
||||||
|
system git, "commit", "-m", "'File added'"
|
||||||
|
@h3 = `git rev-parse HEAD`
|
||||||
|
|
||||||
|
File.open("LICENSE.txt", "w") { |f| f.write("LICENSE") }
|
||||||
|
system git, "add", HOMEBREW_CACHE/"LICENSE.txt"
|
||||||
|
system git, "commit", "-m", "'written to File'"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:file) { "blah.rb" }
|
let(:file) { "README.md" }
|
||||||
let(:hash1) { @h1[0..6] }
|
let(:file_hash1) { @h1[0..6] }
|
||||||
let(:hash2) { @h2[0..6] }
|
let(:file_hash2) { @h2[0..6] }
|
||||||
|
let(:files) { ["README.md", "LICENSE.txt"] }
|
||||||
|
let(:files_hash1) { [@h3[0..6], ["LICENSE.txt"]] }
|
||||||
|
let(:files_hash2) { [@h2[0..6], ["README.md"]] }
|
||||||
|
|
||||||
describe "#last_revision_commit_of_file" do
|
describe "#last_revision_commit_of_file" do
|
||||||
it "gives last revision commit when before_commit is nil" do
|
it "gives last revision commit when before_commit is nil" do
|
||||||
expect(
|
expect(
|
||||||
described_class.last_revision_commit_of_file(HOMEBREW_CACHE, file),
|
described_class.last_revision_commit_of_file(HOMEBREW_CACHE, file),
|
||||||
).to eq(hash1)
|
).to eq(file_hash1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "gives revision commit based on before_commit when it is not nil" do
|
it "gives revision commit based on before_commit when it is not nil" do
|
||||||
expect(
|
expect(
|
||||||
described_class.last_revision_commit_of_file(HOMEBREW_CACHE,
|
described_class.last_revision_commit_of_file(HOMEBREW_CACHE,
|
||||||
file,
|
file,
|
||||||
before_commit: hash2),
|
before_commit: file_hash2),
|
||||||
).to eq(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
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -46,14 +78,14 @@ describe Git do
|
|||||||
expect(
|
expect(
|
||||||
described_class.last_revision_of_file(HOMEBREW_CACHE,
|
described_class.last_revision_of_file(HOMEBREW_CACHE,
|
||||||
HOMEBREW_CACHE/file),
|
HOMEBREW_CACHE/file),
|
||||||
).to eq("blah")
|
).to eq("README")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns last revision of file based on before_commit" do
|
it "returns last revision of file based on before_commit" do
|
||||||
expect(
|
expect(
|
||||||
described_class.last_revision_of_file(HOMEBREW_CACHE, HOMEBREW_CACHE/file,
|
described_class.last_revision_of_file(HOMEBREW_CACHE, HOMEBREW_CACHE/file,
|
||||||
before_commit: "0..3"),
|
before_commit: "0..3"),
|
||||||
).to eq("brew")
|
).to eq("# README")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user