Sha256: 8460d68f99574444042d556f130199368f7f2aa7b00f5407f495c987e527a3e2

Contents?: true

Size: 1.48 KB

Versions: 4

Compression:

Stored size: 1.48 KB

Contents

require 'test_helper'
require 'tins/xt/time_freezer'

module Tins
  class TimeFreezerTest < Test::Unit::TestCase
    def test_freezing
      freezing_point = '2011-11-11T11:11:11Z'
      Tins::TimeFreezer.freeze(freezing_point) do
        assert_equal "2011-11-11 11:11:11 UTC", Time.now.to_s
        assert_equal "2011-11-11T11:11:11+00:00", DateTime.now.to_s
        assert_equal "2011-11-11", Date.today.to_s
      end
    end

    def test_to_time_conversion
      freezing_point = '2011-11-11T11:11:11Z'
      time = Time.parse(freezing_point)
      Tins::TimeFreezer.freeze(time) do
        assert_equal "2011-11-11 11:11:11 UTC", Time.now.utc.to_s
        assert_equal "2011-11-11T11:11:11+00:00", DateTime.now.to_s
        assert_equal "2011-11-11", Date.today.to_s
      end
    end

    def test_to_date_conversion
      freezing_point = '2011-11-11Z'
      date = Date.parse(freezing_point)
      Tins::TimeFreezer.freeze(date) do
        assert_equal "2011-11", Time.now.utc.to_s[0, 7]
        assert_equal "2011-11", DateTime.now.to_s[0, 7]
        assert_equal "2011-11", Date.today.to_s[0, 7]
      end
    end

    def test_to_datetime_conversion
      freezing_point = '2011-11-11T11:11:11Z'
      datetime = DateTime.parse(freezing_point)
      Tins::TimeFreezer.freeze(datetime) do
        assert_equal "2011-11-11 11:11:11 UTC", Time.now.utc.to_s
        assert_equal "2011-11-11T11:11:11+00:00", DateTime.now.to_s
        assert_equal "2011-11-11", Date.today.to_s
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tins-1.37.0 tests/time_freezer_test.rb
tins-1.36.1 tests/time_freezer_test.rb
tins-1.36.0 tests/time_freezer_test.rb
tins-1.35.0 tests/time_freezer_test.rb