Precondition
- You are not using javascript tests
- The file is served from a public folder (not via controller)
Problem description
If you deliver files from a public folder it might be that the Content-Disposition
header is not set. That's why the following
spreewald
Show archive.org snapshot
step might raise an error:
Then I should get a download with filename "..."
expected: /filename="some.pdf"$/
got: nil (using =~) (RSpec::Expectations::ExpectationNotMetError)
Solution
One solution is to check the Content-Type
header only with the following
spreewald
Show archive.org snapshot
step:
Then I should get a response with content-type "..."
Outline
How to test file downloads with tests that need javascript.
Public served
- Look at the link of the url and check if this file exists in your public folder (Example for an image)
Server via controller
- Write an own step which downloads the file and then makes tests with it (you can not check the url because this would be something like
localhost:3000/users/4/avatar/3
) - Override the
send_file
method of your controller (maybe application controller is also fine): If you are in the test suite return a text with the name of the file. Otherwisesuper
.
Read the browser downloads folder
Posted by Emanuel to makandra dev (2017-09-21 08:57)