Sha256: dfd2667da8aae05df0be0a48919873557b526892f9ab6eb891c2b622f3128c7b

Contents?: true

Size: 1.26 KB

Versions: 3

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

require 'timezone/lookup'
require 'minitest/autorun'

class TestLookup < ::Minitest::Test
  def test_test_config
    Timezone::Lookup.config(:test)

    assert_equal Timezone::Lookup::Test,
                 Timezone::Lookup.lookup.class
  end

  def test_geonames_config
    Timezone::Lookup.config(:geonames) do |c|
      c.username = 'foo'
    end

    assert_equal Timezone::Lookup::Geonames,
                 Timezone::Lookup.lookup.class

    assert_equal Timezone::NetHTTPClient,
                 Timezone::Lookup.lookup.config.request_handler
  end

  def test_google_config
    Timezone::Lookup.config(:google) do |c|
      c.api_key = 'foo'
    end

    assert_equal Timezone::Lookup::Google,
                 Timezone::Lookup.lookup.class

    assert_equal Timezone::NetHTTPClient,
                 Timezone::Lookup.lookup.config.request_handler
  end

  def test_custom_config
    custom_lookup = Class.new do
      def initialize(config); end
    end

    Timezone::Lookup.config(custom_lookup)

    assert_equal custom_lookup, Timezone::Lookup.lookup.class
  end

  def test_missing_config
    Timezone::Lookup.instance_variable_set(:@lookup, nil)

    assert_raises Timezone::Error::InvalidConfig do
      Timezone::Lookup.lookup
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
timezone-1.3.28 test/timezone/test_lookup.rb
timezone-1.3.27 test/timezone/test_lookup.rb
timezone-1.3.26 test/timezone/test_lookup.rb