Skip to content

Commit

Permalink
update Downloads helpers to use synchronize (#1143)
Browse files Browse the repository at this point in the history
Use Capybara's built-in `synchronize` method rather than handling the
timeout ourselves.
  • Loading branch information
mockdeep authored Jan 13, 2024
1 parent fed945d commit 9ac411e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
19 changes: 5 additions & 14 deletions spec/support/downloads.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
# frozen_string_literal: true

module Downloads
TIMEOUT = Capybara.default_max_wait_time
PATH = Rails.root.join("tmp/downloads")
PATH = Rails.root.join("tmp/downloads")

class << self
def clear
FileUtils.rm_f(downloads)
end

def content_for(filename)
wait_for_download(filename)

File.read(PATH.join(filename))
def content_for(page, filename)
page.document.synchronize(errors: [Errno::ENOENT]) do
File.read(PATH.join(filename))
end
end

private

def downloads
Dir[PATH.join("*")]
end

def wait_for_download(filename)
Timeout.timeout(TIMEOUT) { sleep(0.1) until downloaded?(filename) }
end

def downloaded?(filename)
File.exist?(PATH.join(filename))
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/system/export_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

click_on "Export"

xml = Capybara.string(Downloads.content_for("stringer.opml"))
xml = Capybara.string(Downloads.content_for(page, "stringer.opml"))
expect(xml).to have_css("outline[title='#{feed.name}']")
end
end

0 comments on commit 9ac411e

Please sign in to comment.