Sha256: 3eaddb77e59ed7fdb0fc6b7bb01df9ce3ed33ce3f3c6cb512073bdfa4815576f

Contents?: true

Size: 1.18 KB

Versions: 9

Compression:

Stored size: 1.18 KB

Contents

require_relative 'test_helper'

class DelimitedWriterTest < Minitest::Test
  describe IOStreams::Line::Writer do
    let :file_name do
      File.join(File.dirname(__FILE__), 'files', 'text.txt')
    end

    let :raw do
      File.read(file_name)
    end

    let :lines do
      raw.lines.map(&:strip)
    end

    describe '#<<' do
      it 'file' do
        temp_file = Tempfile.new('rocket_job')
        file_name = temp_file.to_path
        IOStreams::Line::Writer.file(file_name) do |io|
          lines.each { |line| io << line }
        end
        result = File.read(file_name)
        assert_equal raw, result
      end

      it 'stream' do
        io_string = StringIO.new
        IOStreams::Line::Writer.stream(io_string) do |io|
          lines.each { |line| io << line }
        end
        assert_equal raw, io_string.string
      end
    end

    describe '.write' do
      it 'returns byte count' do
        io_string = StringIO.new
        count     = 0
        IOStreams::Line::Writer.stream(io_string) do |io|
          lines.each { |line| count += io.write(line) }
        end
        assert_equal raw, io_string.string
        assert_equal raw.size, count
      end
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

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