Updated RubySpec source to 55122684.
[rbx.git] / spec / frozen / 1.8 / core / io / rewind_spec.rb
blobc01940b4194511f51eb2859baa1bed4bf4c63b5b
1 require File.dirname(__FILE__) + '/../../spec_helper'
2 require File.dirname(__FILE__) + '/fixtures/classes'
4 describe "IO#rewind" do
5   before :each do
6     @file = File.open(File.dirname(__FILE__) + '/fixtures/readlines.txt', 'r')
7     @io = IO.open @file.fileno, 'r'
8   end
10   after :each do
11     # we *must* close both in order to not leak descriptors
12     @io.close unless @io.closed?
13     @file.close unless @file.closed? rescue Errno::EBADF
14   end
16   it "positions the instance to the beginning of input" do
17     @io.readline.should == "Voici la ligne une.\n"
18     @io.readline.should == "Qui รจ la linea due.\n"
19     @io.rewind
20     @io.readline.should == "Voici la ligne une.\n"
21   end
23   it "sets lineno to 0" do
24     @io.readline.should == "Voici la ligne une.\n"
25     @io.lineno.should == 1
26     @io.rewind
27     @io.lineno.should == 0
28   end
30   it "raises IOError on closed stream" do
31     lambda { IOSpecs.closed_file.rewind }.should raise_error(IOError)
32   end
33 end