Skip to content
This repository has been archived by the owner on Apr 1, 2019. It is now read-only.

Commit

Permalink
Merge branch 'ibrahima-63-latest-version-fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Sep 19, 2018
2 parents cb7f465 + 3a1fac1 commit c7c989f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
8 changes: 3 additions & 5 deletions lib/chromedriver/helper/google_code_parser.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
require 'nokogiri'
require 'open-uri'
require 'uri'

module Chromedriver
class Helper
class GoogleCodeParser
BUCKET_URL = 'https://chromedriver.storage.googleapis.com'

attr_reader :source, :platform
attr_reader :source, :platform, :newest_download_version

def initialize(platform, open_uri_provider=OpenURI)
@platform = platform
@source = open_uri_provider.open_uri(BUCKET_URL)
@newest_download_version = Gem::Version.new(open_uri_provider.open_uri(URI.join(BUCKET_URL, "LATEST_RELEASE")).read)
end

def downloads
Expand All @@ -22,10 +24,6 @@ def downloads
end
end

def newest_download_version
@newest_download_version ||= downloads.map { |download| version_of(download) }.max
end

def version_download_url(version)
gem_version = Gem::Version.new(version)
downloads.find { |download_url| version_of(download_url) == gem_version }
Expand Down
26 changes: 9 additions & 17 deletions spec/google_code_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
describe Chromedriver::Helper::GoogleCodeParser do
let!(:open_uri_provider) do
double("open_uri_provider").tap do |oup|
allow(oup).to receive(:open_uri) { File.read(File.join(File.dirname(__FILE__), "assets/google-code-bucket.xml")) }
allow(oup).to receive(:open_uri) do |uri|
case uri.to_s
when "https://chromedriver.storage.googleapis.com/LATEST_RELEASE"
StringIO.new("2.42")
when "https://chromedriver.storage.googleapis.com"
StringIO.new(File.read(File.join(File.dirname(__FILE__), "assets/google-code-bucket.xml")))
end
end
end
end
let!(:parser) { Chromedriver::Helper::GoogleCodeParser.new('mac', open_uri_provider) }
Expand All @@ -21,22 +28,7 @@

describe "#newest_download_version" do
it "returns the last URL for the platform" do
expect(parser.newest_download_version).to eq Gem::Version.new("2.4")
end

context "out-of-order versions" do
before do
allow(parser).to receive(:downloads).and_return([
"https://chromedriver.storage.googleapis.com/2.3/chromedriver_mac32.zip",
"https://chromedriver.storage.googleapis.com/2.4/chromedriver_mac32.zip",
"https://chromedriver.storage.googleapis.com/2.14/chromedriver_mac32.zip",
"https://chromedriver.storage.googleapis.com/2.2/chromedriver_mac32.zip",
])
end

it "returns the newest version" do
expect(parser.newest_download_version).to eq(Gem::Version.new("2.14"))
end
expect(parser.newest_download_version).to eq Gem::Version.new("2.42")
end
end

Expand Down

0 comments on commit c7c989f

Please sign in to comment.