io-like 0.3.1 → 0.4.0.pre1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
 - data/LICENSE +1 -1
 - data/NEWS.md +14 -1
 - data/README.md +75 -94
 - data/lib/io/like.rb +1916 -1314
 - data/lib/io/like_helpers/abstract_io.rb +512 -0
 - data/lib/io/like_helpers/blocking_io.rb +86 -0
 - data/lib/io/like_helpers/buffered_io.rb +555 -0
 - data/lib/io/like_helpers/character_io/basic_reader.rb +122 -0
 - data/lib/io/like_helpers/character_io/converter_reader.rb +252 -0
 - data/lib/io/like_helpers/character_io.rb +529 -0
 - data/lib/io/like_helpers/delegated_io.rb +250 -0
 - data/lib/io/like_helpers/duplexed_io.rb +259 -0
 - data/lib/io/like_helpers/io.rb +21 -0
 - data/lib/io/like_helpers/io_wrapper.rb +290 -0
 - data/lib/io/like_helpers/pipeline.rb +77 -0
 - data/lib/io/like_helpers/ruby_facts.rb +33 -0
 - data/lib/io/like_helpers.rb +14 -0
 - metadata +107 -224
 - data/.yardopts +0 -1
 - data/Rakefile +0 -228
 - data/ruby.1.8.mspec +0 -7
 - data/spec/binmode_spec.rb +0 -29
 - data/spec/close_read_spec.rb +0 -64
 - data/spec/close_spec.rb +0 -36
 - data/spec/close_write_spec.rb +0 -61
 - data/spec/closed_spec.rb +0 -16
 - data/spec/each_byte_spec.rb +0 -38
 - data/spec/each_line_spec.rb +0 -11
 - data/spec/each_spec.rb +0 -11
 - data/spec/eof_spec.rb +0 -11
 - data/spec/fixtures/classes.rb +0 -96
 - data/spec/fixtures/gets.txt +0 -9
 - data/spec/fixtures/numbered_lines.txt +0 -5
 - data/spec/fixtures/one_byte.txt +0 -1
 - data/spec/fixtures/paragraphs.txt +0 -7
 - data/spec/fixtures/readlines.txt +0 -6
 - data/spec/flush_spec.rb +0 -8
 - data/spec/getc_spec.rb +0 -44
 - data/spec/gets_spec.rb +0 -212
 - data/spec/isatty_spec.rb +0 -6
 - data/spec/lineno_spec.rb +0 -84
 - data/spec/output_spec.rb +0 -47
 - data/spec/pos_spec.rb +0 -53
 - data/spec/print_spec.rb +0 -97
 - data/spec/printf_spec.rb +0 -24
 - data/spec/putc_spec.rb +0 -57
 - data/spec/puts_spec.rb +0 -99
 - data/spec/read_spec.rb +0 -162
 - data/spec/readchar_spec.rb +0 -49
 - data/spec/readline_spec.rb +0 -60
 - data/spec/readlines_spec.rb +0 -140
 - data/spec/readpartial_spec.rb +0 -92
 - data/spec/rewind_spec.rb +0 -56
 - data/spec/seek_spec.rb +0 -72
 - data/spec/shared/each.rb +0 -204
 - data/spec/shared/eof.rb +0 -116
 - data/spec/shared/pos.rb +0 -39
 - data/spec/shared/tty.rb +0 -12
 - data/spec/shared/write.rb +0 -53
 - data/spec/sync_spec.rb +0 -56
 - data/spec/sysread_spec.rb +0 -87
 - data/spec/sysseek_spec.rb +0 -68
 - data/spec/syswrite_spec.rb +0 -60
 - data/spec/tell_spec.rb +0 -7
 - data/spec/to_io_spec.rb +0 -19
 - data/spec/tty_spec.rb +0 -6
 - data/spec/ungetc_spec.rb +0 -118
 - data/spec/write_spec.rb +0 -61
 - data/spec_helper.rb +0 -49
 - /data/{LICENSE-rubyspec → rubyspec/LICENSE} +0 -0
 
    
        data/spec/lineno_spec.rb
    DELETED
    
    | 
         @@ -1,84 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.dirname(__FILE__) + '/../spec_helper'
         
     | 
| 
       2 
     | 
    
         
            -
            require File.dirname(__FILE__) + '/fixtures/classes'
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            describe "IO::Like#lineno" do
         
     | 
| 
       5 
     | 
    
         
            -
              it "raises IOError on closed stream" do
         
     | 
| 
       6 
     | 
    
         
            -
                lambda { IOSpecs.closed_file.lineno }.should raise_error(IOError)
         
     | 
| 
       7 
     | 
    
         
            -
              end
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
              it "returns the current line number" do
         
     | 
| 
       10 
     | 
    
         
            -
                IOSpecs.readable_iowrapper do |f|
         
     | 
| 
       11 
     | 
    
         
            -
                  f.lineno.should == 0
         
     | 
| 
       12 
     | 
    
         
            -
                  while (f.gets)
         
     | 
| 
       13 
     | 
    
         
            -
                    f.lineno.should > 0
         
     | 
| 
       14 
     | 
    
         
            -
                  end
         
     | 
| 
       15 
     | 
    
         
            -
                  f.rewind
         
     | 
| 
       16 
     | 
    
         
            -
                  f.lineno.should == 0
         
     | 
| 
       17 
     | 
    
         
            -
                end
         
     | 
| 
       18 
     | 
    
         
            -
              end
         
     | 
| 
       19 
     | 
    
         
            -
            end
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
            describe "IO::Like#lineno=" do
         
     | 
| 
       22 
     | 
    
         
            -
              it "raises IOError on closed stream" do
         
     | 
| 
       23 
     | 
    
         
            -
                lambda { IOSpecs.closed_file.lineno = 5 }.should raise_error(IOError)
         
     | 
| 
       24 
     | 
    
         
            -
              end
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
              it "invokes to_int on non-numeric arguments" do
         
     | 
| 
       27 
     | 
    
         
            -
                (obj = mock('123')).should_receive(:to_int).and_return(123)
         
     | 
| 
       28 
     | 
    
         
            -
                IOSpecs.readable_iowrapper do |f|
         
     | 
| 
       29 
     | 
    
         
            -
                  f.lineno = obj
         
     | 
| 
       30 
     | 
    
         
            -
                  f.lineno.should == 123
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
                  f.lineno = 1.5
         
     | 
| 
       33 
     | 
    
         
            -
                  f.lineno.should == 1
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                  f.lineno = 92233.72036854775808
         
     | 
| 
       36 
     | 
    
         
            -
                  f.lineno.should == 92233
         
     | 
