Rspecでダウンロードされたかテストする方法
viewに以下のようにsend_fileでファイルをダウンロードした時は、Rspecではcontent_type
を使うと良いらしい。
views
send_file(t.path, type: 'application/zip', dispositon: 'attachment', filename: "hoge.zip")
download_spec.rb
RSpec.describe 'ダウンロードを確認する', type: :request, js: true do
describe 'ダウンロード' do
context '正常の場合' do
it 'ダウンロードできる' do
visit admin_courses_path
click_button "ダウンロード"
expect(page.response_headers['Content-Disposition']).to include("hoge.zip")
expect(page.response_headers['Content-Type']).to eq("application/zip")
end
end
end
end
Author And Source
この問題について(Rspecでダウンロードされたかテストする方法), 我々は、より多くの情報をここで見つけました https://qiita.com/ihatov08/items/c568725d88f09a438138著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .