From 175b2815d6948e2ccca987204a03f87edbd96833 Mon Sep 17 00:00:00 2001
From: "Peter M. Goldstein" <peter.m.goldstein@gmail.com>
Date: Tue, 31 Jul 2012 10:52:46 -0700
Subject: [PATCH] Get tests running green under JRuby

---
 Gemfile                      |  8 ++++++--
 lib/geocoder/lookups/base.rb |  1 +
 test/calculations_test.rb    | 10 +++++-----
 test/test_helper.rb          |  9 +++++++++
 4 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/Gemfile b/Gemfile
index 19d94cd4..b114997e 100644
--- a/Gemfile
+++ b/Gemfile
@@ -5,7 +5,11 @@ gemspec
 group :development, :test do
   gem 'rake'
   gem 'mongoid'
-  gem 'bson_ext'
+  gem 'bson_ext', :platforms => :ruby
 
   gem 'rails'
-end
\ No newline at end of file
+
+  platforms :jruby do
+  	gem 'jruby-openssl'
+  end
+end
diff --git a/lib/geocoder/lookups/base.rb b/lib/geocoder/lookups/base.rb
index 6c80e5ec..fddf8a0d 100644
--- a/lib/geocoder/lookups/base.rb
+++ b/lib/geocoder/lookups/base.rb
@@ -1,4 +1,5 @@
 require 'net/http'
+require 'net/https'
 require 'uri'
 
 unless defined?(ActiveSupport::JSON)
diff --git a/test/calculations_test.rb b/test/calculations_test.rb
index ee18f836..4f9fef0d 100644
--- a/test/calculations_test.rb
+++ b/test/calculations_test.rb
@@ -152,24 +152,24 @@ class CalculationsTest < Test::Unit::TestCase
 
   def test_extract_coordinates
     result = Geocoder::Calculations.extract_coordinates([ nil, nil ])
-    assert_equal [ Geocoder::Calculations::NAN ] * 2, result
+    assert is_nan_coordinates?(result)
 
     result = Geocoder::Calculations.extract_coordinates([ 1.0 / 3, 2.0 / 3 ])
     assert_in_delta 1.0 / 3, result.first, 1E-5
     assert_in_delta 2.0 / 3, result.last, 1E-5
 
     result = Geocoder::Calculations.extract_coordinates(nil)
-    assert_equal [ Geocoder::Calculations::NAN ] * 2, result
+    assert is_nan_coordinates?(result)
 
     result = Geocoder::Calculations.extract_coordinates('')
-    assert_equal [ Geocoder::Calculations::NAN ] * 2, result
+    assert is_nan_coordinates?(result)
 
     result = Geocoder::Calculations.extract_coordinates([ 'nix' ])
-    assert_equal [ Geocoder::Calculations::NAN ] * 2, result
+    assert is_nan_coordinates?(result)
 
     o = Object.new
     result = Geocoder::Calculations.extract_coordinates(o)
-    assert_equal [ Geocoder::Calculations::NAN ] * 2, result
+    assert is_nan_coordinates?(result)
 
     def o.to_coordinates
       [ 1.0 / 3, 2.0 / 3 ]
diff --git a/test/test_helper.rb b/test/test_helper.rb
index f0c1dbfe..ba48c172 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -271,5 +271,14 @@ class Test::Unit::TestCase
   def street_lookups
     all_lookups - [:freegeoip]
   end
+
+  def is_nan_coordinates?(coordinates)
+    if defined?(::Float::NAN)
+      coordinates == ([ Geocoder::Calculations::NAN ] * 2 )
+    else
+      return false unless coordinates.respond_to? :size 
+      coordinates.size == 2 && coordinates[0].nan? && coordinates[1].nan?
+    end
+  end
 end
 
-- 
GitLab