From 9ac411eb526e7d1ef1572fd1d31afdc5c1e2ac6c Mon Sep 17 00:00:00 2001 From: Robert Fletcher Date: Sat, 13 Jan 2024 10:37:12 -0800 Subject: [PATCH] update Downloads helpers to use synchronize (#1143) Use Capybara's built-in `synchronize` method rather than handling the timeout ourselves. --- spec/support/downloads.rb | 19 +++++-------------- spec/system/export_spec.rb | 2 +- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/spec/support/downloads.rb b/spec/support/downloads.rb index ec2d15240..7dabe5b76 100644 --- a/spec/support/downloads.rb +++ b/spec/support/downloads.rb @@ -1,18 +1,17 @@ # 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 @@ -20,14 +19,6 @@ def content_for(filename) 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 diff --git a/spec/system/export_spec.rb b/spec/system/export_spec.rb index 364176d46..4e1f4109a 100644 --- a/spec/system/export_spec.rb +++ b/spec/system/export_spec.rb @@ -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