JT Book a call

Blog

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

Published

1 min read

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

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")

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)

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.

Read next

Tell us whatyou need built

JetThoughts has been building software since 2008. Book a call, or write to sales@jetthoughts.com. You'll leave the call with a written one-page scope within 2 working days.

Paul Keen Paul Keen, founder

A 30-minute call; pick a time.