Sha256: 33806e0822f2e8e6f76488a601eeaae3229871ad8417fae92fa928986e3a4026

Contents?: true

Size: 1.57 KB

Versions: 21

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

require 'timezone'
require 'minitest/autorun'

class TestTimezone < ::Minitest::Test
  parallelize_me!

  def test_names
    assert Timezone.names.is_a?(Array)
    refute Timezone.names.empty?
    assert Timezone.names.include?('Australia/Sydney')
    assert Timezone.names.include?('America/Los_Angeles')
  end

  def test_get
    assert Timezone['Australia/Sydney'].valid?
    refute Timezone['foo/bar'].valid?
  end

  def test_fetch
    assert Timezone.fetch('Australia/Sydney').valid?
    assert_equal 'foo', Timezone.fetch('foo/bar') { 'foo' }
    assert_raises Timezone::Error::InvalidZone do
      Timezone.fetch('foo/bar')
    end
    assert_equal 'foo', Timezone.fetch('foo/bar', 'foo')

    Timezone.stub(:warn, nil) do
      assert_equal 'b', Timezone.fetch('foo/bar', 'a') { 'b' }
    end
  end

  def test_fetch_warning
    warning = false

    Timezone.stub(:warn, ->(_) { warning = true }) do
      Timezone.fetch('foo/bar', 'a') { 'b' }
    end

    assert warning, 'warning was not issued'
  end

  def test_lookup
    Timezone::Lookup.config(:test)

    Timezone::Lookup.lookup.stub(-10, 10, 'America/Los_Angeles')
    Timezone::Lookup.lookup.stub(-20, 20, 'foos')

    assert_equal Timezone['America/Los_Angeles'], Timezone.lookup(-10, 10)
    assert_equal 'foo', Timezone.lookup(-20, 20) { 'foo' }
    assert_raises Timezone::Error::InvalidZone do
      Timezone.lookup(-20, 20)
    end
    assert_equal 'foo', Timezone.lookup(-20, 20, 'foo')

    Timezone.stub(:warn, nil) do
      assert_equal 'b', Timezone.lookup(-20, 20, 'a') { 'b' }
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
timezone-1.3.16 test/test_timezone.rb
timezone-1.3.15 test/test_timezone.rb
timezone-1.3.14 test/test_timezone.rb
timezone-1.3.13 test/test_timezone.rb
timezone-1.3.12 test/test_timezone.rb
timezone-1.3.11 test/test_timezone.rb
timezone-1.3.10 test/test_timezone.rb
timezone-1.3.9 test/test_timezone.rb
timezone-1.3.8 test/test_timezone.rb
timezone-1.3.7 test/test_timezone.rb
timezone-1.3.6 test/test_timezone.rb
timezone-1.3.5 test/test_timezone.rb
timezone-1.3.4 test/test_timezone.rb
timezone-1.3.3 test/test_timezone.rb
timezone-1.3.2 test/test_timezone.rb
timezone-1.3.1 test/test_timezone.rb
timezone-1.3.0 test/test_timezone.rb
timezone-1.2.12 test/test_timezone.rb
timezone-1.2.11 test/test_timezone.rb
timezone-1.2.10 test/test_timezone.rb