Skip to content
Snippets Groups Projects
Commit 3cc4a205 authored by Alex Reisner's avatar Alex Reisner
Browse files

Make all tests pass after adding :test lookup.

parent be30749d
No related branches found
No related tags found
No related merge requests found
......@@ -4,26 +4,12 @@ module Geocoder
module Result
class Test < Base
def address
@data['address']
%w[latitude longitude city state state_code province
province_code postal_code country country_code address].each do |attr|
define_method(attr) do
@data[attr.to_s] || @data[attr.to_sym]
end
end
def state
@data['state']
end
def state_code
@data['state_code']
end
def country
@data['country']
end
def country_code
@data['country_code']
end
end
end
end
......@@ -10,7 +10,7 @@ class ErrorHandlingTest < Test::Unit::TestCase
def test_does_not_choke_on_timeout
# keep test output clean: suppress timeout warning
orig = $VERBOSE; $VERBOSE = nil
all_lookups.each do |l|
all_lookups_except_test.each do |l|
Geocoder::Configuration.lookup = l
assert_nothing_raised { Geocoder.search("timeout") }
end
......@@ -19,7 +19,7 @@ class ErrorHandlingTest < Test::Unit::TestCase
def test_always_raise_timeout_error
Geocoder::Configuration.always_raise = [TimeoutError]
all_lookups.each do |l|
all_lookups_except_test.each do |l|
lookup = Geocoder.send(:get_lookup, l)
assert_raises TimeoutError do
lookup.send(:results, "timeout")
......@@ -29,7 +29,7 @@ class ErrorHandlingTest < Test::Unit::TestCase
def test_always_raise_socket_error
Geocoder::Configuration.always_raise = [SocketError]
all_lookups.each do |l|
all_lookups_except_test.each do |l|
lookup = Geocoder.send(:get_lookup, l)
assert_raises SocketError do
lookup.send(:results, "socket_error")
......
......@@ -4,7 +4,7 @@ require 'test_helper'
class LookupTest < Test::Unit::TestCase
def test_search_returns_empty_array_when_no_results
all_lookups.each do |l|
all_lookups_except_test.each do |l|
lookup = Geocoder.send(:get_lookup, l)
assert_equal [], lookup.send(:results, "no results"),
"Lookup #{l} does not return empty array when no results."
......
......@@ -4,7 +4,7 @@ require 'test_helper'
class ResultTest < Test::Unit::TestCase
def test_result_has_required_attributes
all_lookups.each do |l|
all_lookups_except_test.each do |l|
Geocoder::Configuration.lookup = l
result = Geocoder.search([45.423733, -75.676333]).first
assert_result_has_required_attributes(result)
......
......@@ -281,6 +281,10 @@ class Test::Unit::TestCase
Geocoder.valid_lookups
end
def all_lookups_except_test
Geocoder.valid_lookups - [:test]
end
def street_lookups
all_lookups - [:freegeoip]
end
......
......@@ -5,6 +5,7 @@ class TestModeTest < Test::Unit::TestCase
def setup
@_original_lookup = Geocoder::Configuration.lookup
Geocoder::Configuration.lookup = :test
end
def teardown
......@@ -13,17 +14,17 @@ class TestModeTest < Test::Unit::TestCase
end
def test_search_with_known_stub
Geocoder::Configuration.lookup = :test
coordinates = [40.7143528, -74.0059731]
attributes = {
'latitude' => 40.7143528,
'longitude' => -74.0059731,
'address' => 'New York, NY, USA',
'state' => 'New York',
'state_code' => 'NY',
'country' => 'United States',
'coordinates' => coordinates,
'latitude' => coordinates[0],
'longitude' => coordinates[1],
'address' => 'New York, NY, USA',
'state' => 'New York',
'state_code' => 'NY',
'country' => 'United States',
'country_code' => 'US',
}
coordinates = [attributes['latitude'], attributes['longitude']]
Geocoder::Lookup::Test.add_stub("New York, NY", [attributes])
......@@ -42,8 +43,6 @@ class TestModeTest < Test::Unit::TestCase
end
def test_search_with_unknown_stub
Geocoder::Configuration.lookup = :test
assert_raise ArgumentError do
Geocoder.search("New York, NY")
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment