summaryrefslogtreecommitdiff
path: root/spec/ruby/core/time
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2019-04-27 18:53:23 +0200
committerBenoit Daloze <eregontp@gmail.com>2019-04-27 18:53:23 +0200
commita1b4816759418ca8fe510e8739622fc5d77ab0f0 (patch)
tree9d4fb6091d0086817f5bde46bf1150e9130d34fd /spec/ruby/core/time
parent00c33d9c232ed1a79eda17acd7231ac93caa162b (diff)
Update to ruby/spec@15c9619
Diffstat (limited to 'spec/ruby/core/time')
-rw-r--r--spec/ruby/core/time/shared/now.rb15
1 files changed, 14 insertions, 1 deletions
diff --git a/spec/ruby/core/time/shared/now.rb b/spec/ruby/core/time/shared/now.rb
index c548be283f..80f66a1134 100644
--- a/spec/ruby/core/time/shared/now.rb
+++ b/spec/ruby/core/time/shared/now.rb
@@ -8,7 +8,7 @@ describe :time_now, shared: true do
it "sets the current time" do
now = TimeSpecs::MethodHolder.send(@method)
- now.to_f.should be_close(Process.clock_gettime(Process::CLOCK_REALTIME), 10.0)
+ now.to_f.should be_close(Process.clock_gettime(Process::CLOCK_REALTIME), TIME_TOLERANCE)
end
it "uses the local timezone" do
@@ -17,4 +17,17 @@ describe :time_now, shared: true do
now.utc_offset.should == (-8 * 60 * 60)
end
end
+
+ it "has at least microsecond precision" do
+ times = []
+ 10_000.times do
+ times << Time.now.nsec
+ end
+
+ # The clock should not be less accurate than expected (times should
+ # not all be a multiple of the next precision up, assuming precisions
+ # are multiples of ten.)
+ expected = 1_000
+ times.select { |t| t % (expected * 10) == 0 }.size.should_not == times.size
+ end
end