Currently, my code downloads data in the Controller using send_data. I need to write a feature test to check for the download of the file. I'm using Capybara, selenium (chrome browser). Is there a way to 1. check to see if the file has been downloaded and 2. stop the file from being created in the local download folder e.g. is there a way to intercept the download and store it in a test folder to be able to check it? Or maybe to catch the data rather than the file actually being built? Thank you for your help.
My code to create the file is simply:
send_data csv_data, type: 'text/csv; charset=utf-8; header=present', disposition: "attachment; filename=<filename>"
Ok so the answer was a small workaround that did the correct testing. :headless_chrome will put the downloaded file amongst the app, rather than into the user downloads. I found out that you can attach two drivers, both :chrome and :headless_chrome and switched between the two when I wanted to test if files were downloaded.