2018-03-04 10:09:32 -05:00
|
|
|
require_relative '../../spec_helper'
|
|
|
|
require_relative 'shared/path'
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
describe "File#path" do
|
2018-01-29 11:08:16 -05:00
|
|
|
it_behaves_like :file_path, :path
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "File.path" do
|
2017-05-07 08:04:49 -04:00
|
|
|
before :each do
|
|
|
|
@name = tmp("file_path")
|
|
|
|
end
|
|
|
|
|
|
|
|
after :each do
|
|
|
|
rm_r @name
|
|
|
|
end
|
|
|
|
|
2018-01-29 11:08:16 -05:00
|
|
|
it "returns the string argument without any change" do
|
|
|
|
File.path("abc").should == "abc"
|
|
|
|
File.path("./abc").should == "./abc"
|
|
|
|
File.path("../abc").should == "../abc"
|
|
|
|
File.path("/./a/../bc").should == "/./a/../bc"
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
2018-01-29 11:08:16 -05:00
|
|
|
it "returns path for File argument" do
|
|
|
|
File.open(@name, "w") do |f|
|
|
|
|
File.path(f).should == @name
|
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
2018-01-29 11:08:16 -05:00
|
|
|
it "returns path for Pathname argument" do
|
|
|
|
require "pathname"
|
|
|
|
File.path(Pathname.new(@name)).should == @name
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
2018-01-29 11:08:16 -05:00
|
|
|
it "calls #to_path for non-string argument and returns result" do
|
|
|
|
path = mock("path")
|
|
|
|
path.should_receive(:to_path).and_return("abc")
|
|
|
|
File.path(path).should == "abc"
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
end
|