class Capybara::Cuprite::Downloads

Public Class Methods

pathname() click to toggle source
# File lib/cuprite/downloads.rb, line 11
def self.pathname
  @pathname ||= begin
    unique_id = Time.now.strftime('%s%L') # to keep concurrent runs from colliding
    Capybara.save_path.join(unique_id, "downloads")
 end
end

Public Instance Methods

[](filename) click to toggle source
# File lib/cuprite/downloads.rb, line 35
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/cuprite/downloads.rb, line 22
def dir
  pathname.to_s
end
filenames() click to toggle source
# File lib/cuprite/downloads.rb, line 31
def filenames
  pathname.entries.reject(&:directory?).map(&:to_s)
end
pathname() click to toggle source
# File lib/cuprite/downloads.rb, line 18
def pathname
  self.class.pathname
end
reset() click to toggle source
# File lib/cuprite/downloads.rb, line 26
def reset
  FileUtils.rm_rf(dir)
  FileUtils.mkdir_p(dir)
end