Sha256: 5320f71cb4da2c2aafa0c084b3cf43d1ae2076d5ab3af86844d831c12943fad9

Contents?: true

Size: 1.18 KB

Versions: 19

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

19 entries across 19 versions & 1 rubygems

Version Path
iostreams-1.10.2 test/line_writer_test.rb
iostreams-1.10.1 test/line_writer_test.rb
iostreams-1.10.0 test/line_writer_test.rb
iostreams-1.9.0 test/line_writer_test.rb
iostreams-1.8.0 test/line_writer_test.rb
iostreams-1.7.0 test/line_writer_test.rb
iostreams-1.6.2 test/line_writer_test.rb
iostreams-1.6.1 test/line_writer_test.rb
iostreams-1.6.0 test/line_writer_test.rb
iostreams-1.5.1 test/line_writer_test.rb
iostreams-1.5.0 test/line_writer_test.rb
iostreams-1.4.0 test/line_writer_test.rb
iostreams-1.3.3 test/line_writer_test.rb
iostreams-1.3.2 test/line_writer_test.rb
iostreams-1.3.1 test/line_writer_test.rb
iostreams-1.3.0 test/line_writer_test.rb
iostreams-1.2.1 test/line_writer_test.rb
iostreams-1.2.0 test/line_writer_test.rb
iostreams-1.1.1 test/line_writer_test.rb