| 
       37 
     | 
    
         
            -
                end
         
     | 
| 
       38 
     | 
    
         
            -
              end
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
              it "raises TypeError on nil argument" do
         
     | 
| 
       41 
     | 
    
         
            -
                IOSpecs.readable_iowrapper do |f|
         
     | 
| 
       42 
     | 
    
         
            -
                  lambda { f.lineno = nil }.should raise_error(TypeError)
         
     | 
| 
       43 
     | 
    
         
            -
                end
         
     | 
| 
       44 
     | 
    
         
            -
              end
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
              it "sets the current line number to the given value" do
         
     | 
| 
       47 
     | 
    
         
            -
                IOSpecs.readable_iowrapper do |f|
         
     | 
| 
       48 
     | 
    
         
            -
                  count = 500
         
     | 
| 
       49 
     | 
    
         
            -
                  f.lineno = count - 1
         
     | 
| 
       50 
     | 
    
         
            -
                  while (f.gets)
         
     | 
| 
       51 
     | 
    
         
            -
                    f.lineno.should == count
         
     | 
| 
       52 
     | 
    
         
            -
                    count += 1
         
     | 
| 
       53 
     | 
    
         
            -
                  end
         
     | 
| 
       54 
     | 
    
         
            -
                  f.rewind
         
     | 
| 
       55 
     | 
    
         
            -
                  f.lineno.should == 0
         
     | 
| 
       56 
     | 
    
         
            -
                end
         
     | 
| 
       57 
     | 
    
         
            -
              end
         
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
              it "does not change $." do
         
     | 
| 
       60 
     | 
    
         
            -
                orig_value = $.
         
     | 
| 
       61 
     | 
    
         
            -
                IOSpecs.readable_iowrapper do |f|
         
     | 
| 
       62 
     | 
    
         
            -
                  numbers = [-2**30, -2**16, -2**8, -100, -10, -1, 0, 1, 10, 2**8, 2**16, 2**30]
         
     | 
| 
       63 
     | 
    
         
            -
                  numbers.each { |num|
         
     | 
| 
       64 
     | 
    
         
            -
                    f.lineno = num
         
     | 
| 
       65 
     | 
    
         
            -
                    f.lineno.should == num
         
     | 
| 
       66 
     | 
    
         
            -
                    $..should == orig_value
         
     | 
| 
       67 
     | 
    
         
            -
                  }
         
     | 
| 
       68 
     | 
    
         
            -
                end
         
     | 
| 
       69 
     | 
    
         
            -
              end
         
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
              it "does not change $. until next read" do
         
     | 
| 
       72 
     | 
    
         
            -
                $. = 0
         
     | 
| 
       73 
     | 
    
         
            -
                IOSpecs.readable_iowrapper do |f|
         
     | 
| 
       74 
     | 
    
         
            -
                  $..should == 0
         
     | 
| 
       75 
     | 
    
         
            -
                  count = 500
         
     | 
| 
       76 
     | 
    
         
            -
                  f.lineno = count - 1
         
     | 
| 
       77 
     | 
    
         
            -
                  $..should == 0
         
     | 
| 
       78 
     | 
    
         
            -
                  while (f.gets)
         
     | 
| 
       79 
     | 
    
         
            -
                    $..should == count
         
     | 
| 
       80 
     | 
    
         
            -
                    count += 1
         
     | 
| 
       81 
     | 
    
         
            -
                  end
         
     | 
| 
       82 
     | 
    
         
            -
                end
         
     | 
| 
       83 
     | 
    
         
            -
              end
         
     | 
| 
       84 
     | 
    
         
            -
            end
         
     | 
    
        data/spec/output_spec.rb
    DELETED
    
    | 
         @@ -1,47 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.dirname(__FILE__) + '/../spec_helper'
         
     | 
| 
       2 
     | 
    
         
            -
            require File.dirname(__FILE__) + '/fixtures/classes'
         
     | 
| 
       3 
     | 
    
         
            -
            require File.dirname(__FILE__) + '/shared/write'
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            describe "IO::Like#<<" do
         
     | 
| 
       6 
     | 
    
         
            -
              before :each do
         
     | 
| 
       7 
     | 
    
         
            -
                @filename = tmp("IO_Like__write_test")
         
     | 
| 
       8 
     | 
    
         
            -
                @content = "012345678901234567890123456789"
         
     | 
| 
       9 
     | 
    
         
            -
                File.open(@filename, "w") { |f| f.syswrite(@content) }
         
     | 
| 
       10 
     | 
    
         
            -
                @file = File.open(@filename, "r+")
         
     | 
| 
       11 
     | 
    
         
            -
                @iowrapper = IOWrapper.open(@file)
         
     | 
| 
       12 
     | 
    
         
            -
              end
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
              after :each do
         
     | 
| 
       15 
     | 
    
         
            -
                @iowrapper.close unless @iowrapper.closed?
         
     | 
| 
       16 
     | 
    
         
            -
                @file.close unless @file.closed?
         
     | 
| 
       17 
     | 
    
         
            -
                File.delete(@filename)
         
     | 
| 
       18 
     | 
    
         
            -
              end
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
              it "returns a reference to the stream" do
         
     | 
| 
       21 
     | 
    
         
            -
                (@iowrapper << 'abcde').should == @iowrapper
         
     | 
| 
       22 
     | 
    
         
            -
              end
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
              it "writes all of the string's bytes without buffering if mode is sync" do
         
     | 
| 
       25 
     | 
    
         
            -
                @iowrapper.sync = true
         
     | 
| 
       26 
     | 
    
         
            -
                @iowrapper << "abcde"
         
     | 
| 
       27 
     | 
    
         
            -
                File.open(@filename) do |file|
         
     | 
| 
       28 
     | 
    
         
            -
                  file.read(10).should == "abcde56789"
         
     | 
| 
       29 
     | 
    
         
            -
                end
         
     | 
| 
       30 
     | 
    
         
            -
              end
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
              it "does not raise IOError on read-only stream if writing zero bytes" do
         
     | 
| 
       33 
     | 
    
         
            -
                lambda do
         
     | 
| 
       34 
     | 
    
         
            -
                  IOSpecs.readable_iowrapper do |iowrapper|
         
     | 
| 
       35 
     | 
    
         
            -
                    iowrapper << ""
         
     | 
| 
       36 
     | 
    
         
            -
                  end
         
     | 
| 
       37 
     | 
    
         
            -
                end.should_not raise_error
         
     | 
| 
       38 
     | 
    
         
            -
              end
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
              it "does not raise IOError on closed stream if writing zero bytes" do
         
     | 
