@output = output
end
- def open?; true end
+ def open?; not @input.closed? or not @output.closed? end
def read(sz); @input.read(sz) end
def write(buf); @output.write(buf) end
+ def close; @input.close; @output.close end
+ def to_io; @input end # we're assuming this is used in a IO.select for reading
end
deprecate_class! :TIOStreamTransport => IOStreamTransport
end
describe IOStreamTransport do
before(:each) do
- @input = mock("Input")
- @output = mock("Output")
+ @input = mock("Input", :closed? => false)
+ @output = mock("Output", :closed? => false)
@trans = IOStreamTransport.new(@input, @output)
end
- it "should always be open" do
+ it "should be open as long as both input or output are open" do
@trans.should be_open
- @trans.close
+ @input.stub!(:closed?).and_return(true)
+ @trans.should be_open
+ @input.stub!(:closed?).and_return(false)
+ @output.stub!(:closed?).and_return(true)
@trans.should be_open
+ @input.stub!(:closed?).and_return(true)
+ @trans.should_not be_open
end
it "should pass through read/write to input/output" do
@trans.read(17).should == "+ read"
@trans.write("foobar").should == "+ write"
end
+
+ it "should close both input and output when closed" do
+ @input.should_receive(:close)
+ @output.should_receive(:close)
+ @trans.close
+ end
end
end