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

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

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

DEFAULT_PATH =
"/cable"

Instance Method Summary collapse

Methods included from Assertions

#assert_reject_connection

Instance Method Details

#connect(path = ActionCable.server.config.mount_path, cookies: nil, **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)



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/action_cable/testing/connection/test_case.rb', line 183

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

  unless cookies.nil?
    ActiveSupport::Deprecation.warn(
      "Use `cookies[:param] = value` (or `cookies.signed[:param] = value`). " \
      "Passing `cookies` as the `connect` option is deprecated and is going to be removed in version 1.0"
    )
    cookies.each { |k, v| self.cookies[k] = v }
  end

  connection = self.class.connection_class.allocate
  connection.singleton_class.include(TestConnection)
  connection.send(:initialize, build_test_request(path, **request_params))
  connection.connect if connection.respond_to?(:connect)

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

#cookiesObject



211
212
213
# File 'lib/action_cable/testing/connection/test_case.rb', line 211

def cookies
  @cookie_jar ||= TestCookieJar.new
end

#disconnectObject

Exert #disconnect on the connection under test.



204
205
206
207
208
209
# File 'lib/action_cable/testing/connection/test_case.rb', line 204

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

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