| 
       41 
     | 
    
         
            -
                lambda { IOSpecs.closed_file << "" }.should_not raise_error
         
     | 
| 
       42 
     | 
    
         
            -
              end
         
     | 
| 
       43 
     | 
    
         
            -
            end
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
            describe "IO::Like#<<" do
         
     | 
| 
       46 
     | 
    
         
            -
              it_behaves_like :io_like__write, :<<
         
     | 
| 
       47 
     | 
    
         
            -
            end
         
     | 
    
        data/spec/pos_spec.rb
    DELETED
    
    | 
         @@ -1,53 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.dirname(__FILE__) + '/../spec_helper'
         
     | 
| 
       2 
     | 
    
         
            -
            require File.dirname(__FILE__) + '/fixtures/classes'
         
     | 
| 
       3 
     | 
    
         
            -
            require File.dirname(__FILE__) + '/shared/pos'
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            describe "IO::Like#pos" do
         
     | 
| 
       6 
     | 
    
         
            -
              it_behaves_like(:io_like__pos, :pos)
         
     | 
| 
       7 
     | 
    
         
            -
            end
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
            describe "IO::Like#pos=" do
         
     | 
| 
       10 
     | 
    
         
            -
              before :each do
         
     | 
| 
       11 
     | 
    
         
            -
                @fname = 'test.txt'
         
     | 
| 
       12 
     | 
    
         
            -
                File.open(@fname, 'w') { |f| f.write("123") }
         
     | 
| 
       13 
     | 
    
         
            -
              end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
              after :each do
         
     | 
| 
       16 
     | 
    
         
            -
                File.unlink(@fname)
         
     | 
| 
       17 
     | 
    
         
            -
              end
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
              it "sets the offset" do
         
     | 
| 
       20 
     | 
    
         
            -
                File.open(@fname) do |f|
         
     | 
| 
       21 
     | 
    
         
            -
                  ReadableIOWrapper.open(f) do |iowrapper|
         
     | 
| 
       22 
     | 
    
         
            -
                    val1 = iowrapper.read(1)
         
     | 
| 
       23 
     | 
    
         
            -
                    iowrapper.pos = 0
         
     | 
| 
       24 
     | 
    
         
            -
                    iowrapper.read(1).should == val1
         
     | 
| 
       25 
     | 
    
         
            -
                  end
         
     | 
| 
       26 
     | 
    
         
            -
                end
         
     | 
| 
       27 
     | 
    
         
            -
              end
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
              it "can handle any numerical argument without breaking" do
         
     | 
| 
       30 
     | 
    
         
            -
                File.open(@fname) do |f|
         
     | 
| 
       31 
     | 
    
         
            -
                  ReadableIOWrapper.open(f) do |iowrapper|
         
     | 
| 
       32 
     | 
    
         
            -
                    iowrapper.pos = 1.2
         
     | 
| 
       33 
     | 
    
         
            -
                    iowrapper.pos.should == 1
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                    iowrapper.pos = 2**32
         
     | 
| 
       36 
     | 
    
         
            -
                    iowrapper.pos.should == 2**32
         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
                    iowrapper.pos = 1.23423423432e12
         
     | 
| 
       39 
     | 
    
         
            -
                    iowrapper.pos.should == Integer(1.23423423432e12)
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
                    iowrapper.pos = Float::EPSILON
         
     | 
| 
       42 
     | 
    
         
            -
                    iowrapper.pos.should == 0
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
                    lambda { iowrapper.pos = 2**128 }.should raise_error(RangeError)
         
     | 
| 
       45 
     | 
    
         
            -
                  end
         
     | 
| 
       46 
     | 
    
         
            -
                end
         
     | 
| 
       47 
     | 
    
         
            -
              end
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
              it "raises IOError on closed stream" do
         
     | 
| 
       50 
     | 
    
         
            -
                lambda { IOSpecs.closed_file.pos = 0 }.should raise_error(IOError)
         
     | 
| 
       51 
     | 
    
         
            -
              end
         
     | 
| 
       52 
     | 
    
         
            -
            end
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
    
        data/spec/print_spec.rb
    DELETED
    
    | 
         @@ -1,97 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.dirname(__FILE__) + '/../spec_helper'
         
     | 
| 
       2 
     | 
    
         
            -
            require File.dirname(__FILE__) + '/fixtures/classes'
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            describe "IO::Like#print" do
         
     | 
| 
       5 
     | 
    
         
            -
              before :each do
         
     | 
| 
       6 
     | 
    
         
            -
                @old_record_separator = $\
         
     | 
| 
       7 
     | 
    
         
            -
                @old_field_separator = $,
         
     | 
| 
       8 
     | 
    
         
            -
                @filename = tmp('IO_Like__print_test')
         
     | 
| 
       9 
     | 
    
         
            -
                @file = File.open(@filename, 'w')
         
     | 
| 
       10 
     | 
    
         
            -
                @file.sync = true
         
     | 
| 
       11 
     | 
    
         
            -
                @iowrapper = WritableIOWrapper.open(@file)
         
     | 
| 
       12 
     | 
    
         
            -
                @iowrapper.sync = true
         
     | 
| 
       13 
     | 
    
         
            -
              end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
              after :each do
         
     | 
| 
       16 
     | 
    
         
            -
                $\ = @old_record_separator
         
     | 
| 
       17 
     | 
    
         
            -
                $, = @old_field_separator
         
     | 
| 
       18 
     | 
    
         
            -
                @iowrapper.close unless @iowrapper.closed?
         
     | 
| 
       19 
     | 
    
         
            -
                @file.close unless @file.closed?
         
     | 
| 
       20 
     | 
    
         
            -
              end
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
              it "returns nil" do
         
     | 
| 
       23 
     | 
    
         
            -
                @iowrapper.print('hello').should == nil
         
     | 
| 
       24 
     | 
    
         
            -
              end
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
              # MRI LIMITATION:
         
     | 
| 
       27 
     | 
    
         
            -
              # $_ will not cross into the implementation of print since its value is
         
     | 
| 
       28 
     | 
    
         
            -
              # limited to the local scope in managed code.
         
     | 
| 
       29 
     | 
    
         
            -
              #
         
     | 
| 
       30 
     | 
    
         
            -
              #it "writes $_ by default" do
         
     | 
| 
       31 
     | 
    
         
            -
              #  $_ = 'hello'
         
     | 
| 
       32 
     | 
    
         
            -
              #  @iowrapper.print()
         
     | 
| 
       33 
     | 
    
         
            -
              #  @iowrapper.close
         
     | 
