1

I need to generate a dummy csv file to write my specs. Could someone please help me out with this.

Thanks in advance.

MayankS
  • 446
  • 1
  • 3
  • 17
  • 1
    Just include the csv lib into your *_spec.rb file and create it [like so](http://stackoverflow.com/questions/12718872/how-do-i-create-a-new-csv-file-in-ruby) – AME Jul 22 '14 at 15:12

1 Answers1

3

I found a way to do this, however didn't found a better way to stub it:

let(:headers) { "PackageTrackingNumber,PackagePostalServiceTrackingID,PackageReference1\r\n" }
let(:rows)    { ["1234,,1,L\r\n"] }
let(:io) do
  StringIO.new.tap do |sio|
    sio << headers
    rows.each { |row| sio << row }
    sio.rewind
  end
end
MayankS
  • 446
  • 1
  • 3
  • 17