Skip to content

Instantly share code, notes, and snippets.

@rossta
Created December 25, 2010 05:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rossta/754704 to your computer and use it in GitHub Desktop.
Save rossta/754704 to your computer and use it in GitHub Desktop.
eventmachine socket client mock
class FakeSocketClient < EventMachine::Connection
attr_writer :onopen, :onclose, :onmessage
attr_reader :data
def initialize
@state = :new
@data = []
end
def receive_data(data)
@data << data
if @state == :new
@onopen.call if @onopen
@state = :open
else
@onmessage.call(data) if @onmessage
end
end
def unbind
@onclose.call if @onclose
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment