Class: Timecop::Rspec::TravelLog

Inherits:
Object
  • Object
show all
Defined in:
lib/timecop/rspec/travel_log.rb

Overview

Tracks details about a time travel operation that can be resumed later.

Instance Method Summary collapse

Constructor Details

#initialize(travel_method = nil, start_time = nil) ⇒ TravelLog

Returns a new instance of TravelLog.

Parameters:

  • travel_method (Symbol, nil) (defaults to: nil)

    :travel or :freeze (or nil)

  • start_time (Object, nil) (defaults to: nil)

    a time-like object or string



7
8
9
# File 'lib/timecop/rspec/travel_log.rb', line 7

def initialize(travel_method = nil, start_time = nil)
  new_trip(travel_method, start_time)
end

Instance Method Details

#pause_tripvoid

This method returns an undefined value.

Pauses the current trip, recording its duration.



25
26
27
# File 'lib/timecop/rspec/travel_log.rb', line 25

def pause_trip
  self.trip_duration = Time.now - coalesced_start_time
end

#resume_or_new_trip(travel_method, start_time) ⇒ Object

Either resumes a previous trip or starts a new one.

Parameters:

  • travel_method (Symbol)

    :travel or :freeze

  • start_time (Object)

    a time-like object or string

Returns:

  • (Object)

    the computed starting time for the trip



15
16
17
18
19
20
21
# File 'lib/timecop/rspec/travel_log.rb', line 15

def resume_or_new_trip(travel_method, start_time)
  if resume_trip?(travel_method, start_time)
    resume_trip
  else
    new_trip(travel_method, start_time)
  end
end