Skip to content

Commit

Permalink
[rb] fix test not handling redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Oct 19, 2021
1 parent b67f59f commit 9816645
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
26 changes: 13 additions & 13 deletions rb/lib/selenium/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions rb/spec/unit/selenium/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 9816645

Please sign in to comment.