Sha256: 5dd25f4d73d63e18cc7ba3cf9f8b2432772a92c5cd92273021342c8a75c28aeb

Contents?: true

Size: 1.12 KB

Versions: 83

Compression:

Stored size: 1.12 KB

Contents

require File.dirname(File.join(__rhoGetCurrentDir(), __FILE__)) + '/../../spec_helper'
require File.dirname(File.join(__rhoGetCurrentDir(), __FILE__)) + '/fixtures/classes'
require File.dirname(File.join(__rhoGetCurrentDir(), __FILE__)) + '/shared/pos'

describe "IO#pos" do
  it_behaves_like(:io_pos, :pos)
end

describe "IO#pos=" do

  before :each do
    @fname = 'test.txt'
    File.open @fname, 'w' do |f| f.write "123" end
  end

  after :each do
    File.unlink @fname
  end

  it "sets the offset" do
    File.open @fname do |f|
      val1 = f.read 1
      f.pos = 0
      f.read(1).should == val1
    end
  end

  it "can handle any numerical argument without breaking" do
    File.open @fname do |io|
      io.pos = 1.2
      io.pos.should == 1

      io.pos = 2**32
      io.pos.should == 2**32

      io.pos = 1.23423423432e12
      io.pos.should == Integer(1.23423423432e12)

      io.pos = Float::EPSILON
      io.pos.should == 0

      lambda { io.pos = 2**128 }.should raise_error(RangeError)
    end
  end
  
  it "raises IOError on closed stream" do
    lambda { IOSpecs.closed_file.pos = 0 }.should raise_error(IOError)
  end

end

Version data entries

83 entries across 83 versions & 1 rubygems

Version Path
rhodes-2.0.2 spec/framework_spec/app/spec/core/io/pos_spec.rb
rhodes-2.0.0 spec/framework_spec/app/spec/core/io/pos_spec.rb
rhodes-2.0.0.rc2 spec/framework_spec/app/spec/core/io/pos_spec.rb
rhodes-2.0.0.rc1 spec/framework_spec/app/spec/core/io/pos_spec.rb
rhodes-2.0.0.beta11 spec/framework_spec/app/spec/core/io/pos_spec.rb
rhodes-2.0.0.beta10 spec/framework_spec/app/spec/core/io/pos_spec.rb
rhodes-2.0.0.beta9 spec/framework_spec/app/spec/core/io/pos_spec.rb
rhodes-2.0.0.beta8 spec/framework_spec/app/spec/core/io/pos_spec.rb
rhodes-2.0.0.beta7 spec/framework_spec/app/spec/core/io/pos_spec.rb
rhodes-2.0.0.beta6 spec/framework_spec/app/spec/core/io/pos_spec.rb
rhodes-2.0.0.beta4 spec/framework_spec/app/spec/core/io/pos_spec.rb
rhodes-2.0.0.beta3 spec/framework_spec/app/spec/core/io/pos_spec.rb
rhodes-1.5.5 spec/framework_spec/app/spec/core/io/pos_spec.rb
rhodes-2.0.0.beta2 spec/framework_spec/app/spec/core/io/pos_spec.rb
rhodes-2.0.0.beta1 spec/framework_spec/app/spec/core/io/pos_spec.rb
rhodes-1.5.4 spec/framework_spec/app/spec/core/io/pos_spec.rb
rhodes-1.5.3 spec/framework_spec/app/spec/core/io/pos_spec.rb
rhodes-1.5.2 spec/framework_spec/app/spec/core/io/pos_spec.rb
rhodes-1.5.1 spec/framework_spec/app/spec/core/io/pos_spec.rb
rhodes-1.5.0 spec/framework_spec/app/spec/core/io/pos_spec.rb