Sha256: 91163c31ab7bab377138ad491637d8134b6f5b9d8d54419f8bc5fe7987cfbdbc

Contents?: true

Size: 1.06 KB

Versions: 9

Compression:

Stored size: 1.06 KB

Contents

require_relative 'test_helper'
require 'csv'

class RowWriterTest < Minitest::Test
  describe IOStreams::Row::Writer do
    let :csv_file_name do
      File.join(File.dirname(__FILE__), 'files', 'test.csv')
    end

    let :raw_csv_data do
      File.read(csv_file_name)
    end

    let :csv_rows do
      CSV.read(csv_file_name)
    end

    let :temp_file do
      Tempfile.new('iostreams')
    end

    let :file_name do
      temp_file.path
    end

    after do
      temp_file.delete
    end

    describe '.stream' do
      it 'file' do
        IOStreams::Row::Writer.file(file_name) do |io|
          csv_rows.each { |array| io << array }
        end
        result = ::File.read(file_name)
        assert_equal raw_csv_data, result
      end

      it 'streams' do
        io_string = StringIO.new
        IOStreams::Line::Writer.stream(io_string) do |io|
          IOStreams::Row::Writer.stream(io) do |stream|
            csv_rows.each { |array| stream << array }
          end
        end
        assert_equal raw_csv_data, io_string.string
      end
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
iostreams-1.1.0 test/row_writer_test.rb
iostreams-1.0.0 test/row_writer_test.rb
iostreams-1.0.0.beta7 test/row_writer_test.rb
iostreams-1.0.0.beta6 test/row_writer_test.rb
iostreams-1.0.0.beta5 test/row_writer_test.rb
iostreams-1.0.0.beta4 test/row_writer_test.rb
iostreams-1.0.0.beta3 test/row_writer_test.rb
iostreams-1.0.0.beta2 test/row_writer_test.rb
iostreams-1.0.0.beta test/row_writer_test.rb