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

Merge branch 'test_mode' of git://github.com/mguterl/geocoder into mguterl-test_mode

parents e538e23e 43046a2b
No related branches found
No related tags found
No related merge requests found
......@@ -55,29 +55,5 @@ module Geocoder
END
end
def self.test_mode=(test_mode)
if test_mode
@original_lookup = lookup
self.lookup = :test
else
self.lookup = @original_lookup
end
end
def self.add_stub(query, results)
stubs[query] = results
end
def self.read_stub(query)
stubs.fetch(query) { raise ArgumentError, "unknown stub request #{query}" }
end
def self.stubs
@stubs ||= {}
end
def self.reset_stubs
@stubs = {}
end
end
end
......@@ -5,10 +5,26 @@ module Geocoder
module Lookup
class Test < Base
def self.add_stub(query, results)
stubs[query] = results
end
def self.read_stub(query)
stubs.fetch(query) { raise ArgumentError, "unknown stub request #{query}" }
end
def self.stubs
@stubs ||= {}
end
def self.reset
@stubs = {}
end
private
def results(query, reverse = false)
Geocoder::Configuration.read_stub(query)
Geocoder::Lookup::Test.read_stub(query)
end
end
......
require 'test_helper'
require 'geocoder/lookups/test'
class TestModeTest < Test::Unit::TestCase
def setup
@_original_lookup = Geocoder::Configuration.lookup
end
def teardown
Geocoder::Configuration.reset_stubs
Geocoder::Lookup::Test.reset
Geocoder::Configuration.lookup = @_original_lookup
end
def test_search_with_known_stub
Geocoder::Configuration.test_mode = true
Geocoder::Configuration.lookup = :test
attributes = {
'latitude' => 40.7143528,
'longitude' => -74.0059731,
......@@ -19,7 +25,7 @@ class TestModeTest < Test::Unit::TestCase
}
coordinates = [attributes['latitude'], attributes['longitude']]
Geocoder::Configuration.add_stub("New York, NY", [attributes])
Geocoder::Lookup::Test.add_stub("New York, NY", [attributes])
results = Geocoder.search("New York, NY")
assert_equal 1, results.size
......@@ -36,19 +42,11 @@ class TestModeTest < Test::Unit::TestCase
end
def test_search_with_unknown_stub
Geocoder::Configuration.test_mode = true
Geocoder::Configuration.lookup = :test
assert_raise ArgumentError do
Geocoder.search("New York, NY")
end
end
def test_turning_off_test_mode_restores_lookup
original_lookup = Geocoder::Configuration.lookup
Geocoder::Configuration.test_mode = true
Geocoder::Configuration.test_mode = false
assert_equal original_lookup, Geocoder::Configuration.lookup
end
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