Class: Timecop::Rspec::ExampleDecorator

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

Overview

Decorates an RSpec example to interpret timecop metadata.

Recognized metadata keys:

  • :freeze => Time/Date/DateTime/String/Proc to freeze time to

  • :travel => Time/Date/DateTime/String/Proc to travel to (and optionally continue)

  • :skip_global_timecop => when present, disables global time for this example

Instance Method Summary collapse

Instance Method Details

#global_timecop?Boolean

Whether a global time is configured and not skipped by the example.



38
39
40
# File 'lib/timecop/rspec/example_decorator.rb', line 38

def global_timecop?
  Rspec.global_time_configured? && !skip_global_timecop?
end

#local_timecop?Boolean

Whether the example has local timecop metadata.



32
33
34
# File 'lib/timecop/rspec/example_decorator.rb', line 32

def local_timecop?
  !local_timecop_method.nil?
end

#skip_global_timecop?Boolean

Whether the example requested skipping global timecop behavior.



44
45
46
# File 'lib/timecop/rspec/example_decorator.rb', line 44

def skip_global_timecop?
  .key?(:skip_global_timecop)
end

#timecop?Boolean



14
15
16
# File 'lib/timecop/rspec/example_decorator.rb', line 14

def timecop?
  local_timecop? || global_timecop?
end

#timecop_methodSymbol?

Determines the timecop method to invoke.



20
21
22
# File 'lib/timecop/rspec/example_decorator.rb', line 20

def timecop_method
  local_timecop_method || global_timecop_method
end

#timecop_timeObject?

Determines the time to use for the chosen timecop method.



26
27
28
# File 'lib/timecop/rspec/example_decorator.rb', line 26

def timecop_time
  local_timecop_time || global_timecop_time
end