1
0
Fork 0
mirror of https://github.com/thoughtbot/capybara-webkit synced 2023-03-27 23:22:28 -04:00
capybara-webkit/lib/capybara/webkit/socket_debugger.rb

44 lines
816 B
Ruby
Raw Normal View History

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.
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
private
def sent(content)
Kernel.puts " >> " + content.to_s
end
def received(content)
Kernel.puts " << " + content.to_s
content
end
end
end