Sha256: 74e044e8dd0d4098699f437f16282eea8f63504d01e06ec0d7ca66c54ef9baa3

Contents?: true

Size: 963 Bytes

Versions: 3

Compression:

Stored size: 963 Bytes

Contents

require 'timezone/configure'
require 'timezone/lookup/google'
require 'test/unit'
require_relative 'http_test_client'

class GoogleLookupTest < ::Test::Unit::TestCase
  def setup
    Timezone::Configure.begin do |c|
      c.google_api_key = nil
      c.http_client = HTTPTestClient
      c.google_api_key = '123abc'
    end
  end

  def coordinates
    [-34.92771808058, 138.477041423321]
  end

  def lookup
    ::Timezone::Lookup::Google.new(Timezone::Configure)
  end

  def test_google_using_lat_lon_coordinates
    HTTPTestClient.body = File.open(mock_path + '/google_lat_lon_coords.txt').read

    assert_equal 'Australia/Adelaide', lookup.lookup(*coordinates)
  end

  def test_google_request_denied_read_lat_lon_coordinates
    assert_raise Timezone::Error::Google, 'The provided API key is invalid.' do
      lookup.lookup(*coordinates)
    end
  end

  private

  def mock_path
    File.expand_path(File.join(File.dirname(__FILE__), 'mocks'))
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
timezone-0.3.9 test/google_lookup_test.rb
timezone-0.3.8 test/google_lookup_test.rb
timezone-0.3.7 test/google_lookup_test.rb