Module: ActionCable::Connection::TestCase::Behavior

Extended by:
ActiveSupport::Concern
Includes:
Assertions, ActiveSupport::Testing::ConstantLookup
Included in:
ActionCable::Connection::TestCase
Defined in:
lib/action_cable/connection/test_case.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

DEFAULT_PATH =
"/cable"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Assertions

#assert_reject_connection

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



252
253
254
# File 'lib/action_cable/connection/test_case.rb', line 252

def connection
  @connection
end

#socketObject (readonly)

Returns the value of attribute socket.



252
253
254
# File 'lib/action_cable/connection/test_case.rb', line 252

def socket
  @socket
end

#testserverObject (readonly)

Returns the value of attribute testserver.



252
253
254
# File 'lib/action_cable/connection/test_case.rb', line 252

def testserver
  @testserver
end

Instance Method Details

#connect(path = ActionCable.server.config.mount_path, server: ActionCable.server, **request_params) ⇒ Object

Performs connection attempt to exert #connect on the connection under test.

Accepts request path as the first argument and the following request options:

  • params – URL parameters (Hash)

  • headers – request headers (Hash)

  • session – session data (Hash)

  • env – additional Rack env configuration (Hash)



262
263
264
265
266
267
268
269
270
271
272
# File 'lib/action_cable/connection/test_case.rb', line 262

def connect(path = ActionCable.server.config.mount_path, server: ActionCable.server, **request_params)
  path ||= DEFAULT_PATH

  @socket = TestSocket.new(TestSocket.build_request(path, **request_params, cookies: cookies))
  @testserver = Connection::TestServer.new(server)
  connection = self.class.connection_class.new(@testserver, socket)
  connection.connect if connection.respond_to?(:connect)

  # Only set instance variable if connected successfully
  @connection = connection
end

#cookiesObject



282
283
284
# File 'lib/action_cable/connection/test_case.rb', line 282

def cookies
  @cookie_jar ||= TestCookieJar.new
end

#disconnectObject

Exert #disconnect on the connection under test.



275
276
277
278
279
280
# File 'lib/action_cable/connection/test_case.rb', line 275

def disconnect
  raise "Must be connected!" if connection.nil?

  connection.disconnect if connection.respond_to?(:disconnect)
  @connection = nil
end

#transmissionsObject



286
287
288
# File 'lib/action_cable/connection/test_case.rb', line 286

def transmissions
  socket&.transmissions || []
end