DEV Community

Cover image for New asserts for testing stopped streams after Ruby on Rails 7.1.
JetThoughts Dev for JetThoughts

Posted on • Edited on • Originally published at jetthoughts.com

New asserts for testing stopped streams after Ruby on Rails 7.1.

Previously, developers encountered a significant challenge verifying if streams ceased operation correctly. This issue often led to the creation of intricate workarounds or the omission of proper testing.

The Old Way

Here's an e­xample:

assert_not ActionCable.server.pubsub.redis_connection_for_subscriptions.subscribed_to?("messages")
Enter fullscreen mode Exit fullscreen mode

This code­ works but isn't straightforward to update.

The New Solution

The following Ruby on Rails introduces assert_has_no_stream and assert_has_no_stream_for. These new methods simplify the testing of stopped streams.

assert_has_no_stream "messages"
assert_has_no_stream_for User.find(42)
Enter fullscreen mode Exit fullscreen mode

With these new assertion methods, you can straightforwardly express your test goals. This simplicity and clarity strengthen your tests and make them easier to maintain, giving you confidence in the reliability of your code.

Top comments (0)