Sha256: d7334616158ce9d1f0e7ee723b6f2ad65553ab54c92d572d0ba20efdb638855d

Contents?: true

Size: 1.65 KB

Versions: 7

Compression:

Stored size: 1.65 KB

Contents

require 'rubygems'
require 'bundler/setup'
require 'minitest/autorun'

$VERBOSE = true # enable ruby warnings

begin
  require 'mocha/setup'
rescue LoadError
  require 'mocha'
end

class Minitest::Unit::TestCase
  private
    # Tests to see that two times are within the given distance,
    # in seconds, from each other.
    def times_effectively_equal(time1, time2, seconds_interval = 1)
      (time1 - time2).abs <= seconds_interval
    end

    def assert_times_effectively_equal(time1, time2, seconds_interval = 1, msg = nil)
      assert times_effectively_equal(time1, time2, seconds_interval), "#{msg}: time1 = #{time1.to_s}, time2 = #{time2.to_s}"
    end

    def assert_times_effectively_not_equal(time1, time2, seconds_interval = 1, msg = nil)
      assert !times_effectively_equal(time1, time2, seconds_interval), "#{msg}: time1 = #{time1.to_s}, time2 = #{time2.to_s}"
    end

    # Gets the local offset (supplied by ENV['TZ'] or your computer's clock)
    # At the given timestamp, or Time.now if not time is given.
    def local_offset(time = Time.now)
      Time.at(time.to_i).to_datetime.offset
    end

    TIMEZONES = ["Europe/Paris", "UTC", "America/Chicago"]

    def each_timezone
      old_tz = ENV["TZ"]

      begin
        TIMEZONES.each do |timezone|
          ENV["TZ"] = timezone
          yield
        end
      ensure
        ENV["TZ"] = old_tz
      end
    end

    def a_time_stack_item
      Timecop::TimeStackItem.new(:freeze, 2008, 1, 1, 0, 0, 0)
    end

    def assert_date_times_equal(dt1, dt2)
      assert_in_delta dt1.to_time.to_f, dt2.to_time.to_f, 0.01, "Failed for timezone: #{ENV['TZ']}: #{dt1.to_s} not equal to #{dt2.to_s}"
    end

end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
solidus_backend-1.0.0.pre3 vendor/bundle/gems/timecop-0.7.4/test/test_helper.rb
timecop-0.8.0 test/test_helper.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/timecop-0.7.4/test/test_helper.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/timecop-0.7.4/test/test_helper.rb
timecop-0.7.4 test/test_helper.rb
timecop-0.7.3 test/test_helper.rb
timecop-0.7.2 test/test_helper.rb