aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/test
diff options
context:
space:
mode:
authorutilum <oz@utilum.com>2018-05-13 18:00:54 +0200
committerutilum <oz@utilum.com>2018-05-22 02:29:18 +0200
commit78288f75e127182751938353ef3005a29d9c3bc1 (patch)
tree7bbb3fb358348e2f2968ddfa59274568d06ef19b /actioncable/test
parent6c574ac58993512f975ddaf1f679c5956cc576df (diff)
downloadrails-78288f75e127182751938353ef3005a29d9c3bc1.tar.gz
rails-78288f75e127182751938353ef3005a29d9c3bc1.tar.bz2
rails-78288f75e127182751938353ef3005a29d9c3bc1.zip
remove unnecessary mocking in ActionCable tests
Diffstat (limited to 'actioncable/test')
-rw-r--r--actioncable/test/channel/stream_test.rb11
-rw-r--r--actioncable/test/connection/base_test.rb1
-rw-r--r--actioncable/test/connection/identifier_test.rb27
-rw-r--r--actioncable/test/connection/multiple_identifiers_test.rb11
-rw-r--r--actioncable/test/connection/string_identifier_test.rb13
5 files changed, 24 insertions, 39 deletions
diff --git a/actioncable/test/channel/stream_test.rb b/actioncable/test/channel/stream_test.rb
index 53dd7e5b77..5c1f308f53 100644
--- a/actioncable/test/channel/stream_test.rb
+++ b/actioncable/test/channel/stream_test.rb
@@ -54,13 +54,13 @@ module ActionCable::StreamTests
test "streaming start and stop" do
run_in_eventmachine do
connection = TestConnection.new
- connection.expects(:pubsub).returns mock().tap { |m| m.expects(:subscribe).with("test_room_1", kind_of(Proc), kind_of(Proc)).returns stub_everything(:pubsub) }
+ connection.pubsub.expects(:subscribe).with("test_room_1", kind_of(Proc), kind_of(Proc))
channel = ChatChannel.new connection, "{id: 1}", id: 1
channel.subscribe_to_channel
wait_for_async
- connection.expects(:pubsub).returns mock().tap { |m| m.expects(:unsubscribe) }
+ connection.pubsub.expects(:unsubscribe)
channel.unsubscribe_from_channel
end
end
@@ -68,13 +68,14 @@ module ActionCable::StreamTests
test "stream from non-string channel" do
run_in_eventmachine do
connection = TestConnection.new
- connection.expects(:pubsub).returns mock().tap { |m| m.expects(:subscribe).with("channel", kind_of(Proc), kind_of(Proc)).returns stub_everything(:pubsub) }
+ connection.pubsub.expects(:subscribe).with("channel", kind_of(Proc), kind_of(Proc))
+
channel = SymbolChannel.new connection, ""
channel.subscribe_to_channel
wait_for_async
- connection.expects(:pubsub).returns mock().tap { |m| m.expects(:unsubscribe) }
+ connection.pubsub.expects(:unsubscribe)
channel.unsubscribe_from_channel
end
end
@@ -82,7 +83,7 @@ module ActionCable::StreamTests
test "stream_for" do
run_in_eventmachine do
connection = TestConnection.new
- connection.expects(:pubsub).returns mock().tap { |m| m.expects(:subscribe).with("action_cable:stream_tests:chat:Room#1-Campfire", kind_of(Proc), kind_of(Proc)).returns stub_everything(:pubsub) }
+ connection.pubsub.expects(:subscribe).with("action_cable:stream_tests:chat:Room#1-Campfire", kind_of(Proc), kind_of(Proc))
channel = ChatChannel.new connection, ""
channel.subscribe_to_channel
diff --git a/actioncable/test/connection/base_test.rb b/actioncable/test/connection/base_test.rb
index ed62e90b70..9e480ab60d 100644
--- a/actioncable/test/connection/base_test.rb
+++ b/actioncable/test/connection/base_test.rb
@@ -80,7 +80,6 @@ class ActionCable::Connection::BaseTest < ActionCable::TestCase
connection.process
# Setup the connection
- connection.server.stubs(:timer).returns(true)
connection.send :handle_open
assert connection.connected
diff --git a/actioncable/test/connection/identifier_test.rb b/actioncable/test/connection/identifier_test.rb
index de1ae1d5b9..204197c2a7 100644
--- a/actioncable/test/connection/identifier_test.rb
+++ b/actioncable/test/connection/identifier_test.rb
@@ -21,28 +21,28 @@ 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
+ server.pubsub.expects(:subscribe)
+ .with("action_cable/User#lifo", kind_of(Proc))
+ server.pubsub.expects(:unsubscribe)
+ .with("action_cable/User#lifo", kind_of(Proc))
+
+ open_connection(server)
close_connection
end
end
test "processing disconnect message" do
run_in_eventmachine do
- open_connection_with_stubbed_pubsub
+ open_connection
assert_called(@connection.websocket, :close) do
@connection.process_internal_message "type" => "disconnect"
@@ -52,7 +52,7 @@ class ActionCable::Connection::IdentifierTest < ActionCable::TestCase
test "processing invalid message" do
run_in_eventmachine do
- open_connection_with_stubbed_pubsub
+ open_connection
assert_not_called(@connection.websocket, :close) do
@connection.process_internal_message "type" => "unknown"
@@ -61,14 +61,9 @@ class ActionCable::Connection::IdentifierTest < ActionCable::TestCase
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/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