Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/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
NoMethodError:private方法`CSV';要求_Csv_Ruby On Rails 4_Rspec - Fatal编程技术网

NoMethodError:private方法`CSV';要求

NoMethodError:private方法`CSV';要求,csv,ruby-on-rails-4,rspec,Csv,Ruby On Rails 4,Rspec,我的rspec测试如下: describe "POST import" do describe "handling CSV files" do describe "to import products" do before(:each) do @import = Hotel.create! valid_attributes @import.CSV.stub(:foreach).with("file_path", head

我的rspec测试如下:

describe "POST import" do
    describe "handling CSV files" do
      describe "to import products" do
        before(:each) do
          @import = Hotel.create! valid_attributes
          @import.CSV.stub(:foreach).with("file_path", headers: true).and_return(data)
        end

        it "should process the csv file after save" do
          @import.should_receive(:process_csv)
          @import.save
        end

        it "should load the csv file" do
          CSV.should_receive(:foreach)
          @import.save
        end
      end
    end   
  end
当我运行test命令时,错误显示在这里:

Failure/Error: @import.CSV.stub(:foreach).with("file_path", headers: true).and_return(data)
     NoMethodError:
       private method `CSV' called for #<Hotel:0xbaf96108>
失败/错误:@import.CSV.stub(:foreach).with(“文件路径”,标题:true.)和_返回(数据)
命名错误:
调用了私有方法“CSV”#

我写这些代码是为了测试我的csv上传功能,请告诉我我的错误在哪里。

你可能想要
csv.stub
而不是
@import.csv

另一个错误发生了:
未定义的局部变量或方法'data',对于
是的,你说
并返回(数据)
,但是数据没有在任何地方定义。@Arienjan I删除了
以及其他错误:
失败/错误:CSV.should\u receive(:foreach)#。任意次数()。foreach(任意参数)预期:收到任何参数1次:收到任何参数0次