From 3a0e35209a7ec9264a95728fca044be1917b4112 Mon Sep 17 00:00:00 2001 From: Nick Hammond Date: Thu, 14 Apr 2022 07:15:05 -0700 Subject: [PATCH] Add a simple download spec and mention save_path in the readme --- README.md | 1 + spec/download_spec.rb | 20 ++++++++++++++++++++ spec/support/application.rb | 6 ++++++ 3 files changed, 27 insertions(+) create mode 100644 spec/download_spec.rb diff --git a/README.md b/README.md index 36f9d034..abd5d452 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,7 @@ Ferrum::Browser.new(options) over the web socket, in bytes. Defaults to 64MB. Incoming messages larger than this will cause a `Ferrum::DeadBrowserError`. * `:proxy` (Hash) - Specify proxy settings, [read more](https://github.com/rubycdp/ferrum#proxy) + * `:save_path` (String) - Path to save screenshots, PDF, mhtml, and attachment requests ## Navigation diff --git a/spec/download_spec.rb b/spec/download_spec.rb new file mode 100644 index 00000000..6e71a5a2 --- /dev/null +++ b/spec/download_spec.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Ferrum + describe Browser do + context "download support" do + let(:browser) do + Ferrum::Browser.new( + base_url: Ferrum::Server.server.base_url, + save_path: "/tmp/ferrum" + ) + end + + it "saves an attachment" do + browser.go_to("/attachment.pdf") + + expect(File.exist?("/tmp/ferrum/attachment.pdf")).to be true + end + end + end +end diff --git a/spec/support/application.rb b/spec/support/application.rb index ae93c87c..76118f6e 100644 --- a/spec/support/application.rb +++ b/spec/support/application.rb @@ -182,6 +182,12 @@ def initialize(something, message) "This, is, comma, separated" end + get "/attachment.pdf" do + path = "/tmp/ferrum/attachment.pdf" + FileUtils.touch(path) + attachment(path, :attachment) + end + get "/:view" do |view| erb view.to_sym, locals: { referrer: request.referrer } end