class Capybara::HeadlessChrome::Downloads

Public Instance Methods

[](filename) click to toggle source
# File lib/capybara/headless_chrome/downloads.rb, line 22
def [] filename
  Capybara.current_session.document.synchronize do
    begin
      File.open(pathname.join(filename))
    rescue Errno::ENOENT
      raise NotFound.new("Couldn't find #{filename} in #{filenames}")
    end
  end
end
dir() click to toggle source
# File lib/capybara/headless_chrome/downloads.rb, line 9
def dir
  pathname.to_s
end
filenames() click to toggle source
# File lib/capybara/headless_chrome/downloads.rb, line 18
def filenames
  pathname.entries.reject(&:directory?).map(&:to_s)
end
reset() click to toggle source
# File lib/capybara/headless_chrome/downloads.rb, line 13
def reset
  FileUtils.rm_rf(dir)
  FileUtils.mkdir_p(dir)
end

Private Instance Methods

pathname() click to toggle source
# File lib/capybara/headless_chrome/downloads.rb, line 34
def pathname
  @pathname ||= Capybara.save_path.join(unique_id, "downloads")
end
unique_id() click to toggle source
# File lib/capybara/headless_chrome/downloads.rb, line 38
def unique_id
  Time.now.strftime('%s%L')
end