Used already existing clear_git_available_cache to remove @git

This commit is contained in:
mansimarkaur 2017-08-25 17:55:54 +05:30
parent c695dffd37
commit 784250d550
2 changed files with 10 additions and 31 deletions

View File

@ -4,37 +4,36 @@ describe Git do
before(:each) do before(:each) do
git = HOMEBREW_SHIMS_PATH/"scm/git" git = HOMEBREW_SHIMS_PATH/"scm/git"
@file = "blah.rb"
HOMEBREW_CACHE.cd do HOMEBREW_CACHE.cd do
system git, "init" system git, "init"
File.open(@file, "w") { |f| f.write("blah") } File.open(file, "w") { |f| f.write("blah") }
system git, "add", HOMEBREW_CACHE/@file system git, "add", HOMEBREW_CACHE/file
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(file, "w") { |f| f.write("brew") }
system git, "add", HOMEBREW_CACHE/@file system git, "add", HOMEBREW_CACHE/file
system git, "commit", "-m", "'written to File'" system git, "commit", "-m", "'written to File'"
@h2 = `git rev-parse HEAD` @h2 = `git rev-parse HEAD`
end end
end end
let(:file) { "blah.rb" }
let(:hash1) { @h1[0..6] } let(:hash1) { @h1[0..6] }
let(:hash2) { @h2[0..6] } let(:hash2) { @h2[0..6] }
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(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: hash2),
).to eq(hash2) ).to eq(hash2)
end end
@ -44,13 +43,13 @@ describe Git do
it "returns last revision of file" do it "returns last revision of file" 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("blah")
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("brew")
end end
@ -59,7 +58,7 @@ end
describe Utils do describe Utils do
before(:each) do before(:each) do
described_class.clear_git_version_cache described_class.clear_git_available_cache
end end
describe "::git_available?" do describe "::git_available?" do
@ -148,20 +147,4 @@ describe Utils do
end end
end end
end end
describe "::clear_git_available_cache" do
it "removes @git_path and @git_version if defined" do
described_class.clear_git_available_cache
expect(described_class.instance_variable_get(:@git_path)).to be_nil
expect(described_class.instance_variable_get(:@git_version)).to be_nil
end
it "removes @git if defined" do
described_class.git_available?
described_class.clear_git_available_cache
expect(described_class.instance_variable_get(:@git)).to be_nil
end
end
end end

View File

@ -26,10 +26,6 @@ module Git
end end
module Utils module Utils
def self.clear_git_version_cache
remove_instance_variable(:@git) if instance_variable_defined?(:@git)
end
def self.git_available? def self.git_available?
return @git if instance_variable_defined?(:@git) return @git if instance_variable_defined?(:@git)
@git = quiet_system HOMEBREW_SHIMS_PATH/"scm/git", "--version" @git = quiet_system HOMEBREW_SHIMS_PATH/"scm/git", "--version"