diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-29 16:08:16 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-29 16:08:16 +0000 |
commit | 3fa5bd38af50fb3d98de0ea51043d73f8d06a24b (patch) | |
tree | d473b71cc6925ee1e17727215e9f9a66e3f24802 /spec/ruby/core/file | |
parent | 1e658d45e1f8dbadab18f9c35b5cfb5a5fec98bf (diff) | |
download | ruby-3fa5bd38af50fb3d98de0ea51043d73f8d06a24b.tar.gz |
Update to ruby/spec@83063a3
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62094 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/file')
-rw-r--r-- | spec/ruby/core/file/delete_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/file/exist_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/file/exists_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/file/fnmatch_spec.rb | 4 | ||||
-rw-r--r-- | spec/ruby/core/file/open_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/file/path_spec.rb | 31 | ||||
-rw-r--r-- | spec/ruby/core/file/shared/path.rb | 80 | ||||
-rw-r--r-- | spec/ruby/core/file/stat/world_readable_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/file/stat/world_writable_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/file/to_path_spec.rb | 47 | ||||
-rw-r--r-- | spec/ruby/core/file/unlink_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/file/world_readable_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/file/world_writable_spec.rb | 2 |
13 files changed, 114 insertions, 66 deletions
diff --git a/spec/ruby/core/file/delete_spec.rb b/spec/ruby/core/file/delete_spec.rb index 2e903806d7..9c4bf33c48 100644 --- a/spec/ruby/core/file/delete_spec.rb +++ b/spec/ruby/core/file/delete_spec.rb @@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../shared/unlink', __FILE__) describe "File.delete" do - it_behaves_like(:file_unlink, :delete) + it_behaves_like :file_unlink, :delete end diff --git a/spec/ruby/core/file/exist_spec.rb b/spec/ruby/core/file/exist_spec.rb index 29a410c125..0ca6b87ff4 100644 --- a/spec/ruby/core/file/exist_spec.rb +++ b/spec/ruby/core/file/exist_spec.rb @@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../../../shared/file/exist', __FILE__) describe "File.exist?" do - it_behaves_like(:file_exist, :exist?, File) + it_behaves_like :file_exist, :exist?, File end diff --git a/spec/ruby/core/file/exists_spec.rb b/spec/ruby/core/file/exists_spec.rb index 70ebd12d86..ee5d564112 100644 --- a/spec/ruby/core/file/exists_spec.rb +++ b/spec/ruby/core/file/exists_spec.rb @@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../../../shared/file/exist', __FILE__) describe "File.exists?" do - it_behaves_like(:file_exist, :exists?, File) + it_behaves_like :file_exist, :exists?, File end diff --git a/spec/ruby/core/file/fnmatch_spec.rb b/spec/ruby/core/file/fnmatch_spec.rb index 8a4caacfb8..a2287ffcdb 100644 --- a/spec/ruby/core/file/fnmatch_spec.rb +++ b/spec/ruby/core/file/fnmatch_spec.rb @@ -2,9 +2,9 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../shared/fnmatch', __FILE__) describe "File.fnmatch" do - it_behaves_like(:file_fnmatch, :fnmatch) + it_behaves_like :file_fnmatch, :fnmatch end describe "File.fnmatch?" do - it_behaves_like(:file_fnmatch, :fnmatch?) + it_behaves_like :file_fnmatch, :fnmatch? end diff --git a/spec/ruby/core/file/open_spec.rb b/spec/ruby/core/file/open_spec.rb index 9d0ef62939..3b2ae60489 100644 --- a/spec/ruby/core/file/open_spec.rb +++ b/spec/ruby/core/file/open_spec.rb @@ -526,7 +526,7 @@ describe "File.open" do ruby_version_is "2.3" do platform_is :linux do - if defined?(File::TMPFILE) + guard -> { defined?(File::TMPFILE) } do it "creates an unnamed temporary file with File::TMPFILE" do dir = tmp("tmpfilespec") mkdir_p dir 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 diff --git a/spec/ruby/core/file/shared/path.rb b/spec/ruby/core/file/shared/path.rb new file mode 100644 index 0000000000..3f2fccafa9 --- /dev/null +++ b/spec/ruby/core/file/shared/path.rb @@ -0,0 +1,80 @@ +describe :file_path, shared: true do + before :each do + @name = "file_to_path" + @path = tmp(@name) + touch @path + end + + after :each do + @file.close if @file and !@file.closed? + rm_r @path + end + + it "returns a String" do + @file = File.new @path + @file.send(@method).should be_an_instance_of(String) + 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.send(@method).should == @path + end + + it "does not normalise the path it returns" do + Dir.chdir(tmp("")) do + unorm = "./#{@name}" + @file = File.new unorm + @file.send(@method).should == unorm + end + end + + it "does not canonicalize the path it returns" do + dir = File.basename tmp("") + path = "#{tmp("")}../#{dir}/#{@name}" + @file = File.new path + @file.send(@method).should == path + end + + it "does not absolute-ise the path it returns" do + Dir.chdir(tmp("")) do + @file = File.new @name + @file.send(@method).should == @name + 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.send(@method).encoding.should == Encoding.find("euc-jp") + end + end + + ruby_version_is "2.5" do + 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 + + it "raises IOError if file was opened with File::TMPFILE" do + begin + File.open(@dir, File::RDWR | File::TMPFILE) do |f| + -> { f.send(@method) }.should raise_error(IOError) + end + rescue Errno::EOPNOTSUPP + # EOPNOTSUPP: no support from the filesystem + 1.should == 1 + end + end + end + end + end +end diff --git a/spec/ruby/core/file/stat/world_readable_spec.rb b/spec/ruby/core/file/stat/world_readable_spec.rb index 178e39a1ea..e72963c0b8 100644 --- a/spec/ruby/core/file/stat/world_readable_spec.rb +++ b/spec/ruby/core/file/stat/world_readable_spec.rb @@ -3,7 +3,7 @@ require File.expand_path('../../../../shared/file/world_readable', __FILE__) require File.expand_path('../fixtures/classes', __FILE__) describe "File::Stat.world_readable?" do - it_behaves_like(:file_world_readable, :world_readable?, FileStat) + it_behaves_like :file_world_readable, :world_readable?, FileStat end describe "File::Stat#world_readable?" do diff --git a/spec/ruby/core/file/stat/world_writable_spec.rb b/spec/ruby/core/file/stat/world_writable_spec.rb index 73a7c6d3ed..f532d752dd 100644 --- a/spec/ruby/core/file/stat/world_writable_spec.rb +++ b/spec/ruby/core/file/stat/world_writable_spec.rb @@ -3,7 +3,7 @@ require File.expand_path('../../../../shared/file/world_writable', __FILE__) require File.expand_path('../fixtures/classes', __FILE__) describe "File::Stat.world_writable?" do - it_behaves_like(:file_world_writable, :world_writable?, FileStat) + it_behaves_like :file_world_writable, :world_writable?, FileStat end describe "File::Stat#world_writable?" do diff --git a/spec/ruby/core/file/to_path_spec.rb b/spec/ruby/core/file/to_path_spec.rb index 3dc801cc27..006011089c 100644 --- a/spec/ruby/core/file/to_path_spec.rb +++ b/spec/ruby/core/file/to_path_spec.rb @@ -1,49 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../shared/path', __FILE__) describe "File#to_path" do - before :each do - @name = "file_to_path" - @path = tmp(@name) - touch @path - end - - after :each do - @file.close if @file and !@file.closed? - rm_r @path - end - - it "returns a String" do - @file = File.new @path - @file.to_path.should be_an_instance_of(String) - end - - it "does not normalise the path it returns" do - Dir.chdir(tmp("")) do - unorm = "./#{@name}" - @file = File.new unorm - @file.to_path.should == unorm - end - end - - it "does not canonicalize the path it returns" do - dir = File.basename tmp("") - path = "#{tmp("")}../#{dir}/#{@name}" - @file = File.new path - @file.to_path.should == path - end - - it "does not absolute-ise the path it returns" do - Dir.chdir(tmp("")) do - @file = File.new @name - @file.to_path.should == @name - 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") - end - end + it_behaves_like :file_path, :to_path end diff --git a/spec/ruby/core/file/unlink_spec.rb b/spec/ruby/core/file/unlink_spec.rb index a1e96aef6a..3e67ebc25d 100644 --- a/spec/ruby/core/file/unlink_spec.rb +++ b/spec/ruby/core/file/unlink_spec.rb @@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../shared/unlink', __FILE__) describe "File.unlink" do - it_behaves_like(:file_unlink, :unlink) + it_behaves_like :file_unlink, :unlink end diff --git a/spec/ruby/core/file/world_readable_spec.rb b/spec/ruby/core/file/world_readable_spec.rb index a130f0d115..ea0b739fff 100644 --- a/spec/ruby/core/file/world_readable_spec.rb +++ b/spec/ruby/core/file/world_readable_spec.rb @@ -2,7 +2,7 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../../../shared/file/world_readable', __FILE__) describe "File.world_readable?" do - it_behaves_like(:file_world_readable, :world_readable?, File) + it_behaves_like :file_world_readable, :world_readable?, File it "returns nil if the file does not exist" do file = rand.to_s + $$.to_s diff --git a/spec/ruby/core/file/world_writable_spec.rb b/spec/ruby/core/file/world_writable_spec.rb index 5a39643ef9..57aede397c 100644 --- a/spec/ruby/core/file/world_writable_spec.rb +++ b/spec/ruby/core/file/world_writable_spec.rb @@ -2,7 +2,7 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../../../shared/file/world_writable', __FILE__) describe "File.world_writable?" do - it_behaves_like(:file_world_writable, :world_writable?, File) + it_behaves_like :file_world_writable, :world_writable?, File it "returns nil if the file does not exist" do file = rand.to_s + $$.to_s |