summaryrefslogtreecommitdiff
path: root/spec/ruby/core/file/to_path_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/file/to_path_spec.rb')
-rw-r--r--spec/ruby/core/file/to_path_spec.rb53
1 files changed, 44 insertions, 9 deletions
diff --git a/spec/ruby/core/file/to_path_spec.rb b/spec/ruby/core/file/to_path_spec.rb
index 3dc801cc27..b968d3b2b9 100644
--- a/spec/ruby/core/file/to_path_spec.rb
+++ b/spec/ruby/core/file/to_path_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "File#to_path" do
before :each do
- @name = "file_to_path"
- @path = tmp(@name)
+ @path = tmp("file_to_path")
+ @name = File.basename(@path)
touch @path
end
@@ -14,7 +14,31 @@ describe "File#to_path" do
it "returns a String" do
@file = File.new @path
- @file.to_path.should be_an_instance_of(String)
+ @file.to_path.should.instance_of?(String)
+ end
+
+ it "returns a different String on every call" do
+ @file = File.new @path
+ path1 = @file.to_path
+ path2 = @file.to_path
+ path1.should == path2
+ path1.should_not.equal?(path2)
+ end
+
+ it "returns a mutable String" do
+ @file = File.new @path.dup.freeze
+ path = @file.to_path
+ path.should == @path
+ path.should_not.frozen?
+ path << "test"
+ @file.to_path.should == @path
+ end
+
+ it "calls to_str on argument and returns exact value" do
+ path = mock('path')
+ path.should_receive(:to_str).and_return(@path)
+ @file = File.new path
+ @file.to_path.should == @path
end
it "does not normalise the path it returns" do
@@ -39,11 +63,22 @@ describe "File#to_path" do
end
end
- with_feature :encoding do
- it "preserves the encoding of the path" do
- path = @path.force_encoding("euc-jp")
- @file = File.new path
- @file.to_path.encoding.should == Encoding.find("euc-jp")
+ it "preserves the encoding of the path" do
+ path = @path.force_encoding("euc-jp")
+ @file = File.new path
+ @file.to_path.encoding.should == Encoding.find("euc-jp")
+ end
+
+ platform_is :linux do
+ guard -> { defined?(File::TMPFILE) } do
+ before :each do
+ @dir = tmp("tmpfilespec")
+ mkdir_p @dir
+ end
+
+ after :each do
+ rm_r @dir
+ end
end
end
end