From 5c33417d4d7dcbb556cbb2cb523cdeddb6783e2e Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Wed, 23 Nov 2016 22:12:05 +0100 Subject: [PATCH 1/3] Use paths inside the temp directory for the unlink spec --- core/file/shared/unlink.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/file/shared/unlink.rb b/core/file/shared/unlink.rb index 4630557104..49351d30c9 100644 --- a/core/file/shared/unlink.rb +++ b/core/file/shared/unlink.rb @@ -1,7 +1,7 @@ describe :file_unlink, shared: true do before :each do - @file1 = 'test.txt' - @file2 = 'test2.txt' + @file1 = tmp('test.txt') + @file2 = tmp('test2.txt') touch @file1 touch @file2 From b18298834b7e598a29173dc69f06b5476977b797 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Wed, 23 Nov 2016 22:22:49 +0100 Subject: [PATCH 2/3] Fix spec to use absolute path in unlink specs --- core/file/shared/unlink.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/core/file/shared/unlink.rb b/core/file/shared/unlink.rb index 49351d30c9..ef4cedb032 100644 --- a/core/file/shared/unlink.rb +++ b/core/file/shared/unlink.rb @@ -39,13 +39,9 @@ end it "coerces a given parameter into a string if possible" do - class Coercable - def to_str - "test.txt" - end - end - - File.send(@method, Coercable.new).should == 1 + mock = mock("to_str") + mock.should_receive(:to_str).and_return(@file1) + File.send(@method, mock).should == 1 end it "accepts an object that has a #to_path method" do From 85b1e0ead2abfe474db9b3d4e4726710e8258fe9 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Thu, 24 Nov 2016 20:03:17 +0100 Subject: [PATCH 3/3] Add spec for File::SHARE_DELETE * See #175 --- core/file/shared/unlink.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/file/shared/unlink.rb b/core/file/shared/unlink.rb index ef4cedb032..7b0413b76b 100644 --- a/core/file/shared/unlink.rb +++ b/core/file/shared/unlink.rb @@ -47,4 +47,17 @@ it "accepts an object that has a #to_path method" do File.send(@method, mock_to_path(@file1)).should == 1 end + + ruby_version_is "2.3" do + platform_is :windows do + it "allows deleting an open file with File::SHARE_DELETE" do + path = tmp("share_delete.txt") + File.open(path, mode: File::CREAT | File::WRONLY | File::BINARY | File::SHARE_DELETE) do |f| + File.exist?(path).should be_true + File.send(@method, path) + end + File.exist?(path).should be_false + end + end + end end