Sha256: 8b21a5e005c2742c2d2d1053923bf59af78b62c69da4257bfb2c99b3bd66a553

Contents?: true

Size: 1.98 KB

Versions: 83

Compression:

Stored size: 1.98 KB

Contents

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

describe :io_write, :shared => true do
  before :each do
    @filename = tmp("IO_syswrite_file") + $$.to_s
    File.open(@filename, "w") do |file|
      file.send(@method, "012345678901234567890123456789")
    end
    @file = File.open(@filename, "r+")
    @readonly_file = File.open(@filename)
  end

  after :each do
    @file.close
    @readonly_file.close
    File.delete(@filename)
  end

  it "coerces the argument to a string using to_s" do
    (obj = mock('test')).should_receive(:to_s).and_return('a string')
    @file.send(@method, obj)
  end

  it "checks if the file is writable if writing more than zero bytes" do
    lambda { @readonly_file.send(@method, "abcde") }.should raise_error(IOError)
  end

  it "returns the number of bytes written" do
    written = @file.send(@method, "abcde")
    written.should == 5
  end

  it "invokes to_s on non-String argument" do
    data = "abcdefgh9876"
    (obj = mock(data)).should_receive(:to_s).and_return(data)
    @file.send(@method, obj)
    @file.seek(0)
    @file.read(data.length).should == data
  end

  it "writes all of the string's bytes without buffering if mode is sync" do
    @file.sync = true
    written = @file.send(@method, "abcde")
    written.should == 5
    File.open(@filename) do |file|
      file.read(10).should == "abcde56789"
    end
  end

  it "does not warn if called after IO#read" do
    @file.read(5)
    lambda { @file.send(@method, "fghij") }.should_not complain
  end

  it "writes to the current position after IO#read" do
    @file.read(5)
    @file.send(@method, "abcd")
    @file.rewind
    @file.read.should == "01234abcd901234567890123456789"
  end

  it "advances the file position by the count of given bytes" do
    @file.send(@method, "abcde")
    @file.read(10).should == "5678901234"
  end

  it "raises IOError on closed stream" do
    lambda { IOSpecs.closed_file.send(@method, "hello") }.should raise_error(IOError)
  end
end

Version data entries

83 entries across 83 versions & 1 rubygems

Version Path
rhodes-3.1.1 spec/framework_spec/app/spec/core/io/shared/write.rb
rhodes-3.1.1.beta spec/framework_spec/app/spec/core/io/shared/write.rb
rhodes-3.1.0 spec/framework_spec/app/spec/core/io/shared/write.rb
rhodes-3.1.0.beta.5 spec/framework_spec/app/spec/core/io/shared/write.rb
rhodes-3.1.0.beta.4 spec/framework_spec/app/spec/core/io/shared/write.rb
rhodes-3.1.0.beta.3 spec/framework_spec/app/spec/core/io/shared/write.rb
rhodes-3.1.0.beta.2 spec/framework_spec/app/spec/core/io/shared/write.rb
rhodes-3.1.0.beta.1 spec/framework_spec/app/spec/core/io/shared/write.rb
rhodes-3.0.2 spec/framework_spec/app/spec/core/io/shared/write.rb
rhodes-3.0.2.beta.1 spec/framework_spec/app/spec/core/io/shared/write.rb
rhodes-3.0.1 spec/framework_spec/app/spec/core/io/shared/write.rb
rhodes-3.0.1.beta.8 spec/framework_spec/app/spec/core/io/shared/write.rb
rhodes-3.0.1.beta.7 spec/framework_spec/app/spec/core/io/shared/write.rb
rhodes-3.0.1.beta.6 spec/framework_spec/app/spec/core/io/shared/write.rb
rhodes-3.0.1.beta.5 spec/framework_spec/app/spec/core/io/shared/write.rb
rhodes-3.0.1.beta.4 spec/framework_spec/app/spec/core/io/shared/write.rb
rhodes-3.0.1.beta.3 spec/framework_spec/app/spec/core/io/shared/write.rb
rhodes-3.0.1.beta.2 spec/framework_spec/app/spec/core/io/shared/write.rb
rhodes-3.0.0 spec/framework_spec/app/spec/core/io/shared/write.rb
rhodes-3.0.0.beta.7 spec/framework_spec/app/spec/core/io/shared/write.rb