Jump to content

The ultimate community for Ruby on Rails developers.


Photo

NoMethodError: private method `CSV' called for

rspec csv

  • Please log in to reply
No replies to this topic

#1 dailammoc

dailammoc

    Dispatcher

  • Members
  • 38 posts
  • Location/

Posted 16 April 2014 - 09:43 AM

I have the rspec test like this:

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

When I run test command, the errors were showed here:

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

I write these codes to test my csv upload function, please show me where is my mistake.







Also tagged with one or more of these keywords: rspec, csv

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users