aboutsummaryrefslogtreecommitdiffstats
path: root/spec/ruby/core/file/utime_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/file/utime_spec.rb')
-rw-r--r--spec/ruby/core/file/utime_spec.rb54
1 files changed, 41 insertions, 13 deletions
diff --git a/spec/ruby/core/file/utime_spec.rb b/spec/ruby/core/file/utime_spec.rb
index 542681ea93..64af82ef19 100644
--- a/spec/ruby/core/file/utime_spec.rb
+++ b/spec/ruby/core/file/utime_spec.rb
@@ -1,6 +1,11 @@
require_relative '../../spec_helper'
describe "File.utime" do
+
+ before :all do
+ @time_is_float = /mswin|mingw/ =~ RUBY_PLATFORM && RUBY_VERSION >= '2.5'
+ end
+
before :each do
@atime = Time.now
@mtime = Time.now
@@ -16,18 +21,33 @@ describe "File.utime" do
it "sets the access and modification time of each file" do
File.utime(@atime, @mtime, @file1, @file2)
- File.atime(@file1).to_i.should be_close(@atime.to_i, 2)
- File.mtime(@file1).to_i.should be_close(@mtime.to_i, 2)
- File.atime(@file2).to_i.should be_close(@atime.to_i, 2)
- File.mtime(@file2).to_i.should be_close(@mtime.to_i, 2)
+ if @time_is_float
+ File.atime(@file1).should be_close(@atime, 0.0001)
+ File.mtime(@file1).should be_close(@mtime, 0.0001)
+ File.atime(@file2).should be_close(@atime, 0.0001)
+ File.mtime(@file2).should be_close(@mtime, 0.0001)
+ else
+ File.atime(@file1).to_i.should be_close(@atime.to_i, 2)
+ File.mtime(@file1).to_i.should be_close(@mtime.to_i, 2)
+ File.atime(@file2).to_i.should be_close(@atime.to_i, 2)
+ File.mtime(@file2).to_i.should be_close(@mtime.to_i, 2)
+ end
end
it "uses the current times if two nil values are passed" do
+ tn = Time.now
File.utime(nil, nil, @file1, @file2)
- File.atime(@file1).to_i.should be_close(Time.now.to_i, 2)
- File.mtime(@file1).to_i.should be_close(Time.now.to_i, 2)
- File.atime(@file2).to_i.should be_close(Time.now.to_i, 2)
- File.mtime(@file2).to_i.should be_close(Time.now.to_i, 2)
+ if @time_is_float
+ File.atime(@file1).should be_close(tn, 0.050)
+ File.mtime(@file1).should be_close(tn, 0.050)
+ File.atime(@file2).should be_close(tn, 0.050)
+ File.mtime(@file2).should be_close(tn, 0.050)
+ else
+ File.atime(@file1).to_i.should be_close(Time.now.to_i, 2)
+ File.mtime(@file1).to_i.should be_close(Time.now.to_i, 2)
+ File.atime(@file2).to_i.should be_close(Time.now.to_i, 2)
+ File.mtime(@file2).to_i.should be_close(Time.now.to_i, 2)
+ end
end
it "accepts an object that has a #to_path method" do
@@ -35,11 +55,19 @@ describe "File.utime" do
end
it "accepts numeric atime and mtime arguments" do
- File.utime(@atime.to_i, @mtime.to_i, @file1, @file2)
- File.atime(@file1).to_i.should be_close(@atime.to_i, 2)
- File.mtime(@file1).to_i.should be_close(@mtime.to_i, 2)
- File.atime(@file2).to_i.should be_close(@atime.to_i, 2)
- File.mtime(@file2).to_i.should be_close(@mtime.to_i, 2)
+ if @time_is_float
+ File.utime(@atime.to_f, @mtime.to_f, @file1, @file2)
+ File.atime(@file1).should be_close(@atime, 0.0001)
+ File.mtime(@file1).should be_close(@mtime, 0.0001)
+ File.atime(@file2).should be_close(@atime, 0.0001)
+ File.mtime(@file2).should be_close(@mtime, 0.0001)
+ else
+ File.utime(@atime.to_i, @mtime.to_i, @file1, @file2)
+ File.atime(@file1).to_i.should be_close(@atime.to_i, 2)
+ File.mtime(@file1).to_i.should be_close(@mtime.to_i, 2)
+ File.atime(@file2).to_i.should be_close(@atime.to_i, 2)
+ File.mtime(@file2).to_i.should be_close(@mtime.to_i, 2)
+ end
end
platform_is :linux do