1
0
mirror of https://github.com/meineerde/rackstash.git synced 2026-01-31 17:27:13 +00:00

Properly test every code path for Rackstash::Helpers::Time

Even if it doesn't look like it, there might (and in fact did) lure
unexpected errors even in seemlingly obvious code-paths.
This commit is contained in:
Holger Just 2017-12-05 19:25:54 +01:00
parent 6ce668e09d
commit 9150b2e0ac
2 changed files with 24 additions and 1 deletions

View File

@ -23,7 +23,7 @@ module Rackstash
#
# @return [Float] the current timestamp
def clock_time
Time.now.to_f
::Time.now.to_f
end
end
end

View File

@ -20,11 +20,34 @@ describe Rackstash::Helpers::Time do
end
it 'returns the numeric timestamp' do
expect(::Process::CLOCK_MONOTONIC).to_not be_nil
expect(::Time).not_to receive(:now)
expect(clock_time).to be_a Float
end
it 'is monotinically increasing' do
expect(clock_time).to be < clock_time
end
context 'without a monotonic clock' do
around do |example|
clock_monotic = ::Process.send(:remove_const, :CLOCK_MONOTONIC)
verbose, $VERBOSE = $VERBOSE, false
load File.expand_path('../../../lib/rackstash/helpers/time.rb', __dir__)
$VERBOSE = verbose
example.run
::Process::CLOCK_MONOTONIC = clock_monotic
verbose, $VERBOSE = $VERBOSE, false
load File.expand_path('../../../lib/rackstash/helpers/time.rb', __dir__)
$VERBOSE = verbose
end
it 'returns a float' do
expect(::Time).to receive(:now).and_call_original
expect(clock_time).to be_a Float
end
end
end
end