| 
       34 
     | 
    
         
            -
              #  @file.close
         
     | 
| 
       35 
     | 
    
         
            -
              #  File.read(@filename).should == "hello\n"
         
     | 
| 
       36 
     | 
    
         
            -
              #end
         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
              it "coerces arguments to strings using to_s" do
         
     | 
| 
       39 
     | 
    
         
            -
                data = 'abcdefgh9876'
         
     | 
| 
       40 
     | 
    
         
            -
                (obj = mock('test')).should_receive(:to_s).and_return(data)
         
     | 
| 
       41 
     | 
    
         
            -
                @iowrapper.print(obj)
         
     | 
| 
       42 
     | 
    
         
            -
                File.read(@filename).should == data
         
     | 
| 
       43 
     | 
    
         
            -
              end
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
              it "writes nil arguments as \"nil\"" do
         
     | 
| 
       46 
     | 
    
         
            -
                @iowrapper.print(nil)
         
     | 
| 
       47 
     | 
    
         
            -
                File.read(@filename).should == "nil"
         
     | 
| 
       48 
     | 
    
         
            -
              end
         
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
              it "appends $\\ to the output" do
         
     | 
| 
       51 
     | 
    
         
            -
                $\ = '->'
         
     | 
| 
       52 
     | 
    
         
            -
                data = 'abcdefgh9876'
         
     | 
| 
       53 
     | 
    
         
            -
                @iowrapper.print(data)
         
     | 
| 
       54 
     | 
    
         
            -
                File.read(@filename).should == "#{data}#{$\}"
         
     | 
| 
       55 
     | 
    
         
            -
              end
         
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
              it "does not append $\\ to the output when it is nil" do
         
     | 
| 
       58 
     | 
    
         
            -
                $\ = nil
         
     | 
| 
       59 
     | 
    
         
            -
                data = 'abcdefgh9876'
         
     | 
| 
       60 
     | 
    
         
            -
                @iowrapper.print(data)
         
     | 
| 
       61 
     | 
    
         
            -
                File.read(@filename).should == data
         
     | 
| 
       62 
     | 
    
         
            -
              end
         
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
              it "writes $, between arguments" do
         
     | 
| 
       65 
     | 
    
         
            -
                $, = '->'
         
     | 
| 
       66 
     | 
    
         
            -
                data1 = 'abcdefgh9876'
         
     | 
| 
       67 
     | 
    
         
            -
                data2 = '12345678zyxw'
         
     | 
| 
       68 
     | 
    
         
            -
                @iowrapper.print(data1, data2)
         
     | 
| 
       69 
     | 
    
         
            -
                File.read(@filename).should == "#{data1}#{$,}#{data2}"
         
     | 
| 
       70 
     | 
    
         
            -
              end
         
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
              it "does not write $, between arguments when it is nil" do
         
     | 
| 
       73 
     | 
    
         
            -
                $, = nil
         
     | 
| 
       74 
     | 
    
         
            -
                data1 = 'abcdefgh9876'
         
     | 
| 
       75 
     | 
    
         
            -
                data2 = '12345678zyxw'
         
     | 
| 
       76 
     | 
    
         
            -
                @iowrapper.print(data1, data2)
         
     | 
| 
       77 
     | 
    
         
            -
                File.read(@filename).should == "#{data1}#{data2}"
         
     | 
| 
       78 
     | 
    
         
            -
              end
         
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
              it "does not check if the file is writable if writing zero bytes" do
         
     | 
| 
       81 
     | 
    
         
            -
                lambda { IOSpecs.readable_iowrapper.print("") }.should_not raise_error
         
     | 
| 
       82 
     | 
    
         
            -
              end
         
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
              it "checks if the file is writable if writing more than zero bytes" do
         
     | 
| 
       85 
     | 
    
         
            -
                lambda do
         
     | 
| 
       86 
     | 
    
         
            -
                  IOSpecs.readable_iowrapper.print("hello")
         
     | 
| 
       87 
     | 
    
         
            -
                end.should raise_error(IOError)
         
     | 
| 
       88 
     | 
    
         
            -
              end
         
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
              it "does not raise IOError on closed stream if writing zero bytes" do
         
     | 
| 
       91 
     | 
    
         
            -
                lambda { IOSpecs.closed_file.print("") }.should_not raise_error
         
     | 
| 
       92 
     | 
    
         
            -
              end
         
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
              it "raises IOError on closed stream if writing more than zero bytes" do
         
     | 
| 
       95 
     | 
    
         
            -
                lambda { IOSpecs.closed_file.print("hello") }.should raise_error(IOError)
         
     | 
| 
       96 
     | 
    
         
            -
              end
         
     | 
| 
       97 
     | 
    
         
            -
            end
         
     | 
    
        data/spec/printf_spec.rb
    DELETED
    
    | 
         @@ -1,24 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.dirname(__FILE__) + '/../spec_helper'
         
     | 
| 
       2 
     | 
    
         
            -
            require File.dirname(__FILE__) + '/fixtures/classes'
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            describe "IO::Like#printf" do
         
     | 
| 
       5 
     | 
    
         
            -
              before :each do
         
     | 
| 
       6 
     | 
    
         
            -
                @io = IO.new(STDOUT.fileno, 'w')
         
     | 
| 
       7 
     | 
    
         
            -
                @iowrapper = WritableIOWrapper.open(@io)
         
     | 
| 
       8 
     | 
    
         
            -
                @iowrapper.sync = true
         
     | 
| 
       9 
     | 
    
         
            -
              end
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
              after :each do
         
     | 
| 
       12 
     | 
    
         
            -
                @iowrapper.close unless @iowrapper.closed?
         
     | 
| 
       13 
     | 
    
         
            -
              end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
              it "writes the #sprintf formatted string to the file descriptor" do
         
     | 
| 
       16 
     | 
    
         
            -
                lambda do
         
     | 
| 
       17 
     | 
    
         
            -
                  @io.printf("%s\n", "look ma, no hands")
         
     | 
| 
       18 
     | 
    
         
            -
                end.should output_to_fd("look ma, no hands\n", @io)
         
     | 
| 
       19 
     | 
    
         
            -
              end
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
              it "raises IOError on closed stream" do
         
     | 
| 
       22 
     | 
    
         
            -
                lambda { IOSpecs.closed_file.printf("stuff") }.should raise_error(IOError)
         
     | 
| 
       23 
     | 
    
         
            -
              end
         
     | 
| 
       24 
     | 
    
         
            -
            end
         
     | 
    
        data/spec/putc_spec.rb
    DELETED
    
    | 
         @@ -1,57 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.dirname(__FILE__) + '/../spec_helper'
         
     | 
