Class: ActionCable::Connection::TestServer
- Inherits:
-
Object
- Object
- ActionCable::Connection::TestServer
- Defined in:
- lib/action_cable/connection/test_case.rb
Overview
TestServer provides test pub/sub and executor implementations
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#streams ⇒ Object
readonly
Returns the value of attribute streams.
Instance Method Summary collapse
-
#initialize(server) ⇒ TestServer
constructor
A new instance of TestServer.
-
#post(&work) ⇒ Object
Inline async calls.
-
#subscribe(stream, callback, success_callback = nil) ⇒ Object
Pub/sub interface ==.
-
#timer(_every) ⇒ Object
We don’t support timers in unit tests yet.
- #unsubscribe(stream, callback) ⇒ Object
Constructor Details
#initialize(server) ⇒ TestServer
Returns a new instance of TestServer.
109 110 111 112 |
# File 'lib/action_cable/connection/test_case.rb', line 109 def initialize(server) @streams = Hash.new { |h, k| h[k] = [] } @config = server.config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
107 108 109 |
# File 'lib/action_cable/connection/test_case.rb', line 107 def config @config end |
#streams ⇒ Object (readonly)
Returns the value of attribute streams.
107 108 109 |
# File 'lib/action_cable/connection/test_case.rb', line 107 def streams @streams end |
Instance Method Details
#post(&work) ⇒ Object
Inline async calls
120 121 |
# File 'lib/action_cable/connection/test_case.rb', line 120 def post(&work) = work.call # We don't support timers in unit tests yet |
#subscribe(stream, callback, success_callback = nil) ⇒ Object
Pub/sub interface ==
125 126 127 128 |
# File 'lib/action_cable/connection/test_case.rb', line 125 def subscribe(stream, callback, success_callback = nil) @streams[stream] << callback success_callback&.call end |
#timer(_every) ⇒ Object
We don’t support timers in unit tests yet
122 |
# File 'lib/action_cable/connection/test_case.rb', line 122 def timer(_every) = nil |
#unsubscribe(stream, callback) ⇒ Object
130 131 132 133 |
# File 'lib/action_cable/connection/test_case.rb', line 130 def unsubscribe(stream, callback) @streams[stream].delete(callback) @streams.delete(stream) if @streams[stream].empty? end |