diff --git a/rb/lib/selenium/server.rb b/rb/lib/selenium/server.rb index b68b96c61349e..002766fd45583 100644 --- a/rb/lib/selenium/server.rb +++ b/rb/lib/selenium/server.rb @@ -90,8 +90,8 @@ def download(required_version = :latest) File.open(download_file_name, 'wb') do |destination| net_http_start('github-releases.githubusercontent.com') do |http| - request = Net::HTTP::Get.new redirected - resp = http.request(request) do |response| + request = Net::HTTP::Get.new redirected + resp = http.request(request) do |response| total = response.content_length progress = 0 segment_count = 0 @@ -127,17 +127,17 @@ def download(required_version = :latest) def latest @latest ||= begin - net_http_start('api.github.com') do |http| - json = http.get('/repos/seleniumhq/selenium/releases').body - JSON.parse(json).map { |release| - release['assets'] - }.flatten.map { |asset| - asset['name'][/selenium-server-(\d+\.\d+\.\d+)\.jar/, 1] - }.compact.map { |version| - Gem::Version.new(version) - }.max.version - end - end + net_http_start('api.github.com') do |http| + json = http.get('/repos/seleniumhq/selenium/releases').body + JSON.parse(json).map { |release| + release['assets'] + }.flatten.map { |asset| + asset['name'][/selenium-server-(\d+\.\d+\.\d+)\.jar/, 1] + }.compact.map { |version| + Gem::Version.new(version) + }.max.version + end + end end # @api private diff --git a/rb/spec/unit/selenium/server_spec.rb b/rb/spec/unit/selenium/server_spec.rb index d482641ed0f91..3e727dc6cff8b 100644 --- a/rb/spec/unit/selenium/server_spec.rb +++ b/rb/spec/unit/selenium/server_spec.rb @@ -116,6 +116,9 @@ module Selenium download = 'https://github.com/seleniumhq/selenium/releases/download' stub_request(:get, "#{download}/selenium-10.0.0/#{expected_download_file_name}") + .to_return(headers: {location: 'https://github-releases.githubusercontent.com/something'}) + + stub_request(:get, "https://github-releases.githubusercontent.com/something") .to_return(body: 'this is pretending to be a jar file for testing purposes') begin @@ -175,8 +178,7 @@ module Selenium "assets": { "name": 'selenium-server-10.0.1.jar', "browser_download_url": "#{repo}/selenium-10.0.1/selenium-server-10.0.1.jar" - }} - ] + }}] stub_request(:get, repo).to_return(body: example_json.to_json)