Sha256: 263e1520adefba6cef3a7c55f4723c98feb2703fee40b85c2240c3bb4ad99988

Contents?: true

Size: 1.42 KB

Versions: 2

Compression:

Stored size: 1.42 KB

Contents

require_relative '../../../test_helper'

describe DocParser::CSVOutput do
  before do
    Log4r::Logger['docparser'].level = Log4r::ERROR
  end
  after do
    Log4r::Logger['docparser'].level = Log4r::INFO
  end

  it 'must create a file' do
    Dir.mktmpdir do |dir|
      filename = File.join(dir, 'test.csv')
      DocParser::CSVOutput.new(filename: filename)
      File.exists?(filename).must_equal true
    end
  end

  it 'must save the header' do
    Dir.mktmpdir do |dir|
      filename = File.join(dir, 'test.csv')
      output = DocParser::CSVOutput.new(filename: filename)
      output.header = 'test', 'the', 'header'
      output.close
      open(filename).read.must_equal "test;the;header\n"
    end
  end

  it 'must save some rows' do
    Dir.mktmpdir do |dir|
      filename = File.join(dir, 'test.csv')
      output = DocParser::CSVOutput.new(filename: filename)
      output.add_row %w(aap noot mies)
      output.add_row ['aap', 'noot', 'mies;']
      output.close
      open(filename).read.must_equal "aap;noot;mies\naap;noot;\"mies;\"\n"
    end
  end

  it 'must give the correct rowcount' do
    Dir.mktmpdir do |dir|
      filename = File.join(dir, 'test.csv')
      output = DocParser::CSVOutput.new(filename: filename)
      output.header = 'test', 'the', 'header'
      output.rowcount.must_equal 0
      output.add_row %w(aap noot mies)
      output.add_row %w(aap noot mies)
      output.rowcount.must_equal 2
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
docparser-0.2.0 test/lib/docparser/output/csv_output_test.rb
docparser-0.1.6 test/lib/docparser/output/csv_output_test.rb