Created
December 25, 2010 05:26
-
-
Save rossta/754704 to your computer and use it in GitHub Desktop.
eventmachine socket client mock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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