hydra/test/test_pipe.rb

45 lines
1.2 KiB
Ruby
Raw Normal View History

2010-01-26 20:31:03 +00:00
require File.join(File.dirname(__FILE__), 'helper')
2010-01-26 18:50:44 +00:00
2010-01-26 20:31:03 +00:00
class TestPipe < Test::Unit::TestCase
2010-01-26 18:50:44 +00:00
context "a pipe" do
setup do
@pipe = Hydra::Pipe.new
end
should "be able to write messages" do
Process.fork do
@pipe.identify_as_child
2010-01-26 20:35:58 +00:00
assert_equal "Test Message", @pipe.gets
@pipe.write "Message Received"
@pipe.write "Second Message"
2010-01-26 18:50:44 +00:00
@pipe.close
end
@pipe.identify_as_parent
2010-01-26 20:35:58 +00:00
@pipe.write "Test Message"
assert_equal "Message Received", @pipe.gets
assert_equal "Second Message", @pipe.gets
2010-01-26 18:50:44 +00:00
assert_raise Hydra::PipeError::Broken do
@pipe.write "anybody home?"
end
@pipe.close
end
should "not allow writing if unidentified" do
assert_raise Hydra::PipeError::Unidentified do
@pipe.write "hey\n"
end
end
should "not allow reading if unidentified" do
assert_raise Hydra::PipeError::Unidentified do
@pipe.gets
end
end
2010-01-26 20:35:58 +00:00
should "handle newlines" do
Process.fork do
@pipe.identify_as_child
@pipe.write "Message\n"
end
@pipe.identify_as_parent
assert_equal "Message", @pipe.gets
end
2010-01-26 18:50:44 +00:00
end
end