From 54071081cfe79e48dec8204b25203632d6b150ce Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 21 Dec 2012 15:22:45 -0500 Subject: [PATCH] Test for invalid key warning/exceptions in loop. --- test/lookup_test.rb | 24 ++++++++++++++++++++++++ test/services_test.rb | 39 --------------------------------------- 2 files changed, 24 insertions(+), 39 deletions(-) diff --git a/test/lookup_test.rb b/test/lookup_test.rb index 6e77e4ba..6ad02c52 100644 --- a/test/lookup_test.rb +++ b/test/lookup_test.rb @@ -20,6 +20,30 @@ class LookupTest < Test::Unit::TestCase end end + def test_raises_exception_on_invalid_key + Geocoder.configure(:always_raise => [Geocoder::InvalidApiKey]) + #Geocoder::Lookup.all_services_except_test.each do |l| + [:yahoo, :yandex, :maxmind].each do |l| + lookup = Geocoder::Lookup.get(l) + assert_raises Geocoder::InvalidApiKey do + lookup.send(:results, Geocoder::Query.new("invalid key")) + end + end + end + + def test_warns_about_invalid_key + # keep test output clean: suppress timeout warning + orig = $VERBOSE; $VERBOSE = nil + #Geocoder::Lookup.all_services_except_test.each do |l| + [:yahoo, :yandex, :maxmind].each do |l| + Geocoder.configure(:lookup => l) + set_api_key!(l) + assert_equal [], Geocoder.search("invalid key") + end + ensure + $VERBOSE = orig + end + def test_does_not_choke_on_nil_address Geocoder::Lookup.all_services.each do |l| Geocoder.configure(:lookup => l) diff --git a/test/services_test.rb b/test/services_test.rb index 9c232a85..9174c0c6 100644 --- a/test/services_test.rb +++ b/test/services_test.rb @@ -113,35 +113,6 @@ class ServicesTest < Test::Unit::TestCase end end - def test_yahoo_raises_exception_on_invalid_key - Geocoder.configure(:always_raise => [Geocoder::InvalidApiKey]) - l = Geocoder::Lookup.get(:yahoo) - assert_raises Geocoder::InvalidApiKey do - l.send(:results, Geocoder::Query.new("invalid key")) - end - end - - # --- Yandex --- - - def test_yandex_warns_about_invalid_key - # keep test output clean: suppress timeout warning - orig = $VERBOSE; $VERBOSE = nil - Geocoder.configure(:lookup => :yandex) - set_api_key!(:yandex) - assert_equal [], Geocoder.search("invalid key") - ensure - $VERBOSE = orig - end - - def test_yandex_raises_exception_on_invalid_key - Geocoder.configure(:always_raise => [Geocoder::InvalidApiKey]) - l = Geocoder::Lookup.get(:yandex) - assert_raises Geocoder::InvalidApiKey do - l.send(:results, Geocoder::Query.new("invalid key")) - end - end - - # --- Geocoder.ca --- def test_geocoder_ca_result_components @@ -179,16 +150,6 @@ class ServicesTest < Test::Unit::TestCase assert_equal "Plano, TX 75093, US", result.address end - def test_maxmind_raises_exception_on_invalid_key - Geocoder.configure( - :always_raise => [Geocoder::InvalidApiKey] - ) - l = Geocoder::Lookup.get(:maxmind) - assert_raises Geocoder::InvalidApiKey do - l.send(:results, Geocoder::Query.new("invalid key")) - end - end - # --- Bing --- -- GitLab