Sha256: 0f084ef7bd50070011838a0089e04567ec4156f398422f1eadba91386e94ac8b
Contents?: true
Size: 976 Bytes
Versions: 50
Compression:
Stored size: 976 Bytes
Contents
# frozen_string_literal: true module DownloadHelper TIMEOUT = 10 PATH = Rails.root.join("tmp/downloads").freeze def downloads(name = nil) Dir[PATH.join(name || "*")] end def download_path(name = nil) wait_for_download(name) downloads(name).first end def download_content(name = nil) wait_for_download(name) File.read(download_path(name)) end def wait_for_download(name = nil) Timeout.timeout(TIMEOUT) do sleep 0.1 until downloaded?(name) end end def downloaded?(name = nil) downloads(name).any? && !downloading? end def downloading? downloads.grep(/\.crdownload$/).any? end def clear_downloads FileUtils.rm_f(downloads) end end RSpec.configure do |config| config.include DownloadHelper, download: true config.before :each, download: true do FileUtils.mkdir_p DownloadHelper::PATH.to_s page.driver.browser.download_path = DownloadHelper::PATH.to_s clear_downloads end end
Version data entries
50 entries across 50 versions & 1 rubygems