Sha256: e3a5de285096391b312d6dad36aa66e19e2b7dd34cb41472eb7a83e591603235

Contents?: true

Size: 826 Bytes

Versions: 1

Compression:

Stored size: 826 Bytes

Contents

require 'helper'

class TestIOListener < Test::Unit::TestCase
  context "a server" do
    setup do
      r1, w1 = IO.pipe # Server -> Client
      r2, w2 = IO.pipe # Client -> Server

      @server = PacketIO::IOListener.new(r1, w2)
      @protocol = PacketIO::LineBasedProtocol.new(@server)
      @device = PacketIO::Test::MockServer.new(r2, w1)
    end

    should "exist" do
      assert_not_nil @server
    end

    should "yield packets written to it" do
      @packets = []
      @protocol.on_data { |packet| @packets << packet }

      @device.write("fo").wait.write("o\n").wait.write("bar\n").eof
      @server.run!

      assert_equal ["foo", "bar"], @packets
    end

    should "send data" do
      @protocol << "hello world"
      data = @device.read_all
      assert_equal "hello world\n", data
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
packet_io-0.4.0.rc2 test/test_io_listener.rb