Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在rails中测试从远程源读取CSV的控制器操作?_Ruby On Rails_Csv_Rspec Rails - Fatal编程技术网

Ruby on rails 如何在rails中测试从远程源读取CSV的控制器操作?

Ruby on rails 如何在rails中测试从远程源读取CSV的控制器操作?,ruby-on-rails,csv,rspec-rails,Ruby On Rails,Csv,Rspec Rails,我想测试一个像这样的函数 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 但这不起

我想测试一个像这样的函数

  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

但这不起作用,我是否缺少一些基础知识,或者这是一个很难测试的函数

定义“不工作”。您是否获得预期的200状态,但希望注释中的项目?不,我没有获得200状态。我想了解的是我应该嘲笑什么部分,不应该嘲笑什么部分。
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