aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/utils/git_spec.rb
blob: d4eb978200533546bbed23dc412cd5aaa7c26fb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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