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

47 lines
864 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
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