| 
       2 
     | 
    
         
            -
            require File.dirname(__FILE__) + '/fixtures/classes'
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            describe "IO::Like#putc" do
         
     | 
| 
       5 
     | 
    
         
            -
              before :each do
         
     | 
| 
       6 
     | 
    
         
            -
                @filename = tmp('IO_Like__putc_test')
         
     | 
| 
       7 
     | 
    
         
            -
                @file = File.open(@filename, 'w')
         
     | 
| 
       8 
     | 
    
         
            -
                @file.sync = true
         
     | 
| 
       9 
     | 
    
         
            -
                @iowrapper = WritableIOWrapper.open(@file)
         
     | 
| 
       10 
     | 
    
         
            -
                @iowrapper.sync = true
         
     | 
| 
       11 
     | 
    
         
            -
              end
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
              after :each do
         
     | 
| 
       14 
     | 
    
         
            -
                @iowrapper.close unless @iowrapper.closed?
         
     | 
| 
       15 
     | 
    
         
            -
                @file.close unless @file.closed?
         
     | 
| 
       16 
     | 
    
         
            -
                File.unlink @filename
         
     | 
| 
       17 
     | 
    
         
            -
              end
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
              it "returns a reference to the object" do
         
     | 
| 
       20 
     | 
    
         
            -
                @iowrapper.putc('a').should == 'a'
         
     | 
| 
       21 
     | 
    
         
            -
                @iowrapper.putc(128).should == 128
         
     | 
| 
       22 
     | 
    
         
            -
              end
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
              it "writes the first byte of a String" do
         
     | 
| 
       25 
     | 
    
         
            -
                @iowrapper.putc("foo")
         
     | 
| 
       26 
     | 
    
         
            -
                File.read(@filename).should == 'f'
         
     | 
| 
       27 
     | 
    
         
            -
              end
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
              it "writes the first byte of an object's string representation" do
         
     | 
| 
       30 
     | 
    
         
            -
                (obj = mock('test')).should_receive(:to_int).and_return(261)
         
     | 
| 
       31 
     | 
    
         
            -
                @iowrapper.putc(obj)
         
     | 
| 
       32 
     | 
    
         
            -
                File.read(@filename).should == "\005"
         
     | 
| 
       33 
     | 
    
         
            -
              end
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
              it "writes Numerics that fit in a C char" do
         
     | 
| 
       36 
     | 
    
         
            -
                @iowrapper.putc(-128)
         
     | 
| 
       37 
     | 
    
         
            -
                @iowrapper.putc(0)
         
     | 
| 
       38 
     | 
    
         
            -
                @iowrapper.putc(255)
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
                File.read(@filename).should == "\200\000\377"
         
     | 
| 
       41 
     | 
    
         
            -
              end
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
              it "write the first byte of Numerics that don't fit in a C char" do
         
     | 
| 
       44 
     | 
    
         
            -
                @iowrapper.putc(-129)
         
     | 
| 
       45 
     | 
    
         
            -
                @iowrapper.putc(256)
         
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
                File.read(@filename).should == "\177\000"
         
     | 
| 
       48 
     | 
    
         
            -
              end
         
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
              it "checks if the stream is writable" do
         
     | 
| 
       51 
     | 
    
         
            -
                lambda { IOSpecs.readable_iowrapper.putc('a') }.should raise_error(IOError)
         
     | 
| 
       52 
     | 
    
         
            -
              end
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
              it "raises IOError on closed stream" do
         
     | 
| 
       55 
     | 
    
         
            -
                lambda { IOSpecs.closed_file.putc('a') }.should raise_error(IOError)
         
     | 
| 
       56 
     | 
    
         
            -
              end
         
     | 
| 
       57 
     | 
    
         
            -
            end
         
     | 
    
        data/spec/puts_spec.rb
    DELETED
    
    | 
         @@ -1,99 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.dirname(__FILE__) + '/../spec_helper'
         
     | 
| 
       2 
     | 
    
         
            -
            require File.dirname(__FILE__) + '/fixtures/classes'
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            # TODO: need to find a better way to test this. Too fragile to set expectations
         
     | 
| 
       5 
     | 
    
         
            -
            # to each write call. Only care that all the characters are sent not the number
         
     | 
| 
       6 
     | 
    
         
            -
            # or write calls. Also, these tests do not make sure the ordering of the write calls
         
     | 
| 
       7 
     | 
    
         
            -
            # are correct.
         
     | 
| 
       8 
     | 
    
         
            -
            describe "IO::Like#puts" do
         
     | 
| 
       9 
     | 
    
         
            -
              before :each do
         
     | 
| 
       10 
     | 
    
         
            -
                @old_record_separator = $\
         
     | 
| 
       11 
     | 
    
         
            -
                @old_field_separator = $,
         
     | 
| 
       12 
     | 
    
         
            -
                @filename = tmp('IO_Like__print_test')
         
     | 
| 
       13 
     | 
    
         
            -
                @file = File.open(@filename, 'w')
         
     | 
| 
       14 
     | 
    
         
            -
                @file.sync = true
         
     | 
| 
       15 
     | 
    
         
            -
                @iowrapper = WritableIOWrapper.open(@file)
         
     | 
| 
       16 
     | 
    
         
            -
                @iowrapper.sync = true
         
     | 
| 
       17 
     | 
    
         
            -
              end
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
              after :each do
         
     | 
| 
       20 
     | 
    
         
            -
                $\ = @old_record_separator
         
     | 
| 
       21 
     | 
    
         
            -
                $, = @old_field_separator
         
     | 
| 
       22 
     | 
    
         
            -
                @iowrapper.close unless @iowrapper.closed?
         
     | 
| 
       23 
     | 
    
         
            -
                @file.close unless @file.closed?
         
     | 
| 
       24 
     | 
    
         
            -
              end
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
              it "returns nil" do
         
     | 
| 
       27 
     | 
    
         
            -
                @iowrapper.puts('hello').should == nil
         
     | 
| 
       28 
     | 
    
         
            -
              end
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
              it "writes just a newline when given no args" do
         
     | 
| 
       31 
     | 
    
         
            -
                @iowrapper.puts()
         
     | 
| 
       32 
     | 
    
         
            -
                File.read(@filename).should == "\n"
         
     | 
| 
       33 
     | 
    
         
            -
              end
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
              it "writes just a newline when given just a newline" do
         
     | 
| 
       36 
     | 
    
         
            -
                @iowrapper.puts("\n")
         
     | 
