From 86e7de7968b91bd4256bb07ffbe689b385180910 Mon Sep 17 00:00:00 2001
From: bogdanvlviv <bogdanvlviv@gmail.com>
Date: Thu, 23 Aug 2018 12:39:03 +0300
Subject: DRY in `assert_broadcasts`

Test `assert_no_broadcasts` failure
---
 actioncable/lib/action_cable/test_helper.rb |  5 +++--
 actioncable/test/test_helper_test.rb        | 10 ++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

(limited to 'actioncable')

diff --git a/actioncable/lib/action_cable/test_helper.rb b/actioncable/lib/action_cable/test_helper.rb
index 9092c8b80e..7bc877663c 100644
--- a/actioncable/lib/action_cable/test_helper.rb
+++ b/actioncable/lib/action_cable/test_helper.rb
@@ -47,11 +47,12 @@ module ActionCable
         original_count = broadcasts_size(stream)
         yield
         new_count = broadcasts_size(stream)
-        assert_equal number, new_count - original_count, "#{number} broadcasts to #{stream} expected, but #{new_count - original_count} were sent"
+        actual_count = new_count - original_count
       else
         actual_count = broadcasts_size(stream)
-        assert_equal number, actual_count, "#{number} broadcasts to #{stream} expected, but #{actual_count} were sent"
       end
+
+      assert_equal number, actual_count, "#{number} broadcasts to #{stream} expected, but #{actual_count} were sent"
     end
 
     # Asserts that no messages have been sent to the stream.
diff --git a/actioncable/test/test_helper_test.rb b/actioncable/test/test_helper_test.rb
index f82adb9c8f..90e3dbf01f 100644
--- a/actioncable/test/test_helper_test.rb
+++ b/actioncable/test/test_helper_test.rb
@@ -62,6 +62,16 @@ class TransmissionsTest < ActionCable::TestCase
 
     assert_match(/1 .* but 2/, error.message)
   end
+
+  def test_assert_no_broadcasts_failure
+    error = assert_raises Minitest::Assertion do
+      assert_no_broadcasts "test" do
+        ActionCable.server.broadcast "test", "hello"
+      end
+    end
+
+    assert_match(/0 .* but 1/, error.message)
+  end
 end
 
 class TransmitedDataTest < ActionCable::TestCase
-- 
cgit v1.2.3