Removed shutup

This commit is contained in:
mansimarkaur 2017-08-01 22:27:24 +05:30
parent 4f0f55a774
commit abe78ebb8e

View File

@ -5,50 +5,71 @@ describe Git do
git = HOMEBREW_SHIMS_PATH/"scm/git" git = HOMEBREW_SHIMS_PATH/"scm/git"
file = "lib/blah.rb" file = "lib/blah.rb"
repo = Pathname.new("repo") repo = Pathname.new("repo")
FileUtils.mkpath("repo/lib")
shutup do (repo/"lib").mkpath
system "#{git} init" system git, "init"
FileUtils.touch("repo/#{file}") FileUtils.touch("repo/#{file}")
File.open(repo.join("file").to_s, "w") { |f| f.write("blah") }
system "#{git} add repo/#{file}" File.open(repo/file, "w") { |f| f.write("blah") }
system "#{git} commit -m'File added'" system git, "add", repo/file
@hash1 = `git rev-parse HEAD` system git, "commit", "-m", "'File added'"
File.open(repo.join("file").to_s, "w") { |f| f.write("brew") } @h1 = `git rev-parse HEAD`
system "#{git} add repo/#{file}"
system "#{git} commit -m'written to File'" File.open(repo/file, "w") { |f| f.write("brew") }
@hash2 = `git rev-parse HEAD` system git, "add", repo/file
end system git, "commit", "-m", "'written to File'"
@h2 = `git rev-parse HEAD`
end end
let(:file) { "lib/blah.rb" } let(:file) { "lib/blah.rb" }
let(:repo) { Pathname.new("repo") } let(:repo) { Pathname.new("repo") }
let(:hash1) { @h1[0..6] }
let(:hash2) { @h2[0..6] }
after(:all) do after(:all) do
FileUtils.rm_rf("repo") FileUtils.rm_rf("repo")
end end
describe "#last_revision_commit_of_file" do describe "#last_revision_commit_of_file" do
it "sets args as --skip=1 when before_commit is nil" do it "gives last revision commit when before_commit is nil" do
expect(described_class.last_revision_commit_of_file(repo, file)).to eq(@hash1[0..6]) expect(
described_class.last_revision_commit_of_file(repo, file),
).to eq(hash1)
end end
it "sets args as --skip=1 when before_commit is nil" do it "gives revision commit based on before_commit when it is not nil" do
expect(described_class.last_revision_commit_of_file(repo, file, before_commit: "0..3")).to eq(@hash2[0..6]) expect(
described_class.last_revision_commit_of_file(repo,
file,
before_commit: "0..3"),
).to eq(hash2)
end end
end end
describe "#last_revision_of_file" do describe "#last_revision_of_file" do
it "returns last revision of file" do it "returns last revision of file" do
expect(described_class.last_revision_of_file(repo, repo.join("file").to_s)).to eq("blah") expect(
described_class.last_revision_of_file(repo,
repo/file),
).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(described_class.last_revision_of_file(repo, repo.join("file").to_s, before_commit: "0..3")).to eq("brew") expect(
described_class.last_revision_of_file(repo, repo/file,
before_commit: "0..3"),
).to eq("brew")
end end
end end
end end
describe Utils do describe Utils do
before(:each) do
if described_class.instance_variable_defined?(:@git)
described_class.send(:remove_instance_variable, :@git)
end
end
describe "::git_available?" do describe "::git_available?" do
it "returns true if git --version command succeeds" do it "returns true if git --version command succeeds" do
allow_any_instance_of(Process::Status).to receive(:success?).and_return(true) allow_any_instance_of(Process::Status).to receive(:success?).and_return(true)
@ -73,7 +94,7 @@ describe Utils do
described_class.instance_variable_set(:@git, false) described_class.instance_variable_set(:@git, false)
end end
it "returns" do it "returns nil" do
expect(described_class.git_path).to eq(nil) expect(described_class.git_path).to eq(nil)
end end
end end
@ -84,8 +105,7 @@ describe Utils do
end end
it "returns path of git" do it "returns path of git" do
allow(Utils).to receive(popen_read).with(HOMEBREW_SHIMS_PATH/"scm/git", "--homebrew=print-path").and_return("git") expect(described_class.git_path).to end_with("git")
expect(described_class.git_path).to eq("git")
end end
it "returns git_path if already set" do it "returns git_path if already set" do
@ -138,23 +158,27 @@ describe Utils do
context "when git is available" do context "when git is available" do
before(:all) do before(:all) do
described_class.instance_variable_set(:@git, true) described_class.instance_variable_set(:@git, true)
git = HOMEBREW_SHIMS_PATH/"scm/git"
@repo = Pathname.new("hey")
FileUtils.mkpath("hey")
shutup do
system "cd #{@repo}"
system "#{git} init"
system "#{git} remote add origin git@github.com:Homebrew/brew"
system "cd .."
end
end end
after(:all) do after(:all) do
FileUtils.rm_rf(@repo) if described_class.instance_variable_defined?(:@git)
described_class.send(:remove_instance_variable, :@git)
end
end end
it "returns true when git remote exists" do it "returns true when git remote exists", :needs_network do
git = HOMEBREW_SHIMS_PATH/"scm/git"
repo = Pathname.new("hey")
repo.mkpath
system "cd", repo
system git, "init"
system git, "remote", "add", "origin", "git@github.com:Homebrew/brew"
system "cd .."
expect(described_class.git_remote_exists("git@github.com:Homebrew/brew")).to be_truthy expect(described_class.git_remote_exists("git@github.com:Homebrew/brew")).to be_truthy
FileUtils.rm_rf(repo)
end end
it "returns false when git remote does not exist" do it "returns false when git remote does not exist" do
@ -166,16 +190,25 @@ describe Utils do
describe "::clear_git_available_cache" do describe "::clear_git_available_cache" do
it "removes @git_path and @git_version if defined" do it "removes @git_path and @git_version if defined" do
described_class.clear_git_available_cache described_class.clear_git_available_cache
expect(@git_path).to be_nil expect(@git_path).to be_nil
expect(@git_version).to be_nil expect(@git_version).to be_nil
end end
it "removes @git if defined" do it "removes @git if defined" do
described_class.instance_variable_set(:@git, true) described_class.instance_variable_set(:@git, true)
described_class.clear_git_available_cache
expect(@git).to be_nil begin
expect(@git_path).to be_nil described_class.clear_git_available_cache
expect(@git_version).to be_nil
expect(@git).to be_nil
expect(@git_path).to be_nil
expect(@git_version).to be_nil
ensure
if described_class.instance_variable_defined?(:@git)
described_class.send(:remove_instance_variable, :@git)
end
end
end end
end end
end end