Permalink
Browse files

Made Configuration set defaults when the Configuration class loads an…

…d removed use of eval.

Removed set_defaults from all tests and replaced with teardown to reset the defaults.

Signed-off-by: James McCarthy <james2mccarthy@gmail.com>
  • Loading branch information...
1 parent df0ee95 commit 89d02171133e545ce17bb995e5a7e1e984a5ad35 @james2m james2m committed Jul 21, 2011
@@ -38,20 +38,21 @@ def self.options_and_defaults
end
# define getters and setters for all configuration settings
- self.options_and_defaults.each do |o,d|
- eval("def self.#{o}; @@#{o}; end")
- eval("def self.#{o}=(obj); @@#{o} = obj; end")
+ self.options_and_defaults.each do |option, default|
+ class_eval(<<-END, __FILE__, __LINE__ + 1)
+
+ @@#{option} = default unless defined? @@#{option}
+
+ def self.#{option}
+ @@#{option}
+ end
+
+ def self.#{option}=(obj)
+ @@#{option} = obj
+ end
+
+ END
end
- ##
- # Set all values to default.
- #
- def self.set_defaults
- self.options_and_defaults.each do |o,d|
- self.send("#{o}=", d)
- end
- end
end
-end
-
-Geocoder::Configuration.set_defaults
+end
@@ -9,4 +9,5 @@ def test_exception_raised_on_bad_lookup_config
Geocoder.search "something dumb"
end
end
+
end
@@ -3,10 +3,6 @@
class CustomBlockTest < Test::Unit::TestCase
- def setup
- Geocoder::Configuration.set_defaults
- end
-
def test_geocode_with_block_runs_block
e = Event.new(*venue_params(:msg))
coords = [40.750354, -73.993371]
@@ -3,10 +3,6 @@
class ErrorHandlingTest < Test::Unit::TestCase
- def setup
- Geocoder::Configuration.set_defaults
- end
-
def test_does_not_choke_on_timeout
# keep test output clean: suppress timeout warning
orig = $VERBOSE; $VERBOSE = nil
View
@@ -3,10 +3,6 @@
class GeocoderTest < Test::Unit::TestCase
- def setup
- Geocoder::Configuration.set_defaults
- end
-
def test_distance_to_returns_float
v = Venue.new(*venue_params(:msg))
v.latitude, v.longitude = [40.750354, -73.993371]
View
@@ -3,10 +3,6 @@
class HttpsTest < Test::Unit::TestCase
- def setup
- Geocoder::Configuration.set_defaults
- end
-
def test_uses_https_for_secure_query
Geocoder::Configuration.use_https = true
g = Geocoder::Lookup::Google.new
@@ -3,10 +3,6 @@
class MethodAliasesTest < Test::Unit::TestCase
- def setup
- Geocoder::Configuration.set_defaults
- end
-
def test_distance_from_is_alias_for_distance_to
v = Venue.new(*venue_params(:msg))
v.latitude, v.longitude = [40.750354, -73.993371]
View
@@ -7,10 +7,6 @@
class MongoidTest < Test::Unit::TestCase
- def setup
- Geocoder::Configuration.set_defaults
- end
-
def test_geocoded_check
p = Place.new(*venue_params(:msg))
p.location = [40.750354, -73.993371]
View
@@ -3,10 +3,6 @@
class ProxyTest < Test::Unit::TestCase
- def setup
- Geocoder::Configuration.set_defaults
- end
-
def test_uses_proxy_when_specified
Geocoder::Configuration.http_proxy = 'localhost'
lookup = Geocoder::Lookup::Google.new
View
@@ -3,10 +3,6 @@
class ServicesTest < Test::Unit::TestCase
- def setup
- Geocoder::Configuration.set_defaults
- end
-
# --- Google ---
View
@@ -224,6 +224,12 @@ def initialize(name)
class Test::Unit::TestCase
+
+ def teardown
+ Geocoder.send(:remove_const, :Configuration)
+ load "geocoder/configuration.rb"
+ end
+
def venue_params(abbrev)
{
:msg => ["Madison Square Garden", "4 Penn Plaza, New York, NY"]

0 comments on commit 89d0217

Please sign in to comment.