2018-03-04 10:09:32 -05:00
|
|
|
require_relative '../fixtures/classes'
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
describe :time_now, shared: true do
|
|
|
|
it "creates a subclass instance if called on a subclass" do
|
|
|
|
TimeSpecs::SubTime.send(@method).should be_an_instance_of(TimeSpecs::SubTime)
|
|
|
|
TimeSpecs::MethodHolder.send(@method).should be_an_instance_of(Time)
|
|
|
|
end
|
2017-10-28 11:15:48 -04:00
|
|
|
|
|
|
|
it "sets the current time" do
|
|
|
|
now = TimeSpecs::MethodHolder.send(@method)
|
2019-04-27 12:53:23 -04:00
|
|
|
now.to_f.should be_close(Process.clock_gettime(Process::CLOCK_REALTIME), TIME_TOLERANCE)
|
2017-10-28 11:15:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "uses the local timezone" do
|
|
|
|
with_timezone("PDT", -8) do
|
|
|
|
now = TimeSpecs::MethodHolder.send(@method)
|
|
|
|
now.utc_offset.should == (-8 * 60 * 60)
|
|
|
|
end
|
|
|
|
end
|
2019-04-27 12:53:23 -04:00
|
|
|
|
2020-02-08 05:43:27 -05:00
|
|
|
it "has at least microsecond precision" do
|
|
|
|
# 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
|
2021-02-27 07:00:26 -05:00
|
|
|
t = 0
|
|
|
|
10_000.times.find do
|
|
|
|
t = Time.now.nsec
|
|
|
|
t % (expected * 10) != 0
|
|
|
|
end
|
|
|
|
(t % (expected * 10)).should != 0
|
2019-04-27 12:53:23 -04:00
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|