Module: Brut::SpecSupport::ClockSupport

Included in:
ComponentSupport, HandlerSupport
Defined in:
lib/brut/spec_support/clock_support.rb

Overview

Convienience methods for creating clocks needed in tests

Instance Method Summary collapse

Instance Method Details

#clock_at(now:) ⇒ Object

Return a clock whose value for now is now, in UTC

Parameters:

  • now (String)

    a string containing the value you want for Clock#now to return.



9
10
11
# File 'lib/brut/spec_support/clock_support.rb', line 9

def clock_at(now:)
  self.clock_in_timezone_at(timezone_name: "UTC", now: now)
end

#clock_in_timezone_at(timezone_name:, now:) ⇒ Object

Return a clock whose value for now is now in the given timezone

Parameters:

  • timezone_name (String)

    a string that is the name of the timezone to use.

  • now (String)

    a string containing the value you want for Clock#now to return.



17
18
19
20
21
22
23
# File 'lib/brut/spec_support/clock_support.rb', line 17

def clock_in_timezone_at(timezone_name:, now:)
  time = Time.parse(now)
  timezone = TZInfo::Timezone.get(timezone_name)
  same_time_in_timezone = timezone.local_time(time.year, time.month, time.day, time.hour, time.min, time.sec)

  Clock.new(TZInfo::Timezone.get(timezone_name), now: same_time_in_timezone)
end

#real_clockObject

Return a real lock in UTC



4
# File 'lib/brut/spec_support/clock_support.rb', line 4

def real_clock = Clock.new(TZInfo::Timezone.get("UTC"))