Sha256: b7b97a479d712ad98c56aa7150eb84023e3687a8ffdb9557af30a8b68f7e15ed

Contents?: true

Size: 1.56 KB

Versions: 12

Compression:

Stored size: 1.56 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
    _out, err = capture_io do
      Timezone.fetch('foo/bar', 'a') { 'b' }
    end

    assert_equal "warning: block supersedes default value argument\n", err
  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

12 entries across 12 versions & 1 rubygems

Version Path
timezone-1.3.28 test/test_timezone.rb
timezone-1.3.27 test/test_timezone.rb
timezone-1.3.26 test/test_timezone.rb
timezone-1.3.25 test/test_timezone.rb
timezone-1.3.24 test/test_timezone.rb
timezone-1.3.23 test/test_timezone.rb
timezone-1.3.22 test/test_timezone.rb
timezone-1.3.21 test/test_timezone.rb
timezone-1.3.20 test/test_timezone.rb
timezone-1.3.19 test/test_timezone.rb
timezone-1.3.18 test/test_timezone.rb
timezone-1.3.17 test/test_timezone.rb