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:
parent
6ce668e09d
commit
9150b2e0ac
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user