diff options
Diffstat (limited to 'actioncable/test/connection')
-rw-r--r-- | actioncable/test/connection/authorization_test.rb | 6 | ||||
-rw-r--r-- | actioncable/test/connection/base_test.rb | 24 | ||||
-rw-r--r-- | actioncable/test/connection/client_socket_test.rb | 8 | ||||
-rw-r--r-- | actioncable/test/connection/identifier_test.rb | 40 | ||||
-rw-r--r-- | actioncable/test/connection/multiple_identifiers_test.rb | 11 | ||||
-rw-r--r-- | actioncable/test/connection/stream_test.rb | 11 | ||||
-rw-r--r-- | actioncable/test/connection/string_identifier_test.rb | 13 | ||||
-rw-r--r-- | actioncable/test/connection/subscriptions_test.rb | 15 |
8 files changed, 64 insertions, 64 deletions
diff --git a/actioncable/test/connection/authorization_test.rb b/actioncable/test/connection/authorization_test.rb index 7d039336b8..f77e543435 100644 --- a/actioncable/test/connection/authorization_test.rb +++ b/actioncable/test/connection/authorization_test.rb @@ -25,9 +25,9 @@ class ActionCable::Connection::AuthorizationTest < ActionCable::TestCase "HTTP_HOST" => "localhost", "HTTP_ORIGIN" => "http://rubyonrails.com" connection = Connection.new(server, env) - connection.websocket.expects(:close) - - connection.process + assert_called(connection.websocket, :close) do + connection.process + end end end end diff --git a/actioncable/test/connection/base_test.rb b/actioncable/test/connection/base_test.rb index c69d4d0b36..6ffa0961bc 100644 --- a/actioncable/test/connection/base_test.rb +++ b/actioncable/test/connection/base_test.rb @@ -59,11 +59,12 @@ class ActionCable::Connection::BaseTest < ActionCable::TestCase run_in_eventmachine do connection = open_connection - connection.websocket.expects(:transmit).with({ type: "welcome" }.to_json) - connection.message_buffer.expects(:process!) - - connection.process - wait_for_async + assert_called_with(connection.websocket, :transmit, [{ type: "welcome" }.to_json]) do + assert_called(connection.message_buffer, :process!) do + connection.process + wait_for_async + end + end assert_equal [ connection ], @server.connections assert connection.connected @@ -76,14 +77,14 @@ class ActionCable::Connection::BaseTest < ActionCable::TestCase connection.process # Setup the connection - connection.server.stubs(:timer).returns(true) connection.send :handle_open assert connection.connected - connection.subscriptions.expects(:unsubscribe_from_all) - connection.send :handle_close + assert_called(connection.subscriptions, :unsubscribe_from_all) do + connection.send :handle_close + end - assert ! connection.connected + assert_not connection.connected assert_equal [], @server.connections end end @@ -106,8 +107,9 @@ class ActionCable::Connection::BaseTest < ActionCable::TestCase connection = open_connection connection.process - connection.websocket.expects(:close) - connection.close + assert_called(connection.websocket, :close) do + connection.close + end end end diff --git a/actioncable/test/connection/client_socket_test.rb b/actioncable/test/connection/client_socket_test.rb index 5c31690c8b..9176c7ac8b 100644 --- a/actioncable/test/connection/client_socket_test.rb +++ b/actioncable/test/connection/client_socket_test.rb @@ -40,10 +40,12 @@ class ActionCable::Connection::ClientSocketTest < ActionCable::TestCase # Internal hax = :( client = connection.websocket.send(:websocket) - client.instance_variable_get("@stream").expects(:write).raises("foo") - client.expects(:client_gone).never + client.instance_variable_get("@stream").stub(:write, proc { raise "foo" }) do - client.write("boo") + assert_not_called(client, :client_gone) do + client.write("boo") + end + end assert_equal %w[ foo ], connection.errors end end diff --git a/actioncable/test/connection/identifier_test.rb b/actioncable/test/connection/identifier_test.rb index 6b6c8cd31a..707f4bab72 100644 --- a/actioncable/test/connection/identifier_test.rb +++ b/actioncable/test/connection/identifier_test.rb @@ -18,52 +18,52 @@ class ActionCable::Connection::IdentifierTest < ActionCable::TestCase test "connection identifier" do run_in_eventmachine do - open_connection_with_stubbed_pubsub + open_connection assert_equal "User#lifo", @connection.connection_identifier end end test "should subscribe to internal channel on open and unsubscribe on close" do run_in_eventmachine do - pubsub = mock("pubsub_adapter") - pubsub.expects(:subscribe).with("action_cable/User#lifo", kind_of(Proc)) - pubsub.expects(:unsubscribe).with("action_cable/User#lifo", kind_of(Proc)) - server = TestServer.new - server.stubs(:pubsub).returns(pubsub) - open_connection server: server + open_connection(server) close_connection + wait_for_async + + %w[subscribe unsubscribe].each do |method| + pubsub_call = server.pubsub.class.class_variable_get "@@#{method}_called" + + assert_equal "action_cable/User#lifo", pubsub_call[:channel] + assert_instance_of Proc, pubsub_call[:callback] + end end end test "processing disconnect message" do run_in_eventmachine do - open_connection_with_stubbed_pubsub + open_connection - @connection.websocket.expects(:close) - @connection.process_internal_message "type" => "disconnect" + assert_called(@connection.websocket, :close) do + @connection.process_internal_message "type" => "disconnect" + end end end test "processing invalid message" do run_in_eventmachine do - open_connection_with_stubbed_pubsub + open_connection - @connection.websocket.expects(:close).never - @connection.process_internal_message "type" => "unknown" + assert_not_called(@connection.websocket, :close) do + @connection.process_internal_message "type" => "unknown" + end end end private - def open_connection_with_stubbed_pubsub - server = TestServer.new - server.stubs(:adapter).returns(stub_everything("adapter")) - - open_connection server: server - end + def open_connection(server = nil) + server ||= TestServer.new - def open_connection(server:) env = Rack::MockRequest.env_for "/test", "HTTP_HOST" => "localhost", "HTTP_CONNECTION" => "upgrade", "HTTP_UPGRADE" => "websocket" @connection = Connection.new(server, env) diff --git a/actioncable/test/connection/multiple_identifiers_test.rb b/actioncable/test/connection/multiple_identifiers_test.rb index 7f90cb3876..51716410b2 100644 --- a/actioncable/test/connection/multiple_identifiers_test.rb +++ b/actioncable/test/connection/multiple_identifiers_test.rb @@ -16,20 +16,15 @@ class ActionCable::Connection::MultipleIdentifiersTest < ActionCable::TestCase test "multiple connection identifiers" do run_in_eventmachine do - open_connection_with_stubbed_pubsub + open_connection + assert_equal "Room#my-room:User#lifo", @connection.connection_identifier end end private - def open_connection_with_stubbed_pubsub + def open_connection server = TestServer.new - server.stubs(:pubsub).returns(stub_everything("pubsub")) - - open_connection server: server - end - - def open_connection(server:) env = Rack::MockRequest.env_for "/test", "HTTP_HOST" => "localhost", "HTTP_CONNECTION" => "upgrade", "HTTP_UPGRADE" => "websocket" @connection = Connection.new(server, env) diff --git a/actioncable/test/connection/stream_test.rb b/actioncable/test/connection/stream_test.rb index b0419b0994..0f4576db40 100644 --- a/actioncable/test/connection/stream_test.rb +++ b/actioncable/test/connection/stream_test.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "test_helper" +require "minitest/mock" require "stubs/test_server" class ActionCable::Connection::StreamTest < ActionCable::TestCase @@ -41,10 +42,12 @@ class ActionCable::Connection::StreamTest < ActionCable::TestCase # 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") + rack_hijack_io = client.instance_variable_get("@stream").instance_variable_get("@rack_hijack_io") + rack_hijack_io.stub(:write, proc { raise(closed_exception, "foo") }) do + assert_called(client, :client_gone) do + client.write("boo") + end + end assert_equal [], connection.errors end end diff --git a/actioncable/test/connection/string_identifier_test.rb b/actioncable/test/connection/string_identifier_test.rb index 4cb58e7fd0..f7019b926a 100644 --- a/actioncable/test/connection/string_identifier_test.rb +++ b/actioncable/test/connection/string_identifier_test.rb @@ -18,22 +18,17 @@ class ActionCable::Connection::StringIdentifierTest < ActionCable::TestCase test "connection identifier" do run_in_eventmachine do - open_connection_with_stubbed_pubsub + open_connection + assert_equal "random-string", @connection.connection_identifier end end private - def open_connection_with_stubbed_pubsub - @server = TestServer.new - @server.stubs(:pubsub).returns(stub_everything("pubsub")) - - open_connection - end - def open_connection + server = TestServer.new env = Rack::MockRequest.env_for "/test", "HTTP_HOST" => "localhost", "HTTP_CONNECTION" => "upgrade", "HTTP_UPGRADE" => "websocket" - @connection = Connection.new(@server, env) + @connection = Connection.new(server, env) @connection.process @connection.send :on_open diff --git a/actioncable/test/connection/subscriptions_test.rb b/actioncable/test/connection/subscriptions_test.rb index 3323785494..902085c5d6 100644 --- a/actioncable/test/connection/subscriptions_test.rb +++ b/actioncable/test/connection/subscriptions_test.rb @@ -55,9 +55,11 @@ class ActionCable::Connection::SubscriptionsTest < ActionCable::TestCase subscribe_to_chat_channel channel = subscribe_to_chat_channel - channel.expects(:unsubscribe_from_channel) - @subscriptions.execute_command "command" => "unsubscribe", "identifier" => @chat_identifier + assert_called(channel, :unsubscribe_from_channel) do + @subscriptions.execute_command "command" => "unsubscribe", "identifier" => @chat_identifier + end + assert_empty @subscriptions.identifiers end end @@ -92,10 +94,11 @@ class ActionCable::Connection::SubscriptionsTest < ActionCable::TestCase channel2_id = ActiveSupport::JSON.encode(id: 2, channel: "ActionCable::Connection::SubscriptionsTest::ChatChannel") channel2 = subscribe_to_chat_channel(channel2_id) - channel1.expects(:unsubscribe_from_channel) - channel2.expects(:unsubscribe_from_channel) - - @subscriptions.unsubscribe_from_all + assert_called(channel1, :unsubscribe_from_channel) do + assert_called(channel2, :unsubscribe_from_channel) do + @subscriptions.unsubscribe_from_all + end + end end end |