| 
       37 
     | 
    
         
            -
                File.read(@filename).should == "\n"
         
     | 
| 
       38 
     | 
    
         
            -
              end
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
              it "writes nil with a newline when given nil as an arg" do
         
     | 
| 
       41 
     | 
    
         
            -
                @iowrapper.puts(nil)
         
     | 
| 
       42 
     | 
    
         
            -
                File.read(@filename).should == "nil\n"
         
     | 
| 
       43 
     | 
    
         
            -
              end
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
              it "coerces arguments to strings using to_s" do
         
     | 
| 
       46 
     | 
    
         
            -
                data = 'abcdefgh9876'
         
     | 
| 
       47 
     | 
    
         
            -
                (obj = mock('test')).should_receive(:to_s).and_return(data)
         
     | 
| 
       48 
     | 
    
         
            -
                @iowrapper.puts(obj)
         
     | 
| 
       49 
     | 
    
         
            -
                File.read(@filename).should == "#{data}\n"
         
     | 
| 
       50 
     | 
    
         
            -
              end
         
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
              it "writes each arg if given several" do
         
     | 
| 
       53 
     | 
    
         
            -
                data1 = 'abcdefgh9876'
         
     | 
| 
       54 
     | 
    
         
            -
                data2 = '12345678zyxw'
         
     | 
| 
       55 
     | 
    
         
            -
                @iowrapper.puts(data1, data2)
         
     | 
| 
       56 
     | 
    
         
            -
                File.read(@filename).should == "#{data1}\n#{data2}\n"
         
     | 
| 
       57 
     | 
    
         
            -
              end
         
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
              it "flattens a nested array before writing it" do
         
     | 
| 
       60 
     | 
    
         
            -
                data = ['abcdefgh9876', '12345678zyxw']
         
     | 
| 
       61 
     | 
    
         
            -
                @iowrapper.puts(data)
         
     | 
| 
       62 
     | 
    
         
            -
                File.read(@filename).should == "#{data[0]}\n#{data[1]}\n"
         
     | 
| 
       63 
     | 
    
         
            -
              end
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
              it "writes [...] for a recursive array arg" do
         
     | 
| 
       66 
     | 
    
         
            -
                data = []
         
     | 
| 
       67 
     | 
    
         
            -
                data << 1 << data << 2
         
     | 
| 
       68 
     | 
    
         
            -
                @iowrapper.puts(data)
         
     | 
| 
       69 
     | 
    
         
            -
                File.read(@filename).should == "#{data[0]}\n[...]\n#{data[2]}\n"
         
     | 
| 
       70 
     | 
    
         
            -
              end
         
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
              it "writes a newline after objects that do not end in newlines" do
         
     | 
| 
       73 
     | 
    
         
            -
                data = 'abcdefgh9876'
         
     | 
| 
       74 
     | 
    
         
            -
                @iowrapper.puts(data)
         
     | 
| 
       75 
     | 
    
         
            -
                File.read(@filename).should == "#{data}\n"
         
     | 
| 
       76 
     | 
    
         
            -
              end
         
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
              it "does not write a newline after objects that end in newlines" do
         
     | 
| 
       79 
     | 
    
         
            -
                data = "abcdefgh9876\n"
         
     | 
| 
       80 
     | 
    
         
            -
                @iowrapper.puts(data)
         
     | 
| 
       81 
     | 
    
         
            -
                File.read(@filename).should == data
         
     | 
| 
       82 
     | 
    
         
            -
              end
         
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
              it "ignores the $\ separator global" do
         
     | 
| 
       85 
     | 
    
         
            -
                $\ = ":"
         
     | 
| 
       86 
     | 
    
         
            -
                data1 = 'abcdefgh9876'
         
     | 
| 
       87 
     | 
    
         
            -
                data2 = '12345678zyxw'
         
     | 
| 
       88 
     | 
    
         
            -
                @iowrapper.puts(data1, data2)
         
     | 
| 
       89 
     | 
    
         
            -
                File.read(@filename).should == "#{data1}\n#{data2}\n"
         
     | 
| 
       90 
     | 
    
         
            -
              end
         
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
              it "raises IOError on read-only stream" do
         
     | 
| 
       93 
     | 
    
         
            -
                lambda { IOSpecs.readable_iowrapper.puts }.should raise_error(IOError)
         
     | 
| 
       94 
     | 
    
         
            -
              end
         
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
              it "raises IOError on closed stream" do
         
     | 
| 
       97 
     | 
    
         
            -
                lambda { IOSpecs.closed_file.puts }.should raise_error(IOError)
         
     | 
| 
       98 
     | 
    
         
            -
              end
         
     | 
| 
       99 
     | 
    
         
            -
            end
         
     | 
    
        data/spec/read_spec.rb
    DELETED
    
    | 
         @@ -1,162 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.dirname(__FILE__) + '/../spec_helper'
         
     | 
| 
       2 
     | 
    
         
            -
            require File.dirname(__FILE__) + '/fixtures/classes'
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            describe "IO::Like#read" do
         
     | 
| 
       5 
     | 
    
         
            -
              before :each do
         
     | 
| 
       6 
     | 
    
         
            -
                @filename = tmp('IO_Like__read_test')
         
     | 
| 
       7 
     | 
    
         
            -
                @contents = "1234567890"
         
     | 
| 
       8 
     | 
    
         
            -
                File.open(@filename, "w") { |io| io.write(@contents) }
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
                @file = File.open(@filename, "r+")
         
     | 
| 
       11 
     | 
    
         
            -
                @iowrapper = IOWrapper.open(@file)
         
     | 
| 
       12 
     | 
    
         
            -
              end
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
              after :each do
         
     | 
| 
       15 
     | 
    
         
            -
                @iowrapper.close unless @iowrapper.closed?
         
     | 
| 
       16 
     | 
    
         
            -
                @file.close unless @file.closed?
         
     | 
| 
       17 
     | 
    
         
            -
                File.delete(@filename) if File.exists?(@filename)
         
     | 
| 
       18 
     | 
    
         
            -
              end
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
              it "can be read from consecutively" do
         
     | 
| 
       21 
     | 
    
         
            -
                @iowrapper.read(1).should == '1'
         
     | 
| 
       22 
     | 
    
         
            -
                @iowrapper.read(2).should == '23'
         
     | 
| 
       23 
     | 
    
         
            -
                @iowrapper.read(3).should == '456'
         
     | 
| 
       24 
     | 
    
         
            -
                @iowrapper.read(4).should == '7890'
         
     | 
| 
       25 
     | 
    
         
            -
              end
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
              it "can read lots of data" do
         
     | 
