spec/unit/git/alternates_spec.rb in r10k-2.0.3 vs spec/unit/git/alternates_spec.rb in r10k-2.1.0
- old
+ new
@@ -15,11 +15,11 @@
expect(subject.file).to receive(:readlines).and_return([
"/var/cache/r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git\n",
"/vagrant/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git\n",
])
- expect(subject.to_a).to eq([
+ expect(subject.read).to eq([
"/var/cache/r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git",
"/vagrant/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git",
])
end
@@ -45,15 +45,16 @@
it "is false if the element is not in the array of read entries" do
expect(subject).to_not include("/tmp/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git")
end
end
- describe "appending a new alternate object entry" do
+
+ describe "writing alternate entries" do
describe "and the git objects/info directory does not exist" do
it "raises an error when the parent directory does not exist" do
expect {
- subject << "/tmp/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git"
+ subject.write(["/tmp/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git"])
}.to raise_error(R10K::Git::GitError,"Cannot write /some/nonexistent/path/.git/objects/info/alternates; parent directory does not exist")
end
end
describe "and the git objects/info directory exists" do
@@ -62,29 +63,54 @@
before do
expect(subject.file).to receive(:open).with('w').and_yield(io)
expect(subject.file).to receive_message_chain(:parent, :directory?).and_return true
end
-
it "creates the alternates file with the new entry when not present" do
- expect(subject).to receive(:to_a).and_return([])
- subject << "/tmp/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git"
-
+ subject.write(["/tmp/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git"])
expect(io.string).to eq("/tmp/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git\n")
end
it "rewrites the file with all alternate entries" do
- expect(subject).to receive(:to_a).and_return([
- "/var/cache/r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git",
- "/vagrant/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git",
- ])
- subject << "/tmp/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git"
+ subject.write(["/var/cache/r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git",
+ "/vagrant/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git",
+ "/tmp/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git"])
expect(io.string).to eq(<<-EOD)
/var/cache/r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git
/vagrant/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git
/tmp/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git
EOD
end
+ end
+
+ describe "appending a new alternate object entry" do
+ it "re-writes the file with the new entry concatenated to the file" do
+ expect(subject).to receive(:to_a).and_return(["/var/cache/r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git",
+ "/vagrant/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git"])
+
+ expect(subject).to receive(:write).with(["/var/cache/r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git",
+ "/vagrant/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git",
+ "/tmp/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git"])
+
+ subject.add("/tmp/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git")
+ end
+ end
+ end
+
+ describe "conditionally appending a new alternate object entry" do
+ before do
+ expect(subject).to receive(:read).and_return(%w[/var/cache/r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git])
+ end
+
+ it "adds the entry and returns true when the entry doesn't exist" do
+ expect(subject).to receive(:write).with(["/var/cache/r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git",
+ "/tmp/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git"])
+ expect(subject.add?("/tmp/.r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git")).to eq true
+ end
+
+ it "doesn't modify the file and returns false when the entry exists" do
+ expect(subject).to_not receive(:write)
+ expect(subject.add?("/var/cache/r10k/git/git---github.com-puppetlabs-puppetlabs-apache.git")).to eq false
end
end
end