Class: Capybara::Cuprite::Downloads
- Inherits:
-
Object
- Object
- Capybara::Cuprite::Downloads
- Defined in:
- lib/cuprite/downloads.rb
Defined Under Namespace
Classes: NotFound
Class Method Summary collapse
Instance Method Summary collapse
- #[](filename, wait: Capybara.default_max_wait_time) ⇒ Object
- #dir ⇒ Object
- #filenames ⇒ Object
- #pathname ⇒ Object
- #reset ⇒ Object
Class Method Details
.pathname ⇒ Object
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 .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: .default_max_wait_time .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 |
#dir ⇒ Object
22 23 24 |
# File 'lib/cuprite/downloads.rb', line 22 def dir pathname.to_s end |
#filenames ⇒ Object
31 32 33 |
# File 'lib/cuprite/downloads.rb', line 31 def filenames pathname.entries.reject(&:directory?).map(&:to_s) end |
#pathname ⇒ Object
18 19 20 |
# File 'lib/cuprite/downloads.rb', line 18 def pathname self.class.pathname end |
#reset ⇒ Object
26 27 28 29 |
# File 'lib/cuprite/downloads.rb', line 26 def reset FileUtils.rm_rf(dir) FileUtils.mkdir_p(dir) end |