forked from geokit/geokit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_net_adapter.rb
45 lines (38 loc) · 1.12 KB
/
test_net_adapter.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require File.join(File.dirname(__FILE__), 'helper')
# Base class for testing geocoders.
class NetAdapterTest < Test::Unit::TestCase #:nodoc: all
class Geokit::Geocoders::CachedGeocoder < Geokit::Geocoders::Geocoder
def self.parse_json(hash)
hash
end
end
class SuperSimpleCache
def initialize
@cache = {}
end
def write(key, value)
@cache[key] = value
end
def fetch(key)
@cache[key]
end
end
RESULT = '{"name":"json"}'
RESULT_HASH = {'name' => 'json'}
# Defines common test fixtures.
def setup
@url = 'http://www.cacheme.com'
@address = 'San Francisco, CA'
end
def test_cache
old_adapter = Geokit::Geocoders.net_adapter
Geokit::Geocoders.net_adapter = Geokit::NetAdapter::Typhoeus
Typhoeus::Config.cache = SuperSimpleCache
success = MockSuccess.new
success.expects(:body).returns(RESULT)
Geokit::NetAdapter::Typhoeus.expects(:do_get).with(@url).returns(success)
assert_equal RESULT_HASH, Geokit::Geocoders::CachedGeocoder.process(:json, @url)
Typhoeus::Config.cache = nil
Geokit::Geocoders.net_adapter = old_adapter
end
end