| 
       28 
     | 
    
         
            -
                data = "\xaa" * (8096 * 2 + 1024) # HACK IO::BufferSize
         
     | 
| 
       29 
     | 
    
         
            -
                File.open(@filename, 'w') { |io| io.write(data) }
         
     | 
| 
       30 
     | 
    
         
            -
                actual = nil
         
     | 
| 
       31 
     | 
    
         
            -
                File.open(@filename, 'r') { |io| actual = io.read }
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
                actual.length.should == data.length
         
     | 
| 
       34 
     | 
    
         
            -
                actual.split('').all? { |c| c == "\xaa" }.should == true
         
     | 
| 
       35 
     | 
    
         
            -
              end
         
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
              it "can read lots of data with length" do
         
     | 
| 
       38 
     | 
    
         
            -
                read_length = 8096 * 2 + 1024 # HACK IO::BufferSize
         
     | 
| 
       39 
     | 
    
         
            -
                data = "\xaa" * (read_length + 8096) # HACK same
         
     | 
| 
       40 
     | 
    
         
            -
                File.open(@filename, 'w') { |io| io.write(data) }
         
     | 
| 
       41 
     | 
    
         
            -
                actual = nil
         
     | 
| 
       42 
     | 
    
         
            -
                File.open(@filename, 'r') { |io| actual = io.read(read_length) }
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
                actual.length.should == read_length
         
     | 
| 
       45 
     | 
    
         
            -
                actual.split('').all? { |c| c == "\xaa" }.should == true
         
     | 
| 
       46 
     | 
    
         
            -
              end
         
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
              it "consumes zero bytes when reading zero bytes" do
         
     | 
| 
       49 
     | 
    
         
            -
                pre_pos = @iowrapper.pos
         
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
                @iowrapper.read(0).should == ''
         
     | 
| 
       52 
     | 
    
         
            -
                @iowrapper.getc.chr.should == '1'
         
     | 
| 
       53 
     | 
    
         
            -
              end
         
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
              it "is at end-of-file when everything has been read" do
         
     | 
| 
       56 
     | 
    
         
            -
                @iowrapper.read
         
     | 
| 
       57 
     | 
    
         
            -
                @iowrapper.eof?.should == true
         
     | 
| 
       58 
     | 
    
         
            -
              end
         
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
              it "reads the contents of a file" do
         
     | 
| 
       61 
     | 
    
         
            -
                @iowrapper.read.should == @contents
         
     | 
| 
       62 
     | 
    
         
            -
              end
         
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
              it "places the specified number of bytes in the buffer" do
         
     | 
| 
       65 
     | 
    
         
            -
                buf = ""
         
     | 
| 
       66 
     | 
    
         
            -
                @iowrapper.read(5, buf)
         
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
                buf.should == "12345"
         
     | 
| 
       69 
     | 
    
         
            -
              end
         
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
              it "expands the buffer when too small" do
         
     | 
| 
       72 
     | 
    
         
            -
                buf = "ABCDE"
         
     | 
| 
       73 
     | 
    
         
            -
                @iowrapper.read(nil, buf)
         
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
                buf.should == @contents
         
     | 
| 
       76 
     | 
    
         
            -
              end
         
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
              it "overwrites the buffer" do
         
     | 
| 
       79 
     | 
    
         
            -
                buf = "ABCDEFGHIJ"
         
     | 
| 
       80 
     | 
    
         
            -
                @iowrapper.read(nil, buf)
         
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
                buf.should == @contents
         
     | 
| 
       83 
     | 
    
         
            -
              end
         
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
              it "truncates the buffer when too big" do
         
     | 
| 
       86 
     | 
    
         
            -
                buf = "ABCDEFGHIJKLMNO"
         
     | 
| 
       87 
     | 
    
         
            -
                @iowrapper.read(nil, buf)
         
     | 
| 
       88 
     | 
    
         
            -
                buf.should == @contents
         
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
                @iowrapper.rewind
         
     | 
| 
       91 
     | 
    
         
            -
                buf = "ABCDEFGHIJKLMNO"
         
     | 
| 
       92 
     | 
    
         
            -
                @iowrapper.read(5, buf)
         
     | 
| 
       93 
     | 
    
         
            -
                buf.should == @contents[0..4]
         
     | 
| 
       94 
     | 
    
         
            -
              end
         
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
              it "returns the given buffer" do
         
     | 
| 
       97 
     | 
    
         
            -
                buf = ""
         
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
     | 
    
         
            -
                @iowrapper.read(nil, buf).object_id.should == buf.object_id
         
     | 
| 
       100 
     | 
    
         
            -
              end
         
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
              it "coerces the second argument to string and uses it as a buffer" do
         
     | 
| 
       103 
     | 
    
         
            -
                buf = "ABCDE"
         
     | 
| 
       104 
     | 
    
         
            -
                obj = mock("buff")
         
     | 
| 
       105 
     | 
    
         
            -
                obj.should_receive(:to_str).any_number_of_times.and_return(buf)
         
     | 
| 
       106 
     | 
    
         
            -
             
     | 
| 
       107 
     | 
    
         
            -
                @iowrapper.read(15, obj).object_id.should_not == obj.object_id
         
     | 
| 
       108 
     | 
    
         
            -
                buf.should == @contents
         
     | 
| 
       109 
     | 
    
         
            -
              end
         
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
              it "returns an empty string at end-of-file" do
         
     | 
| 
       112 
     | 
    
         
            -
                @iowrapper.read
         
     | 
| 
       113 
     | 
    
         
            -
                @iowrapper.read.should == ''
         
     | 
| 
       114 
     | 
    
         
            -
              end
         
     | 
| 
       115 
     | 
    
         
            -
             
     | 
| 
       116 
     | 
    
         
            -
              it "reads the contents of a file when more bytes are specified" do
         
     | 
| 
       117 
     | 
    
         
            -
                @iowrapper.read(@contents.length + 1).should == @contents
         
     | 
| 
       118 
     | 
    
         
            -
              end
         
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
              it "reads all data available before a SystemCallError is raised" do
         
     | 
| 
       121 
     | 
    
         
            -
                # Overrride @file.sysread to raise SystemCallError every other time it's
         
     | 
| 
       122 
     | 
    
         
            -
                # called.
         
     | 
| 
       123 
     | 
    
         
            -
                class << @file
         
     | 
| 
       124 
     | 
    
         
            -
                  alias :sysread_orig :sysread
         
     | 
| 
       125 
     | 
    
         
            -
                  def sysread(length)
         
     | 
| 
       126 
     | 
    
         
            -
                    if @error_raised then
         
     | 
