Rails MiniTestでCSVファイルを返すControllerをテストしたい
CSVデータファイルを返すControllerがあり、
そのCSVデータの中身を次のようにテストしました。
Controller側
def create_csv
<略>
respond_to do |format|
format.csv {
send_data records.to_csv, :type => 'text/csv', :filename => 'test.csv'
return
}
end
end
TestCode側
(次の例では各行が'数字,数字,数字'になっていることを確認)
describe "create_csv" do
it "return csv file" do
get :create_csv
response.body.each_line |line| do
assert_match /\d,\d,\d/, line
end
end
end