From 539e911b24d925f4e1740dfd5b59af8240b79cb3 Mon Sep 17 00:00:00 2001 From: jlhonora <jlhonora@ing.puc.cl> Date: Sun, 15 May 2016 17:07:44 -0300 Subject: [PATCH] Better naming of aliases and test for http(s) request --- test/test_helper.rb | 4 +++- test/unit/lookup_test.rb | 15 --------------- test/unit/lookups/google_test.rb | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index d0b6ca48..00055c80 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -120,7 +120,9 @@ module Geocoder fixture_exists?(filename) ? filename : default_fixture_filename end - alias_method :make_api_http_request, :make_api_request + # This alias allows us to use this method in further tests + # to actually test http requests + alias_method :actual_make_api_request, :make_api_request remove_method(:make_api_request) def make_api_request(query) diff --git a/test/unit/lookup_test.rb b/test/unit/lookup_test.rb index c4dbce13..5a91ad57 100644 --- a/test/unit/lookup_test.rb +++ b/test/unit/lookup_test.rb @@ -160,19 +160,4 @@ class LookupTest < GeocoderTestCase assert_equal :google, Geocoder::Lookup::Google.new.handle assert_equal :geocoder_ca, Geocoder::Lookup::GeocoderCa.new.handle end - - def test_http_request - Geocoder.configure(use_https: true) - - require 'webmock/test_unit' - WebMock.enable! - stub_all = WebMock.stub_request(:any, /.*/).to_return(status: 200) - - g = Geocoder::Lookup::Google.new - g.send(:make_api_http_request, Geocoder::Query.new('test location')) - assert_requested(stub_all) - - WebMock.reset! - WebMock.disable! - end end diff --git a/test/unit/lookups/google_test.rb b/test/unit/lookups/google_test.rb index 490b863d..32f147e9 100644 --- a/test/unit/lookups/google_test.rb +++ b/test/unit/lookups/google_test.rb @@ -111,4 +111,19 @@ class GoogleTest < GeocoderTestCase query = Geocoder::Query.new("Madison Square Garden, New York, NY") assert_match(/^https:/, query.url) end + + def test_actual_make_api_request_with_https + Geocoder.configure(use_https: true, lookup: :google) + + require 'webmock/test_unit' + WebMock.enable! + stub_all = WebMock.stub_request(:any, /.*/).to_return(status: 200) + + g = Geocoder::Lookup::Google.new + g.send(:actual_make_api_request, Geocoder::Query.new('test location')) + assert_requested(stub_all) + + WebMock.reset! + WebMock.disable! + end end -- GitLab