diff --git a/core/io/pwrite_spec.rb b/core/io/pwrite_spec.rb index c10578a8e..2691d2c11 100644 --- a/core/io/pwrite_spec.rb +++ b/core/io/pwrite_spec.rb @@ -28,6 +28,20 @@ @file.pread(6, 0).should == "foobar" end + it "calls #to_s on the object to be written" do + data = mock("to_s") + data.should_receive(:to_s).and_return("foo") + @file.pwrite(data, 0) + @file.pread(3, 0).should == "foo" + end + + it "calls #to_int on the offset" do + offset = mock("to_int") + offset.should_receive(:to_int).and_return(2) + @file.pwrite("foo", offset) + @file.pread(3, 2).should == "foo" + end + it "raises IOError when file is not open in write mode" do File.open(@fname, "r") do |file| -> { file.pwrite("foo", 1) }.should raise_error(IOError) @@ -39,5 +53,17 @@ file.close -> { file.pwrite("foo", 1) }.should raise_error(IOError) end + + it "raises a NoMethodError if #to_s cannot be called on the object to be written" do + -> { + @file.pwrite(BasicObject.new, 0) + }.should raise_error(NoMethodError, /undefined method `to_s'/) + end + + it "raises a TypeError if the offset cannot be converted to an Integer" do + -> { + @file.pwrite("foo", Object.new) + }.should raise_error(TypeError, "no implicit conversion of Object into Integer") + end end end