Skip to content

Commit

Permalink
Add a simple download spec and mention save_path in the readme
Browse files Browse the repository at this point in the history
  • Loading branch information
nickhammond committed Apr 14, 2022
1 parent 2c087c5 commit 3a0e352
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions spec/download_spec.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions spec/support/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3a0e352

Please sign in to comment.