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.
-
#timers ⇒ Object
readonly
Returns the value of attribute timers.
Instance Method Summary collapse
- #advance_time(seconds) ⇒ Object
-
#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, &block) ⇒ Object
- #unsubscribe(stream, callback) ⇒ Object
Constructor Details
#initialize(server) ⇒ TestServer
Returns a new instance of TestServer.
137 138 139 140 141 |
# File 'lib/action_cable/connection/test_case.rb', line 137 def initialize(server) @streams = Hash.new { |h, k| h[k] = [] } @config = server.config @timers = [] end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
135 136 137 |
# File 'lib/action_cable/connection/test_case.rb', line 135 def config @config end |
#streams ⇒ Object (readonly)
Returns the value of attribute streams.
135 136 137 |
# File 'lib/action_cable/connection/test_case.rb', line 135 def streams @streams end |
#timers ⇒ Object (readonly)
Returns the value of attribute timers.
135 136 137 |
# File 'lib/action_cable/connection/test_case.rb', line 135 def timers @timers end |
Instance Method Details
#advance_time(seconds) ⇒ Object
155 156 157 |
# File 'lib/action_cable/connection/test_case.rb', line 155 def advance_time(seconds) @timers.each { |timer| timer.advance(seconds) } end |
#post(&work) ⇒ Object
Inline async calls
149 |
# File 'lib/action_cable/connection/test_case.rb', line 149 def post(&work) = work.call |
#subscribe(stream, callback, success_callback = nil) ⇒ Object
Pub/sub interface ==
160 161 162 163 |
# File 'lib/action_cable/connection/test_case.rb', line 160 def subscribe(stream, callback, success_callback = nil) @streams[stream] << callback success_callback&.call end |
#timer(every, &block) ⇒ Object
151 152 153 |
# File 'lib/action_cable/connection/test_case.rb', line 151 def timer(every, &block) TestTimer.new(every, &block).tap { |t| @timers << t } end |
#unsubscribe(stream, callback) ⇒ Object
165 166 167 168 |
# File 'lib/action_cable/connection/test_case.rb', line 165 def unsubscribe(stream, callback) @streams[stream].delete(callback) @streams.delete(stream) if @streams[stream].empty? end |