2018-03-04 10:09:32 -05:00
|
|
|
require_relative '../../spec_helper'
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
describe "File.rename" do
|
|
|
|
before :each do
|
|
|
|
@old = tmp("file_rename.txt")
|
|
|
|
@new = tmp("file_rename.new")
|
|
|
|
|
|
|
|
rm_r @new
|
|
|
|
touch(@old) { |f| f.puts "hello" }
|
|
|
|
end
|
|
|
|
|
|
|
|
after :each do
|
|
|
|
rm_r @old, @new
|
|
|
|
end
|
|
|
|
|
|
|
|
it "renames a file" do
|
2019-09-29 13:13:37 -04:00
|
|
|
File.should.exist?(@old)
|
|
|
|
File.should_not.exist?(@new)
|
2017-05-07 08:04:49 -04:00
|
|
|
File.rename(@old, @new)
|
2019-09-29 13:13:37 -04:00
|
|
|
File.should_not.exist?(@old)
|
|
|
|
File.should.exist?(@new)
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "raises an Errno::ENOENT if the source does not exist" do
|
|
|
|
rm_r @old
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { File.rename(@old, @new) }.should raise_error(Errno::ENOENT)
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "raises an ArgumentError if not passed two arguments" do
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { File.rename }.should raise_error(ArgumentError)
|
|
|
|
-> { File.rename(@file) }.should raise_error(ArgumentError)
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "raises a TypeError if not passed String types" do
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { File.rename(1, 2) }.should raise_error(TypeError)
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
end
|