You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/03-code-internals/20-system-specs.md
+37Lines changed: 37 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -445,6 +445,43 @@ Finally, some strings are quite big and there's no need to check that the entire
445
445
446
446
Our `RateLimiter` system is disabled by default in specs. However if you need to turn it on to test some rate limiting specifically in system specs (though you should use request specs for this), use `RateLimiter.enable`.
When testing UI interactions that trigger real-time updates—typically sent via `MessageBus`—you might find that these updates aren’t appearing in your system tests as expected. To ensure that streaming updates work reliably in tests, make sure the following pieces are in place:
451
+
452
+
1.**Track the `MessageBus.last_id` on the server and pass it to the client.**
453
+
This ensures the client receives only messages that occur after the page has loaded.
454
+
455
+
On the server side, expose the last ID for the relevant `MessageBus` channel (usually via a serializer):
456
+
457
+
```ruby
458
+
deffoo_channel_last_id
459
+
MessageBus.last_id("/foo-channel")
460
+
end
461
+
```
462
+
463
+
On the client side, use this ID when subscribing to the MessageBus channel:
464
+
465
+
```js
466
+
this.messageBus.subscribe(
467
+
this.fooChannel,
468
+
this.updateResult,
469
+
this.args.foo_channel_last_id
470
+
);
471
+
```
472
+
473
+
> ⚠️ Note: Be mindful that frequent calls to `MessageBus.last_id` can result in increased Redis traffic. If you're calling this in high-volume serializers or endpoints, consider optimizing to reduce the number of Redis hits—for example, by caching or batching where appropriate.
474
+
475
+
2.**Run jobs immediately in your system specs.**
476
+
477
+
This ensures background jobs that publish messages (e.g., via `MessageBus.publish`) are executed synchronously during the test:
478
+
479
+
```ruby
480
+
before do
481
+
Jobs.run_immediately!
482
+
end
483
+
```
484
+
448
485
## Advanced Chrome Interaction
449
486
450
487
In certain cases you will need to use some advanced features of Chrome in your system specs. Some examples are interacting with the clipboard (copy and paste) and network manipulation (simulating slow connections). This is achieved using the [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/), and sometimes with native Capybara functionality.
0 commit comments