Testing the Ruby TCPSocket Server

I have a small application serving connections (like chat). He catches the connection, captures the login from him, then listens to the data and passes it to each connection except the sender.

The problem is that I'm not a very advanced tester and I don’t know how to check it.

# Handle each connection
def serve(io)
  io.puts("LOGIN\n")
  # Listen for identifier
  user = io.gets.chomp

  ...

  # Add connection to the list
  @mutex.synchronize { @chatters[user] = io }

  # Get and broadcast input until connection returns nil
  loop do

    incoming = io.gets
    broadcast(incoming, io)

  end
end

#Send message out to everyone, but sender
def broadcast(message="", sender)

  # Mutex for safety - GServer uses threads
  @mutex.synchronize do

    @chatters.each do |chatter|

      socket = chatter[1]
      # Do not send to sender
      if sock != sender

        sock.print(message)

      end

    end

  end
end
+3
source share
1 answer

, RSpec mocks ( - ), , , . , , , .

- , -, . , .

, , , , , .

+4
source

All Articles