aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actioncable/lib/rails/generators/test_unit/templates/channel_test.rb.tt2
-rw-r--r--guides/source/testing.md10
-rw-r--r--railties/CHANGELOG.md4
-rw-r--r--railties/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt2
-rw-r--r--railties/lib/rails/test_unit/testing.rake2
-rw-r--r--railties/test/application/test_runner_test.rb15
6 files changed, 22 insertions, 13 deletions
diff --git a/actioncable/lib/rails/generators/test_unit/templates/channel_test.rb.tt b/actioncable/lib/rails/generators/test_unit/templates/channel_test.rb.tt
index 301dc0b6fe..7307654611 100644
--- a/actioncable/lib/rails/generators/test_unit/templates/channel_test.rb.tt
+++ b/actioncable/lib/rails/generators/test_unit/templates/channel_test.rb.tt
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
require "test_helper"
class <%= class_name %>ChannelTest < ActionCable::Channel::TestCase
diff --git a/guides/source/testing.md b/guides/source/testing.md
index 576c4d768c..1a2f480407 100644
--- a/guides/source/testing.md
+++ b/guides/source/testing.md
@@ -1735,14 +1735,14 @@ Testing Action Cable
--------------------
Since Action Cable is used at different levels inside your application,
-you'll need to test both the channels and connection classes themsleves and that other
+you'll need to test both the channels, connection classes themselves, and that other
entities broadcast correct messages.
### Connection Test Case
By default, when you generate new Rails application with Action Cable, a test for the base connection class (`ApplicationCable::Connection`) is generated as well under `test/channels/application_cable` directory.
-Connection tests aim to check whether a connection's identifiers gets assigned properly
+Connection tests aim to check whether a connection's identifiers get assigned properly
or that any improper connection requests are rejected. Here is an example:
```ruby
@@ -1765,9 +1765,8 @@ end
You can also specify request cookies the same way you do in integration tests:
-
```ruby
-test "connects with_cookies" do
+test "connects with cookies" do
cookies.signed[:user_id] = "42"
connect
@@ -1778,7 +1777,6 @@ end
See the API documentation for [`AcionCable::Connection::TestCase`](http://api.rubyonrails.org/classes/ActionCable/Connection/TestCase.html) for more information.
-
### Channel Test Case
By default, when you generate a channel, an associated test will be generated as well
@@ -1823,7 +1821,7 @@ See the API documentation for [`AcionCable::Channel::TestCase`](http://api.rubyo
Action Cable ships with a bunch of custom assertions that can be used to lessen the verbosity of tests. For a full list of available assertions, see the API documentation for [`ActionCable::TestHelper`](http://api.rubyonrails.org/classes/ActionCable/TestHelper.html).
-It's a good practice to ensure that the correct message has been broadcasted inside another components (e.g. inside your controllers). This is precisely where
+It's a good practice to ensure that the correct message has been broadcasted inside other components (e.g. inside your controllers). This is precisely where
the custom assertions provided by Action Cable are pretty useful. For instance,
within a model:
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index aca55fae80..3691bb3fb1 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Add `rails test:channels`.
+
+ *bogdanvlviv*
+
* Use original `bundler` environment variables during the process of generating a new rails project.
*Marco Costa*
diff --git a/railties/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt b/railties/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt
index cc8337fc6d..800405f15e 100644
--- a/railties/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt
@@ -1,5 +1,3 @@
-# frozen_string_literal: true
-
require "test_helper"
class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase
diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake
index ecc458b21e..3a1b62d9d1 100644
--- a/railties/lib/rails/test_unit/testing.rake
+++ b/railties/lib/rails/test_unit/testing.rake
@@ -28,7 +28,7 @@ namespace :test do
desc "Run tests quickly, but also reset db"
task db: %w[db:test:prepare test]
- ["models", "helpers", "controllers", "mailers", "integration", "jobs", "mailboxes"].each do |name|
+ ["models", "helpers", "channels", "controllers", "mailers", "integration", "jobs", "mailboxes"].each do |name|
task name => "test:prepare" do
$: << "test"
Rails::TestUnit::Runner.rake_run(["test/#{name}"])
diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb
index 6765eef9d0..fda6df500d 100644
--- a/railties/test/application/test_runner_test.rb
+++ b/railties/test/application/test_runner_test.rb
@@ -98,6 +98,17 @@ module ApplicationTests
end
end
+ def test_run_channels
+ create_test_file :channels, "foo_channel"
+ create_test_file :channels, "bar_channel"
+
+ rails("test:channels").tap do |output|
+ assert_match "FooChannelTest", output
+ assert_match "BarChannelTest", output
+ assert_match "2 runs, 2 assertions, 0 failures", output
+ end
+ end
+
def test_run_controllers
create_test_file :controllers, "foo_controller"
create_test_file :controllers, "bar_controller"
@@ -167,11 +178,11 @@ module ApplicationTests
end
def test_run_all_suites
- suites = [:models, :helpers, :unit, :controllers, :mailers, :functional, :integration, :jobs, :mailboxes]
+ suites = [:models, :helpers, :unit, :channels, :controllers, :mailers, :functional, :integration, :jobs, :mailboxes]
suites.each { |suite| create_test_file suite, "foo_#{suite}" }
run_test_command("") .tap do |output|
suites.each { |suite| assert_match "Foo#{suite.to_s.camelize}Test", output }
- assert_match "9 runs, 9 assertions, 0 failures", output
+ assert_match "10 runs, 10 assertions, 0 failures", output
end
end