aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/test
diff options
context:
space:
mode:
authorutilum <oz@utilum.com>2018-04-22 18:33:40 +0200
committerutilum <oz@utilum.com>2018-04-26 08:02:08 +0200
commit94ceda00b99794d4f8c28e84d237cc1541af12d7 (patch)
treedaf32b6039ce0056950dd22a915fdc71087029b0 /actioncable/test
parente4e25cc8dc76f641a304251ba37e1db99713e584 (diff)
downloadrails-94ceda00b99794d4f8c28e84d237cc1541af12d7.tar.gz
rails-94ceda00b99794d4f8c28e84d237cc1541af12d7.tar.bz2
rails-94ceda00b99794d4f8c28e84d237cc1541af12d7.zip
assert_called
Diffstat (limited to 'actioncable/test')
-rw-r--r--actioncable/test/channel/stream_test.rb20
-rw-r--r--actioncable/test/client_test.rb10
-rw-r--r--actioncable/test/connection/authorization_test.rb9
-rw-r--r--actioncable/test/connection/base_test.rb21
-rw-r--r--actioncable/test/connection/identifier_test.rb5
-rw-r--r--actioncable/test/connection/stream_test.rb8
-rw-r--r--actioncable/test/connection/subscriptions_test.rb18
-rw-r--r--actioncable/test/server/base_test.rb18
8 files changed, 71 insertions, 38 deletions
diff --git a/actioncable/test/channel/stream_test.rb b/actioncable/test/channel/stream_test.rb
index df9d44d8dd..53dd7e5b77 100644
--- a/actioncable/test/channel/stream_test.rb
+++ b/actioncable/test/channel/stream_test.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true
require "test_helper"
+require "active_support/testing/method_call_assertions"
require "stubs/test_connection"
require "stubs/room"
@@ -143,6 +144,8 @@ module ActionCable::StreamTests
end
class StreamFromTest < ActionCable::TestCase
+ include ActiveSupport::Testing::MethodCallAssertions
+
setup do
@server = TestServer.new(subscription_adapter: ActionCable::SubscriptionAdapter::Async)
@server.config.allowed_request_origins = %w( http://rubyonrails.com )
@@ -153,10 +156,11 @@ module ActionCable::StreamTests
connection = open_connection
subscribe_to connection, identifiers: { id: 1 }
- connection.websocket.expects(:transmit)
- @server.broadcast "test_room_1", { foo: "bar" }, { coder: DummyEncoder }
- wait_for_async
- wait_for_executor connection.server.worker_pool.executor
+ assert_called(connection.websocket, :transmit) do
+ @server.broadcast "test_room_1", { foo: "bar" }, { coder: DummyEncoder }
+ wait_for_async
+ wait_for_executor connection.server.worker_pool.executor
+ end
end
end
@@ -175,10 +179,10 @@ module ActionCable::StreamTests
run_in_eventmachine do
connection = open_connection
expected = { "identifier" => { "channel" => MultiChatChannel.name }.to_json, "type" => "confirm_subscription" }
- connection.websocket.expects(:transmit).with(expected.to_json)
- receive(connection, command: "subscribe", channel: MultiChatChannel.name, identifiers: {})
-
- wait_for_async
+ assert_called(connection.websocket, :transmit, [expected.to_json]) do
+ receive(connection, command: "subscribe", channel: MultiChatChannel.name, identifiers: {})
+ wait_for_async
+ end
end
end
diff --git a/actioncable/test/client_test.rb b/actioncable/test/client_test.rb
index ec672a5828..92fe59c803 100644
--- a/actioncable/test/client_test.rb
+++ b/actioncable/test/client_test.rb
@@ -7,6 +7,7 @@ require "websocket-client-simple"
require "json"
require "active_support/hash_with_indifferent_access"
+require "active_support/testing/method_call_assertions"
####
# 😷 Warning suppression 😷
@@ -27,6 +28,8 @@ WebSocket::Frame::Data.prepend Module.new {
####
class ClientTest < ActionCable::TestCase
+ include ActiveSupport::Testing::MethodCallAssertions
+
WAIT_WHEN_EXPECTING_EVENT = 2
WAIT_WHEN_NOT_EXPECTING_EVENT = 0.5
@@ -289,9 +292,10 @@ class ClientTest < ActionCable::TestCase
subscriptions = app.connections.first.subscriptions.send(:subscriptions)
assert_not_equal 0, subscriptions.size, "Missing EchoChannel subscription"
channel = subscriptions.first[1]
- channel.expects(:unsubscribed)
- c.close
- sleep 0.1 # Data takes a moment to process
+ assert_called(channel, :unsubscribed) do
+ c.close
+ sleep 0.1 # Data takes a moment to process
+ end
# All data is removed: No more connection or subscription information!
assert_equal(0, app.connections.count)
diff --git a/actioncable/test/connection/authorization_test.rb b/actioncable/test/connection/authorization_test.rb
index 7d039336b8..be41d510ff 100644
--- a/actioncable/test/connection/authorization_test.rb
+++ b/actioncable/test/connection/authorization_test.rb
@@ -1,9 +1,12 @@
# frozen_string_literal: true
require "test_helper"
+require "active_support/testing/method_call_assertions"
require "stubs/test_server"
class ActionCable::Connection::AuthorizationTest < ActionCable::TestCase
+ include ActiveSupport::Testing::MethodCallAssertions
+
class Connection < ActionCable::Connection::Base
attr_reader :websocket
@@ -25,9 +28,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 ac10b3d4d2..cbeac1bb3a 100644
--- a/actioncable/test/connection/base_test.rb
+++ b/actioncable/test/connection/base_test.rb
@@ -3,8 +3,11 @@
require "test_helper"
require "stubs/test_server"
require "active_support/core_ext/object/json"
+require "active_support/testing/method_call_assertions"
class ActionCable::Connection::BaseTest < ActionCable::TestCase
+ include ActiveSupport::Testing::MethodCallAssertions
+
class Connection < ActionCable::Connection::Base
attr_reader :websocket, :subscriptions, :message_buffer, :connected
@@ -60,10 +63,10 @@ class ActionCable::Connection::BaseTest < ActionCable::TestCase
connection = open_connection
connection.websocket.expects(:transmit).with({ type: "welcome" }.to_json)
- connection.message_buffer.expects(:process!)
-
- connection.process
- wait_for_async
+ assert_called(connection.message_buffer, :process!) do
+ connection.process
+ wait_for_async
+ end
assert_equal [ connection ], @server.connections
assert connection.connected
@@ -80,8 +83,9 @@ class ActionCable::Connection::BaseTest < ActionCable::TestCase
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_not connection.connected
assert_equal [], @server.connections
@@ -106,8 +110,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/identifier_test.rb b/actioncable/test/connection/identifier_test.rb
index f3bc6f99a4..de1ae1d5b9 100644
--- a/actioncable/test/connection/identifier_test.rb
+++ b/actioncable/test/connection/identifier_test.rb
@@ -44,8 +44,9 @@ class ActionCable::Connection::IdentifierTest < ActionCable::TestCase
run_in_eventmachine do
open_connection_with_stubbed_pubsub
- @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
diff --git a/actioncable/test/connection/stream_test.rb b/actioncable/test/connection/stream_test.rb
index b0419b0994..1e1466af31 100644
--- a/actioncable/test/connection/stream_test.rb
+++ b/actioncable/test/connection/stream_test.rb
@@ -1,9 +1,12 @@
# frozen_string_literal: true
require "test_helper"
+require "active_support/testing/method_call_assertions"
require "stubs/test_server"
class ActionCable::Connection::StreamTest < ActionCable::TestCase
+ include ActiveSupport::Testing::MethodCallAssertions
+
class Connection < ActionCable::Connection::Base
attr_reader :connected, :websocket, :errors
@@ -42,9 +45,10 @@ 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")
+ assert_called(client, :client_gone) do
+ client.write("boo")
+ end
assert_equal [], connection.errors
end
end
diff --git a/actioncable/test/connection/subscriptions_test.rb b/actioncable/test/connection/subscriptions_test.rb
index 3323785494..7bc8c4241c 100644
--- a/actioncable/test/connection/subscriptions_test.rb
+++ b/actioncable/test/connection/subscriptions_test.rb
@@ -1,8 +1,11 @@
# frozen_string_literal: true
require "test_helper"
+require "active_support/testing/method_call_assertions"
class ActionCable::Connection::SubscriptionsTest < ActionCable::TestCase
+ include ActiveSupport::Testing::MethodCallAssertions
+
class Connection < ActionCable::Connection::Base
attr_reader :websocket
@@ -55,9 +58,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 +97,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
diff --git a/actioncable/test/server/base_test.rb b/actioncable/test/server/base_test.rb
index 1312e45f49..3b5931f0a4 100644
--- a/actioncable/test/server/base_test.rb
+++ b/actioncable/test/server/base_test.rb
@@ -3,8 +3,11 @@
require "test_helper"
require "stubs/test_server"
require "active_support/core_ext/hash/indifferent_access"
+require "active_support/testing/method_call_assertions"
class BaseTest < ActiveSupport::TestCase
+ include ActiveSupport::Testing::MethodCallAssertions
+
def setup
@server = ActionCable::Server::Base.new
@server.config.cable = { adapter: "async" }.with_indifferent_access
@@ -19,17 +22,20 @@ class BaseTest < ActiveSupport::TestCase
conn = FakeConnection.new
@server.add_connection(conn)
- conn.expects(:close)
- @server.restart
+ assert_called(conn, :close) do
+ @server.restart
+ end
end
test "#restart shuts down worker pool" do
- @server.worker_pool.expects(:halt)
- @server.restart
+ assert_called(@server.worker_pool, :halt) do
+ @server.restart
+ end
end
test "#restart shuts down pub/sub adapter" do
- @server.pubsub.expects(:shutdown)
- @server.restart
+ assert_called(@server.pubsub, :shutdown) do
+ @server.restart
+ end
end
end