diff options
Diffstat (limited to 'spec/ruby/core/file/path_spec.rb')
-rw-r--r-- | spec/ruby/core/file/path_spec.rb | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/spec/ruby/core/file/path_spec.rb b/spec/ruby/core/file/path_spec.rb index 5004e128cd..7a613a757f 100644 --- a/spec/ruby/core/file/path_spec.rb +++ b/spec/ruby/core/file/path_spec.rb @@ -1,6 +1,11 @@ require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../shared/path', __FILE__) describe "File#path" do + it_behaves_like :file_path, :path +end + +describe "File.path" do before :each do @name = tmp("file_path") end @@ -9,21 +14,27 @@ describe "File#path" do rm_r @name end - it "returns the pathname used to create file as a string" do - File.open(@name,'w') { |file| file.path.should == @name } + 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" end -end -describe "File.path" do - before :each do - @name = tmp("file_path") + it "returns path for File argument" do + File.open(@name, "w") do |f| + File.path(f).should == @name + end end - after :each do - rm_r @name + it "returns path for Pathname argument" do + require "pathname" + File.path(Pathname.new(@name)).should == @name end - it "returns the full path for the given file" do - File.path(@name).should == @name + 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" end end |