class Timecop

Monkey patches to call our Lolex interface

Private Instance Methods

return() { || ... } click to toggle source
# File lib/hyper-spec/time_cop.rb, line 177
def return(&block)
  current_stack = @_stack
  current_baseline = @baseline
  unmock!
  yield
ensure
  Lolex.restore
  @_stack = current_stack
  @baseline = current_baseline
end
travel(mock_type, *args) { |time| ... } click to toggle source
# File lib/hyper-spec/time_cop.rb, line 157
def travel(mock_type, *args, &block)
  raise SafeModeException if Timecop.safe_mode? && !block_given?

  stack_item = TimeStackItem.new(mock_type, *args)

  stack_backup = @_stack.dup
  @_stack << stack_item

  Lolex.push(mock_type, *args)

  if block_given?
    begin
      yield stack_item.time
    ensure
      Lolex.pop
      @_stack.replace stack_backup
    end
  end
end