| 
       127 
     | 
    
         
            -
                      @error_raised = false
         
     | 
| 
       128 
     | 
    
         
            -
                      sysread_orig(length)
         
     | 
| 
       129 
     | 
    
         
            -
                    else
         
     | 
| 
       130 
     | 
    
         
            -
                      @error_raised = true
         
     | 
| 
       131 
     | 
    
         
            -
                      raise SystemCallError, 'Test Error'
         
     | 
| 
       132 
     | 
    
         
            -
                    end
         
     | 
| 
       133 
     | 
    
         
            -
                  end
         
     | 
| 
       134 
     | 
    
         
            -
                end
         
     | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
       136 
     | 
    
         
            -
                lambda { @iowrapper.read }.should raise_error(SystemCallError)
         
     | 
| 
       137 
     | 
    
         
            -
                @iowrapper.read.should == @contents
         
     | 
| 
       138 
     | 
    
         
            -
              end
         
     | 
| 
       139 
     | 
    
         
            -
             
     | 
| 
       140 
     | 
    
         
            -
              it "returns an empty string when the current pos is bigger than the content size" do
         
     | 
| 
       141 
     | 
    
         
            -
                @iowrapper.pos = 1000
         
     | 
| 
       142 
     | 
    
         
            -
                @iowrapper.read.should == ''
         
     | 
| 
       143 
     | 
    
         
            -
              end
         
     | 
| 
       144 
     | 
    
         
            -
             
     | 
| 
       145 
     | 
    
         
            -
              it "returns nil at end-of-file with a length" do
         
     | 
| 
       146 
     | 
    
         
            -
                @iowrapper.read
         
     | 
| 
       147 
     | 
    
         
            -
                @iowrapper.read(1).should == nil
         
     | 
| 
       148 
     | 
    
         
            -
              end
         
     | 
| 
       149 
     | 
    
         
            -
             
     | 
| 
       150 
     | 
    
         
            -
              it "with length argument returns nil when the current pos is bigger than the content size" do
         
     | 
| 
       151 
     | 
    
         
            -
                @iowrapper.pos = 1000
         
     | 
| 
       152 
     | 
    
         
            -
                @iowrapper.read(1).should == nil
         
     | 
| 
       153 
     | 
    
         
            -
              end
         
     | 
| 
       154 
     | 
    
         
            -
             
     | 
| 
       155 
     | 
    
         
            -
              it "raises IOError on write-only stream" do
         
     | 
| 
       156 
     | 
    
         
            -
                lambda { IOSpecs.writable_iowrapper.read }.should raise_error(IOError)
         
     | 
| 
       157 
     | 
    
         
            -
              end
         
     | 
| 
       158 
     | 
    
         
            -
             
     | 
| 
       159 
     | 
    
         
            -
              it "raises IOError on closed stream" do
         
     | 
| 
       160 
     | 
    
         
            -
                lambda { IOSpecs.closed_file.read }.should raise_error(IOError)
         
     | 
| 
       161 
     | 
    
         
            -
              end
         
     | 
| 
       162 
     | 
    
         
            -
            end
         
     | 
    
        data/spec/readchar_spec.rb
    DELETED
    
    | 
         @@ -1,49 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.dirname(__FILE__) + '/../spec_helper'
         
     | 
| 
       2 
     | 
    
         
            -
            require File.dirname(__FILE__) + '/fixtures/classes'
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            describe "IO::Like#readchar" do
         
     | 
| 
       5 
     | 
    
         
            -
              before :each do
         
     | 
| 
       6 
     | 
    
         
            -
                @file_name = File.dirname(__FILE__) + '/fixtures/readlines.txt'
         
     | 
| 
       7 
     | 
    
         
            -
                @io = File.open(@file_name, 'r')
         
     | 
| 
       8 
     | 
    
         
            -
                @iowrapper = IOWrapper.open(@io)
         
     | 
| 
       9 
     | 
    
         
            -
              end
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
              after :each do
         
     | 
| 
       12 
     | 
    
         
            -
                @iowrapper.close unless @iowrapper.closed?
         
     | 
| 
       13 
     | 
    
         
            -
                @io.close unless @io.closed?
         
     | 
| 
       14 
     | 
    
         
            -
              end
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
              it "returns the next byte from the stream" do
         
     | 
| 
       17 
     | 
    
         
            -
                @io.readchar.should == 86
         
     | 
| 
       18 
     | 
    
         
            -
                @io.readchar.should == 111
         
     | 
| 
       19 
     | 
    
         
            -
                @io.readchar.should == 105
         
     | 
| 
       20 
     | 
    
         
            -
                # read the rest of line
         
     | 
| 
       21 
     | 
    
         
            -
                @io.readline.should == "ci la ligne une.\n"
         
     | 
| 
       22 
     | 
    
         
            -
                @io.readchar.should == 81
         
     | 
| 
       23 
     | 
    
         
            -
              end
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
              it "raises EOFError when invoked at the end of the stream" do
         
     | 
| 
       26 
     | 
    
         
            -
                # read entire content
         
     | 
| 
       27 
     | 
    
         
            -
                @io.read
         
     | 
| 
       28 
     | 
    
         
            -
                lambda { @io.readchar }.should raise_error(EOFError)
         
     | 
| 
       29 
     | 
    
         
            -
              end
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
              it "raises EOFError when reaches the end of the stream" do
         
     | 
| 
       32 
     | 
    
         
            -
                lambda { loop { @io.readchar } }.should raise_error(EOFError)
         
     | 
| 
       33 
     | 
    
         
            -
              end
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
              it "raises EOFError on empty stream" do
         
     | 
| 
       36 
     | 
    
         
            -
                path = tmp('empty.txt')
         
     | 
| 
       37 
     | 
    
         
            -
                File.open(path, "w+") do |empty|
         
     | 
| 
       38 
     | 
    
         
            -
                  IOWrapper.open(empty) do |iowrapper|
         
     | 
| 
       39 
     | 
    
         
            -
                    lambda { iowrapper.readchar }.should raise_error(EOFError)
         
     | 
| 
       40 
     | 
    
         
            -
                  end
         
     | 
| 
       41 
     | 
    
         
            -
                end
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
                File.unlink(path)
         
     | 
| 
       44 
     | 
    
         
            -
              end
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
              it "raises IOError on closed stream" do
         
     | 
| 
       47 
     | 
    
         
            -
                lambda { IOSpecs.closed_file.readchar }.should raise_error(IOError)
         
     | 
| 
       48 
     | 
    
         
            -
              end
         
     | 
| 
       49 
     | 
    
         
            -
            end
         
     |