2011-07-22 14:21:15 -04:00
|
|
|
# Wraps the TCP socket and prints data sent and received. Used for debugging
|
|
|
|
# the wire protocol. You can use this by passing a :socket_class to Browser.
|
2012-07-08 15:17:08 -04:00
|
|
|
module Capybara::Webkit
|
2011-07-22 14:21:15 -04:00
|
|
|
class SocketDebugger
|
|
|
|
def self.open(host, port)
|
|
|
|
real_socket = TCPSocket.open(host, port)
|
|
|
|
new(real_socket)
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(socket)
|
|
|
|
@socket = socket
|
|
|
|
end
|
|
|
|
|
|
|
|
def read(length)
|
|
|
|
received @socket.read(length)
|
|
|
|
end
|
|
|
|
|
|
|
|
def puts(line)
|
|
|
|
sent line
|
|
|
|
@socket.puts(line)
|
|
|
|
end
|
|
|
|
|
|
|
|
def print(content)
|
|
|
|
sent content
|
|
|
|
@socket.print(content)
|
|
|
|
end
|
|
|
|
|
|
|
|
def gets
|
|
|
|
received @socket.gets
|
|
|
|
end
|
|
|
|
|
2012-08-10 13:30:34 -04:00
|
|
|
def setsockopt(level, name, value)
|
|
|
|
end
|
|
|
|
|
2011-07-22 14:21:15 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def sent(content)
|
|
|
|
Kernel.puts " >> " + content.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
def received(content)
|
|
|
|
Kernel.puts " << " + content.to_s
|
|
|
|
content
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|