Sha256: 95b746a32f5415fb0b4722d6662ceef0612bb9a85dc474c8aa940bdb3eafc124

Contents?: true

Size: 1.55 KB

Versions: 4

Compression:

Stored size: 1.55 KB

Contents

require_relative 'test_helper'

# Unit Test for IOStreams::File
module Streams
  class IOStreamsTest < Minitest::Test
    describe IOStreams do
      before do
        @source_file_name = File.join(File.dirname(__FILE__), 'files', 'text.txt')
        @data             = File.read(@source_file_name)

        @temp_file        = Tempfile.new('iostreams')
        @target_file_name = @temp_file.to_path
      end

      after do
        @temp_file.delete if @temp_file
      end

      describe '.copy' do
        it 'file' do
          size   = IOStreams.reader(@source_file_name) do |source_stream|
            IOStreams.writer(@target_file_name) do |target_stream|
              IOStreams.copy(source_stream, target_stream)
            end
          end
          actual = File.read(@target_file_name)

          assert_equal actual, @data
          assert_equal actual.size, size
        end

        it 'stream' do
          size   = File.open(@source_file_name) do |source_stream|
            IOStreams.writer(@target_file_name) do |target_stream|
              IOStreams.copy(source_stream, target_stream)
            end
          end
          actual = File.read(@target_file_name)

          assert_equal actual, @data
          assert_equal actual.size, size
        end
      end

      describe '.copy_file' do
        it 'copies' do
          size   = IOStreams.copy_file(@source_file_name, @target_file_name)
          actual = File.read(@target_file_name)

          assert_equal actual, @data
          assert_equal actual.size, size
        end
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
iostreams-0.12.1 test/io_streams_test.rb
iostreams-0.12.0 test/io_streams_test.rb
iostreams-0.11.0 test/io_streams_test.rb
iostreams-0.10.1 test/io_streams_test.rb