spec/pa/cmd_spec.rb in pa-1.1.4 vs spec/pa/cmd_spec.rb in pa-1.2.0
- old
+ new
@@ -1,25 +1,40 @@
require "spec_helper"
require "fileutils"
require "tmpdir"
module Pa::Cmd::ClassMethods
- public :_copy, :_touch, :_mkdir, :_mktmpname, :_rmdir, :_copy, :_move
+ public :_copy, :_touch, :_mkdir, :_mktmpname, :_rmdir, :_copy, :_move, :_ln
end
describe Pa do
before :all do
@curdir = Dir.pwd
@tmpdir = Dir.mktmpdir
Dir.chdir(@tmpdir)
end
-
- after(:all) do
+ after :all do
Dir.chdir(@curdir)
FileUtils.rm_r @tmpdir
end
+ describe "#_ln" do
+ # lna
+ before :all do
+ FileUtils.touch(%w[lna])
+ end
+
+ it "works" do
+ output = capture :stdout do
+ Pa._ln(:link, "lna", "lnb", :verbose => true)
+ end
+
+ output.should == "ln lna lnb\n"
+ File.identical?("lna", "lnb").should be_true
+ end
+ end
+
describe "#_rmdir" do
# dir/
# a
# dira/
# aa
@@ -136,11 +151,10 @@
Pa._copy 'dir', 'dirc'
Dir.entries('dirc').sort.should == Dir.entries('dir').sort
end
context "with :symlink" do
-
it "_copy" do
Pa._copy 'symfile', 'symfilea'
File.symlink?('symfilea').should be_true
end
@@ -267,20 +281,39 @@
File.exists?("dir/a").should be_true
File.exists?("dir/b").should be_true
end
end
- describe ".rename2" do
- it "works" do
- a = Pa.rename2('/home/guten.jpg') {|pa| pa.name+'_1'+pa.fext }
- a.should == '/home/guten_1.jpg'
- end
- end
+ describe "#_mktmpname" do
+ it "works" do
+ path = Pa._mktmpname("foo", :tmpdir => "guten")
- describe "#rename" do
- it "works" do
- Pa('/home/guten.jpg').rename {|pa|
- pa.name+'_1'+pa.fext
- }.should == Pa('/home/guten_1.jpg')
- end
- end
+ path.should =~ %r~guten/foo\..{6}~
+ end
+ end
+
+ describe "#mktmpdir" do
+ it "works" do
+ File.should_receive(:mkdir)
+
+ path = Pa.mktmpdir("foo")
+
+ path.should =~ %r~#{Regexp.escape(ENV["TEMP"])}/foo~
+ end
+ end
+
+ describe "#mktmpfile2" do
+ it "works" do
+ path = Pa.mktmpfile2 :tmpdir => "foo"
+
+ path.should =~ %r~foo/#{$$}~
+ end
+ end
+
+ describe "#mktmpfile" do
+ it "works" do
+ path = Pa.mktmpfile
+
+ path.should be_an_instance_of(Pa)
+ end
+ end
end