LoginSignup
5
4

More than 5 years have passed since last update.

Rspecでダウンロードされたかテストする方法

Posted at

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
5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4