我想测试一个看起来像这样的函数。
def load_template_from_csv
arr = []
images = []
CSV.new(open(params[:a_csv]), headers: true).each_with_index do |row, index|
# some formating
res << {row}
end
render json: { data: res }
end
我尝试过像
这样的事情it 'tests load_ad_template_from_csv action' do
account_id = Account.last.id
get :load_template_from_csv, internal_ad_account_id: ad_account_id, ad_csv: 'test'
# expect(File).to receive(:open).with('test', headers: true)
# expect(CSV.stub(:new)).to receive(:new).with('test', headers: true)
# expect(CSV.stub).to receive(:read).with('test', headers: true)
# CSV.should_receive(:new).with("file", headers: true)
expect(response.status).to eq(200)
end
但是这不起作用,我缺少一些基础知识还是难以测试的功能?