require File.dirname(__FILE__) + "/spec_helper" require "piston/repository" require "fileutils" describe Piston::Repository do it "should raise an ArgumentError is instantiated without a URL" do lambda { Piston::Repository.new }.should raise_error(ArgumentError) end it "should raise an ArgumentError is instantiated with nil as the URL" do lambda { Piston::Repository.new(nil) }.should raise_error(ArgumentError) end it "should NOT raise an error if the URL is a URI object" do Piston::Repository.new(URI.parse("http://svn.repository.org/repos")) end it "should report it does not exist when used on a repository which does not exist" do Piston::Repository.new("file:///path/to/some/repos").should_not exist end end describe Piston::Repository, "with a file:/// URL" do it_should_behave_like "A local repository" it "should report it exists when used on a repository which was created" do @repos.should exist end it "should create the repository on-disk" do File.directory?(@repos_dir).should == true end it "should raise an exception if the directory already exists" do lambda { @repos.create! }.should raise_error(Piston::Repository::DirectoryAlreadyExists) end end describe Piston::Repository, "with a newly created local repository" do it_should_behave_like "A local repository" it "should report the current revision number" do @repos.youngest.should == 0 end it "should report the full URL" do @repos.url.should == "file://#{@repos_dir}" end it "should report the repository's UUID" do @repos.uuid.should == YAML.load(`svn info #{@repos.url}`)["Repository UUID"] end end describe Piston::Repository, "on a remote repository" do it "should complain when attempting to create the repository" do lambda { Piston::Repository.new("http://some.repository.net/").create! }.should raise_error(Piston::Repository::NoCreateOnRemoteRepositoryUrl) end end describe Piston::Repository, "with 2 revisions" do it_should_behave_like "A working copy against a local repository" before do @wc.checkout(@repos.url) @wc.create!("main.c", "rev1") @wc.commit @wc.edit!("main.c", "rev2") @wc.commit end it "should allow catting the HEAD revision of a file" do @repos.cat("main.c").should == "rev2" end it "should allow catting a specific revision of a file" do @repos.cat("main.c", 1).should == "rev1" end it "should raise a FileNotFound exception when the file does not exist" do lambda { @repos.cat("missing.c") }.should raise_error(Piston::Repository::FileNotFound) end end