Sha256: 412993705af08dfcdeff040963fcf42aa030d42579cd51a9bc28aeb8d6229765

Contents?: true

Size: 1.22 KB

Versions: 61

Compression:

Stored size: 1.22 KB

Contents

# encoding: utf-8

require 'test_helper'
require 'tins/xt/temp_io'

module Tins
  class TempIOTest < Test::Unit::TestCase
    def test_with_string
      returned = temp_io(content: 'foo') { |io|
        assert_equal 'foo', io.read
        :done
      }
      assert_equal returned, :done
    end

    def test_with_suffixed_name
      returned = temp_io(content: 'foo', name: 'foo.csv') { |io|
        assert_true io.path.end_with?('foo.csv')
        :done
      }
      assert_equal returned, :done
    end

    def test_with_proc
      returned = temp_io(content: -> { 'foo' }) { |io|
        assert_equal 'foo', io.read
        :done
      }
      assert_equal returned, :done
    end

    def test_with_proc_and_io_arg
      returned = temp_io(content: -> io { io << 'foo' }) { |io|
        assert_equal 'foo', io.read
        :done
      }
      assert_equal returned, :done
    end

    def test_as_enum
      enum = Tins::TempIO::Enum.new(chunk_size: 5, filename: 'foo') { |file|
        assert_kind_of File, file
        file << "hello" << "world"
      }
      assert_equal 'foo', enum.filename
      assert_equal "hello", enum.next
      assert_equal "world", enum.next
      assert_raise(StopIteration) { enum.next }
    end
  end
end

Version data entries

61 entries across 51 versions & 2 rubygems

Version Path
tins-1.38.0 tests/temp_io_test.rb
tins-1.37.1 tests/temp_io_test.rb
tins-1.37.0 tests/temp_io_test.rb
tins-1.36.1 tests/temp_io_test.rb
tins-1.36.0 tests/temp_io_test.rb
tins-1.35.0 tests/temp_io_test.rb
tins-1.34.0 tests/temp_io_test.rb
tins-1.33.0 tests/temp_io_test.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/tests/temp_io_test.rb
tins-1.32.1 tests/temp_io_test.rb
tins-1.32.0 tests/temp_io_test.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/tests/temp_io_test.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/tests/temp_io_test.rb
tins-1.31.1 tests/temp_io_test.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/tins-1.31.0/tests/temp_io_test.rb
tins-1.31.0 tests/temp_io_test.rb
tins-1.30.0 tests/temp_io_test.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/tins-1.29.1/tests/temp_io_test.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/tins-1.29.1/tests/temp_io_test.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/tins-1.29.1/tests/temp_io_test.rb