Skip to content

module Athena::Clock::Spec::ClockSensitive #

An Athena::Spec::TestCase mix-in that allows freezing time and restoring the global clock after each test.

struct MonthSensitiveTest < ASPEC::TestCase
  include ACLK::Spec::ClockSensitive

  def test_winter_month : Nil
    clock = self.mock_time Time.utc 2023, 12, 10

    month_sensitive = MonthSensitive.new
    month_sensitive.clock = clock

    month_sensitive.winter_month?.should be_true
  end

  def test_non_winter_month : Nil
    clock = self.mock_time Time.utc 2023, 7, 10

    month_sensitive = MonthSensitive.new
    month_sensitive.clock = clock

    month_sensitive.winter_month?.should be_false
  end
end

Methods#

#mock_time(now : Time | Bool = true) : ACLK::Interface#

Returns clock instance based on the provided now value.

If a Time instance is passed, that value is used. If true, freezes the global clock to the current time. If false, restores the previous global clock.

View source

#shift(*, years : Int = 0, months : Int = 0, weeks : Int = 0, days : Int = 0, hours : Int = 0, minutes : Int = 0, seconds : Int = 0) : ACLK::Interface#

Returns a new clock instanced with the global clock value shifted by the provided amount of time. Positive values shift into the future, while negative values shift into the past.

View source