blob: e6012c0098baa8034dfc4e4bd4c9ba69b1d9dbe8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# -*- encoding: binary -*-
describe :io_putc, shared: true do
after :each do
@io.close if @io && [email protected]?
@io_object = nil
rm_r @name
end
describe "with an Integer argument" do
it "writes one character as a String" do
@io.should_receive(:write).with("A")
@io_object.send(@method, 65).should == 65
end
it "writes the low byte as a String" do
@io.should_receive(:write).with("A")
@io_object.send(@method, 0x2441).should == 0x2441
end
end
describe "with a String argument" do
it "writes one character" do
@io.should_receive(:write).with("B")
@io_object.send(@method, "B").should == "B"
end
it "writes the first character" do
@io.should_receive(:write).with("R")
@io_object.send(@method, "Ruby").should == "Ruby"
end
end
it "calls #to_int to convert an object to an Integer" do
obj = mock("kernel putc")
obj.should_receive(:to_int).and_return(65)
@io.should_receive(:write).with("A")
@io_object.send(@method, obj).should == obj
end
it "raises IOError on a closed stream" do
@io.close
-> { @io_object.send(@method, "a") }.should raise_error(IOError)
end
it "raises a TypeError when passed nil" do
-> { @io_object.send(@method, nil) }.should raise_error(TypeError)
end
it "raises a TypeError when passed false" do
-> { @io_object.send(@method, false) }.should raise_error(TypeError)
end
it "raises a TypeError when passed true" do
-> { @io_object.send(@method, true) }.should raise_error(TypeError)
end
end
|