Class: Zerg::Support::EventMachine::ReceiveMock
- Inherits:
-
Object
- Object
- Zerg::Support::EventMachine::ReceiveMock
- 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
-
#objects ⇒ Object
Returns the value of attribute objects.
-
#strings ⇒ Object
Returns the value of attribute strings.
Class Method Summary collapse
-
.object_name(name) ⇒ Object
Declares the name of the object to be received.
Instance Method Summary collapse
-
#initialize(strings = ['']) ⇒ ReceiveMock
constructor
A new instance of ReceiveMock.
-
#receive__object(object) ⇒ Object
:nodoc:.
-
#replay ⇒ Object
Simulates receiving all the given strings as data from Event Machine.
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
#objects ⇒ Object
Returns the value of attribute objects.
20 21 22 |
# File 'lib/zerg_support/event_machine/connection_mocks.rb', line 20 def objects @objects end |
#strings ⇒ Object
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 |
#replay ⇒ Object
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 |