Sha256: 8f8cac9a739cddf345191fe01a56b9bd2aba869fa4234936a000aa6a7714bcda
Contents?: true
Size: 1.43 KB
Versions: 1
Compression:
Stored size: 1.43 KB
Contents
require_relative '../../spec_helper' module Kamerling describe Server::TCP do let(:addr) { Addr['localhost', 1981, :TCP] } describe '#addr' do it 'returns the server’s host + port as a TCP addr' do Server::TCP.new(addr: addr).addr.must_equal addr end end describe '#start' do it 'listens on a TCP port and passes received inputs to the handler' do server = Server::TCP.new addr: addr, handler: handler = fake(:handler) server.start s_addr_foo = TCPSocket.open(*server.addr) do |socket| socket << 'foo' Addr[*socket.local_address.ip_unpack, :TCP] end s_addr_bar = TCPSocket.open(*server.addr) do |socket| socket << 'bar' Addr[*socket.local_address.ip_unpack, :TCP] end run_all_threads server.stop handler.must_have_received :handle, ['foo', s_addr_foo] handler.must_have_received :handle, ['bar', s_addr_bar] end it 'doesn’t blow up on unknown inputs' do server = Server::TCP.new addr: addr, handler: handler = fake(:handler) server.start stub(handler).handle('foo', any(Addr)) { fail Handler::UnknownInput } TCPSocket.open(*server.addr) { |socket| socket << 'foo' } server.stop end end describe '#stop' do it 'stops the server' do server = Server::TCP.new(addr: addr).start server.stop -> { TCPSocket.open(*addr).close }.must_raise Errno::ECONNREFUSED end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
kamerling-0.0.2 | spec/kamerling/server/tcp_spec.rb |