Sha256: 35825d8d3c8e664e828e64f7c07966c00b9cb664cd1e706f87df52be3327cc6c

Contents?: true

Size: 1.05 KB

Versions: 14

Compression:

Stored size: 1.05 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 '.open' do
      it 'file' do
        IOStreams::Row::Writer.open(file_name) do |io|
          csv_rows.each { |array| io << array }
        end
        result = File.read(file_name)
        assert_equal raw_csv_data, result
      end

      it 'stream' do
        io_string = StringIO.new
        IOStreams::Line::Writer.open(io_string) do |io|
          IOStreams::Row::Writer.open(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

14 entries across 14 versions & 1 rubygems

Version Path
iostreams-0.20.3 test/row_writer_test.rb
iostreams-0.20.2 test/row_writer_test.rb
iostreams-0.20.1 test/row_writer_test.rb
iostreams-0.20.0 test/row_writer_test.rb
iostreams-0.19.0 test/row_writer_test.rb
iostreams-0.18.0 test/row_writer_test.rb
iostreams-0.17.3 test/row_writer_test.rb
iostreams-0.17.2 test/row_writer_test.rb
iostreams-0.17.1 test/row_writer_test.rb
iostreams-0.17.0 test/row_writer_test.rb
iostreams-0.16.2 test/row_writer_test.rb
iostreams-0.16.1 test/row_writer_test.rb
iostreams-0.16.0 test/row_writer_test.rb
iostreams-0.15.0 test/row_writer_test.rb