NoMethodError:私有方法`CSV'呼吁

时间:2014-04-16 08:25:17

标签: 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", 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

当我运行测试命令时,错误显示在这里:

Failure/Error: @import.CSV.stub(:foreach).with("file_path", headers: true).and_return(data)
     NoMethodError:
       private method `CSV' called for #<Hotel:0xbaf96108>

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

1 个答案:

答案 0 :(得分:0)

您可能需要CSV.stub而不是@import.CSV