Skip to content
Snippets Groups Projects
error_handling_test.rb 1.32 KiB
Newer Older
# encoding: utf-8
$: << File.join(File.dirname(__FILE__), "..")
require 'test_helper'

class ErrorHandlingTest < GeocoderTestCase
    Geocoder.configure(:always_raise => [])
  def test_does_not_choke_on_timeout
    # keep test output clean: suppress timeout warning
    orig = $VERBOSE; $VERBOSE = nil
    Geocoder::Lookup.all_services_except_test.each do |l|
      Geocoder.configure(:lookup => l)
Alex Reisner's avatar
Alex Reisner committed
      set_api_key!(l)
      assert_nothing_raised { Geocoder.search("timeout") }
    end
  ensure
    $VERBOSE = orig
  end

  def test_always_raise_timeout_error
    Geocoder.configure(:always_raise => [TimeoutError])
    Geocoder::Lookup.all_services_except_test.each do |l|
      next if l == :maxmind_local # local, does not raise timeout
      lookup = Geocoder::Lookup.get(l)
Alex Reisner's avatar
Alex Reisner committed
      set_api_key!(l)
      assert_raises TimeoutError do
        lookup.send(:results, Geocoder::Query.new("timeout"))
  end

  def test_always_raise_socket_error
    Geocoder.configure(:always_raise => [SocketError])
    Geocoder::Lookup.all_services_except_test.each do |l|
      next if l == :maxmind_local # local, does not raise timeout
      lookup = Geocoder::Lookup.get(l)
Alex Reisner's avatar
Alex Reisner committed
      set_api_key!(l)
      assert_raises SocketError do
        lookup.send(:results, Geocoder::Query.new("socket_error"))