|
28 | 28 | @file.pread(6, 0).should == "foobar"
|
29 | 29 | end
|
30 | 30 |
|
| 31 | + it "calls #to_s on the object to be written" do |
| 32 | + object = mock("to_s") |
| 33 | + object.should_receive(:to_s).and_return("foo") |
| 34 | + @file.pwrite(object, 0) |
| 35 | + @file.pread(3, 0).should == "foo" |
| 36 | + end |
| 37 | + |
| 38 | + it "calls #to_int on the offset" do |
| 39 | + offset = mock("to_int") |
| 40 | + offset.should_receive(:to_int).and_return(2) |
| 41 | + @file.pwrite("foo", offset) |
| 42 | + @file.pread(3, 2).should == "foo" |
| 43 | + end |
| 44 | + |
31 | 45 | it "raises IOError when file is not open in write mode" do
|
32 | 46 | File.open(@fname, "r") do |file|
|
33 |
| - -> { file.pwrite("foo", 1) }.should raise_error(IOError) |
| 47 | + -> { file.pwrite("foo", 1) }.should raise_error(IOError, "not opened for writing") |
34 | 48 | end
|
35 | 49 | end
|
36 | 50 |
|
37 | 51 | it "raises IOError when file is closed" do
|
38 | 52 | file = File.open(@fname, "w+")
|
39 | 53 | file.close
|
40 |
| - -> { file.pwrite("foo", 1) }.should raise_error(IOError) |
| 54 | + -> { file.pwrite("foo", 1) }.should raise_error(IOError, "closed stream") |
| 55 | + end |
| 56 | + |
| 57 | + it "raises a NoMethodError if object does not respond to #to_s" do |
| 58 | + -> { |
| 59 | + @file.pwrite(BasicObject.new, 0) |
| 60 | + }.should raise_error(NoMethodError, /undefined method `to_s'/) |
| 61 | + end |
| 62 | + |
| 63 | + it "raises a TypeError if the offset cannot be converted to an Integer" do |
| 64 | + -> { |
| 65 | + @file.pwrite("foo", Object.new) |
| 66 | + }.should raise_error(TypeError, "no implicit conversion of Object into Integer") |
41 | 67 | end
|
42 | 68 | end
|
43 | 69 | end
|
0 commit comments