2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-07-20 17:20:12 +02:00
|
|
|
module DownloadHelpers
|
|
|
|
TIMEOUT = 2
|
|
|
|
|
|
|
|
extend self
|
|
|
|
|
|
|
|
def downloads
|
|
|
|
Dir[Capybara.save_path.join("*.zip")]
|
|
|
|
end
|
|
|
|
|
|
|
|
def download
|
|
|
|
downloads.first
|
|
|
|
end
|
|
|
|
|
|
|
|
def download_content
|
|
|
|
wait_for_download
|
|
|
|
File.read(download)
|
|
|
|
end
|
|
|
|
|
|
|
|
def wait_for_download
|
|
|
|
Timeout.timeout(TIMEOUT) do
|
|
|
|
sleep 0.1 until downloaded?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def downloaded?
|
|
|
|
!downloading? && downloads.any?
|
|
|
|
end
|
|
|
|
|
|
|
|
def downloading?
|
|
|
|
downloads.grep(/\.part$/).any?
|
|
|
|
end
|
|
|
|
|
|
|
|
def clear_downloads
|
|
|
|
FileUtils.rm_f(downloads)
|
|
|
|
end
|
|
|
|
end
|