Sha256: 7b4a97928dcea3d8b540603ce74ca30e8392a23bacbc567ccd165f79c52c0777
Contents?: true
Size: 954 Bytes
Versions: 13
Compression:
Stored size: 954 Bytes
Contents
module Marty::RSpec::DownloadHelper TIMEOUT = 10 PATH = Rails.root.join('spec/tmp/downloads') ACCEPTED_EXTS = ['.xlsx', '.csv'] extend self def downloads Dir[PATH.join("*")] end def download downloads.first end def download_content wait_for_download # doesn't work for excel files... File.read(download) end def download_content_acceptable? wait_for_download downloads.each do |f| return false unless ACCEPTED_EXTS.include? File.extname(f) end true end def wait_for_download Timeout.timeout(TIMEOUT) do sleep 0.1 until downloaded? end end def downloaded? downloads.any? && !downloading? end def downloading? downloads.grep(/\.part$/).any? || downloads.select { |f| File.size(f).zero? }.any? end def clear_downloads FileUtils.rm_f(downloads) Timeout.timeout(TIMEOUT) do sleep 0.1 until !downloads.any? end end end
Version data entries
13 entries across 13 versions & 1 rubygems