aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test
diff options
context:
space:
mode:
authormansimarkaur2017-07-28 00:37:32 +0530
committermansimarkaur2017-08-27 01:23:32 +0530
commitd91036e8912b31e3eb145b1cb3964a321a587c4f (patch)
tree96e55ed4a4fac27d24af276b3945372f441e933b /Library/Homebrew/test
parent551e5dd94578062e0ab42bc56e0fdd106807839b (diff)
downloadbrew-d91036e8912b31e3eb145b1cb3964a321a587c4f.tar.bz2
Added tests for last_revision_commit_of_file
Diffstat (limited to 'Library/Homebrew/test')
-rw-r--r--Library/Homebrew/test/utils/git_spec.rb47
1 files changed, 47 insertions, 0 deletions
diff --git a/Library/Homebrew/test/utils/git_spec.rb b/Library/Homebrew/test/utils/git_spec.rb
new file mode 100644
index 000000000..d4eb97820
--- /dev/null
+++ b/Library/Homebrew/test/utils/git_spec.rb
@@ -0,0 +1,47 @@
+require "utils/git"
+
+describe Git do
+ before(:all) do
+ git = HOMEBREW_SHIMS_PATH/"scm/git"
+ file = "lib/blah.rb"
+ repo = Pathname.new("repo")
+ FileUtils.mkpath("repo/lib")
+ `#{git} init`
+ FileUtils.touch("repo/#{file}")
+ File.open(repo.to_s+"/"+file, "w") { |f| f.write("blah") }
+ `#{git} add repo/#{file}`
+ `#{git} commit -m"File added"`
+ @hash1 = `git rev-parse HEAD`
+ File.open(repo.to_s+"/"+file, "w") { |f| f.write("brew") }
+ `#{git} add repo/#{file}`
+ `#{git} commit -m"written to File"`
+ @hash2 = `git rev-parse HEAD`
+ end
+
+ let(:file) { "lib/blah.rb" }
+ let(:repo) { Pathname.new("repo") }
+
+ # after(:all) do
+ # FileUtils.rm_rf("repo")
+ # end
+
+ describe "#last_revision_commit_of_file" do
+ it "sets args as --skip=1 when before_commit is nil" do
+ expect(described_class.last_revision_commit_of_file(repo, file)).to eq(@hash1[0..6])
+ end
+
+ it "sets args as --skip=1 when before_commit is nil" do
+ expect(described_class.last_revision_commit_of_file(repo, file, before_commit: "0..3")).to eq(@hash2[0..6])
+ end
+ end
+
+ describe "#last_revision_of_file" do
+ it "returns last revision of file" do
+ expect(described_class.last_revision_of_file(repo, repo.to_s+"/"+file)).to eq("blah")
+ end
+
+ it "returns last revision of file based on before_commit" do
+ expect(described_class.last_revision_of_file(repo, repo.to_s+"/"+file, before_commit: "0..3")).to eq("brew")
+ end
+ end
+end