NoMethodError:private方法`CSV';要求
我的rspec测试如下: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
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次