Path: blob/master/spec/support/acceptance/countdown.rb
19715 views
module Acceptance1###2# A utility class which can be used in conjunction with Timeout mechanisms3###4class Countdown5# @param [int] timeout The time in seconds that this count starts from6def initialize(timeout)7@start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :second)8@end_time = @start_time + timeout9@timeout = timeout10end1112# @return [TrueClass, FalseClass] True if the timeout has surpassed, false otherwise13def elapsed?14remaining_time == 015end1617# @return [Integer] The time in seconds left before this countdown expires18def remaining_time19[@end_time - Process.clock_gettime(Process::CLOCK_MONOTONIC, :second), 0].max20end21end22end232425