Sha256: 971f9187f72fdb0d4c9b131fa2ae2d5266c6d0dfa5ffe82b1bc410603c375745
Contents?: true
Size: 1.64 KB
Versions: 1
Compression:
Stored size: 1.64 KB
Contents
# frozen_string_literal: true require "test_helper" require "stubs/test_server" class ActionCable::Connection::StreamTest < ActionCable::TestCase class Connection < ActionCable::Connection::Base attr_reader :connected, :websocket, :errors def initialize(*) super @errors = [] end def connect @connected = true end def disconnect @connected = false end def send_async(method, *args) send method, *args end def on_error(message) @errors << message end end setup do @server = TestServer.new @server.config.allowed_request_origins = %w( http://rubyonquails.com ) end [ EOFError, Errno::ECONNRESET ].each do |closed_exception| test "closes socket on #{closed_exception}" do run_in_eventmachine do connection = open_connection # Internal hax = :( client = connection.websocket.send(:websocket) client.instance_variable_get("@stream").instance_variable_get("@rack_hijack_io").expects(:write).raises(closed_exception, "foo") client.expects(:client_gone) client.write("boo") assert_equal [], connection.errors end end end private def open_connection env = Rack::MockRequest.env_for "/test", "HTTP_CONNECTION" => "upgrade", "HTTP_UPGRADE" => "websocket", "HTTP_HOST" => "localhost", "HTTP_ORIGIN" => "http://rubyonquails.com" env["rack.hijack"] = -> { env["rack.hijack_io"] = StringIO.new } Connection.new(@server, env).tap do |connection| connection.process connection.send :handle_open assert connection.connected end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ruby-on-quails-0.1.0 | actioncable/test/connection/stream_test.rb |