diff options
Diffstat (limited to 'spec/ruby/core/file/absolute_path_spec.rb')
| -rw-r--r-- | spec/ruby/core/file/absolute_path_spec.rb | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/spec/ruby/core/file/absolute_path_spec.rb b/spec/ruby/core/file/absolute_path_spec.rb index b1f4f05aee..fc12985a75 100644 --- a/spec/ruby/core/file/absolute_path_spec.rb +++ b/spec/ruby/core/file/absolute_path_spec.rb @@ -1,4 +1,55 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' + +describe "File.absolute_path?" do + before :each do + @abs = File.expand_path(__FILE__) + end + + it "returns true if it's an absolute pathname" do + File.absolute_path?(@abs).should == true + end + + it "returns false if it's a relative path" do + File.absolute_path?(File.basename(__FILE__)).should == false + end + + it "returns false if it's a tricky relative path" do + File.absolute_path?("C:foo\\bar").should == false + end + + it "does not expand '~' to a home directory." do + File.absolute_path?('~').should == false + end + + it "does not expand '~user' to a home directory." do + path = File.dirname(@abs) + Dir.chdir(path) do + File.absolute_path?('~user').should == false + end + end + + it "calls #to_path on its argument" do + mock = mock_to_path(File.expand_path(__FILE__)) + + File.absolute_path?(mock).should == true + end + + platform_is_not :windows do + it "takes into consideration the platform's root" do + File.absolute_path?("C:\\foo\\bar").should == false + File.absolute_path?("C:/foo/bar").should == false + File.absolute_path?("/foo/bar\\baz").should == true + end + end + + platform_is :windows do + it "takes into consideration the platform path separator(s)" do + File.absolute_path?("C:\\foo\\bar").should == true + File.absolute_path?("C:/foo/bar").should == true + File.absolute_path?("/foo/bar\\baz").should == false + end + end +end describe "File.absolute_path" do before :each do @@ -20,6 +71,12 @@ describe "File.absolute_path" do File.absolute_path('~').should_not == File.expand_path('~') end + platform_is_not :windows do + it "does not expand '~' when given dir argument" do + File.absolute_path('~', '/').should == '/~' + end + end + it "does not expand '~user' to a home directory." do path = File.dirname(@abs) Dir.chdir(path) do @@ -28,7 +85,7 @@ describe "File.absolute_path" do end it "accepts a second argument of a directory from which to resolve the path" do - File.absolute_path(__FILE__, File.dirname(__FILE__)).should == @abs + File.absolute_path(__FILE__, __dir__).should == @abs end it "calls #to_path on its argument" do |
