Class: Capybara::Cuprite::Downloads

Inherits:
Object
  • Object
show all
Defined in:
lib/cuprite/downloads.rb

Defined Under Namespace

Classes: NotFound

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.pathnameObject



11
12
13
14
15
16
# 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

Instance Method Details

#[](filename, wait: Capybara.default_max_wait_time) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/cuprite/downloads.rb', line 35

def [] filename, wait: Capybara.default_max_wait_time
  Capybara.current_session.document.synchronize(wait, errors: [NotFound]) do
    begin
      File.open(pathname.join(filename))
    rescue Errno::ENOENT
      raise NotFound.new("Couldn't find #{filename} in #{filenames}")
    end
  end
end

#dirObject



22
23
24
# File 'lib/cuprite/downloads.rb', line 22

def dir
  pathname.to_s
end

#filenamesObject



31
32
33
# File 'lib/cuprite/downloads.rb', line 31

def filenames
  pathname.entries.reject(&:directory?).map(&:to_s)
end

#pathnameObject



18
19
20
# File 'lib/cuprite/downloads.rb', line 18

def pathname
  self.class.pathname
end

#resetObject



26
27
28
29
# File 'lib/cuprite/downloads.rb', line 26

def reset
  FileUtils.rm_rf(dir)
  FileUtils.mkdir_p(dir)
end