Class: Rubyfox::Client::Recorder
- Inherits:
-
Object
- Object
- Rubyfox::Client::Recorder
- Includes:
- Timeout
- Defined in:
- lib/rubyfox/client/recorder.rb
Overview
Records all incoming and outgoing events, requests and extension requests for test purposes.
Example
client = Rubyfox::Client.new
recorder = Rubyfox::Rubyfox::Recorder.new(client)
client.connect
client.send :login, "username", "password", "zone"
client.disconnect
assert_equal 1, recorder.events(:connection).size
assert_equal 1, recorder.events(:login).size
assert_equal 1, recorder.extensions("Me.User").size
assert_equal 1, recorder.events(:connection_lost).size
Instance Method Summary collapse
- #events(name) ⇒ Object
- #extensions(command) ⇒ Object
-
#initialize(client) ⇒ Recorder
constructor
A new instance of Recorder.
- #verify(options = {}, &block) ⇒ Object
Constructor Details
#initialize(client) ⇒ Recorder
Returns a new instance of Recorder.
25 26 27 28 29 30 31 |
# File 'lib/rubyfox/client/recorder.rb', line 25 def initialize(client) @client = client @events = Hash.new { |hash, type| hash[type] = [] } @extensions = Hash.new { |hash, command| hash[command] = [] } @connection_lost = false install_callbacks end |
Instance Method Details
#events(name) ⇒ Object
33 34 35 36 |
# File 'lib/rubyfox/client/recorder.rb', line 33 def events(name) type = Event[name] @events[type] end |
#extensions(command) ⇒ Object
38 39 40 |
# File 'lib/rubyfox/client/recorder.rb', line 38 def extensions(command) @extensions[command] end |
#verify(options = {}, &block) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rubyfox/client/recorder.rb', line 42 def verify(={}, &block) @client.connect wait = [:timeout] || 1 timeout wait do while not @connection_lost sleep 0.1 end end rescue Timeout::Error # ignore ensure yield end |