Class: Zerg::Support::EventMachine::ReceiveMock

Inherits:
Object
  • Object
show all
Defined in:
lib/zerg_support/event_machine/connection_mocks.rb

Overview

Mocks the receiving end of an EventMachine connection. The data to be received is passed as an array of strings to the constructor. Calling #replay mocks receiving the data.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(strings = ['']) ⇒ ReceiveMock

Returns a new instance of ReceiveMock.



22
23
24
25
# File 'lib/zerg_support/event_machine/connection_mocks.rb', line 22

def initialize(strings = [''])
  @strings = strings
  @objects = []
end

Instance Attribute Details

#objectsObject

Returns the value of attribute objects.



20
21
22
# File 'lib/zerg_support/event_machine/connection_mocks.rb', line 20

def objects
  @objects
end

#stringsObject

Returns the value of attribute strings.



19
20
21
# File 'lib/zerg_support/event_machine/connection_mocks.rb', line 19

def strings
  @strings
end

Class Method Details

.object_name(name) ⇒ Object

Declares the name of the object to be received. For instance, a frame protocol would use :frame for name. This generates a receive_frame method, and a frames accessor.



41
42
43
44
45
# File 'lib/zerg_support/event_machine/connection_mocks.rb', line 41

def self.object_name(name)
  alias_method "receive_#{name}".to_sym, :receive__object
  return if name == :object
  alias_method "#{name}s".to_sym, :objects
end

Instance Method Details

#receive__object(object) ⇒ Object

:nodoc:



34
35
36
# File 'lib/zerg_support/event_machine/connection_mocks.rb', line 34

def receive__object(object)
  @objects << object
end

#replayObject

Simulates receiving all the given strings as data from Event Machine.



28
29
30
31
# File 'lib/zerg_support/event_machine/connection_mocks.rb', line 28

def replay
  @strings.each { |str| receive_data str }
  self
end