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.
-
#replay ⇒ Object
Simulates receiving all the given strings as data from Event Machine.
Constructor Details
#initialize(strings = ['']) ⇒ ReceiveMock
Returns a new instance of ReceiveMock.
25 26 27 28 |
# File 'lib/zerg_support/event_machine/connection_mocks.rb', line 25 def initialize(strings = ['']) @strings = strings.kind_of?(String) ? [strings] : strings @objects = [] end |
Instance Attribute Details
#objects ⇒ Object
Returns the value of attribute objects.
23 24 25 |
# File 'lib/zerg_support/event_machine/connection_mocks.rb', line 23 def objects @objects end |
#strings ⇒ Object
Returns the value of attribute strings.
22 23 24 |
# File 'lib/zerg_support/event_machine/connection_mocks.rb', line 22 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.
39 40 41 42 43 |
# File 'lib/zerg_support/event_machine/connection_mocks.rb', line 39 def self.object_name(name) define_method(:"receive_#{name}") { |object| @objects << object } return if name == :object alias_method :"#{name}s", :objects end |
Instance Method Details
#replay ⇒ Object
Simulates receiving all the given strings as data from Event Machine.
31 32 33 34 |
# File 'lib/zerg_support/event_machine/connection_mocks.rb', line 31 def replay @strings.each { |str| receive_data str } self end |