-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Is your feature request related to a problem? Please describe.
Rails 7+ uses Turbo as the default for form submissions and page updates via turbo-rails. Currently, rspec-rails has no built-in support for testing Turbo Stream and Turbo Frame responses, forcing users to write manual assertions against raw HTML or content types.
Describe the solution you'd like
Matchers for Turbo Stream and Turbo Frame responses:
- have_turbo_stream(action:, target:) - asserts a element exists with the given action and target/targets, with optional .with_count(n) chaining
- be_turbo_stream - asserts the response has Turbo Stream content type (text/vnd.turbo-stream.html)
- have_turbo_frame(id) - asserts a element exists with the given id
Similar to what Rails provides in its own test helpers: https://github.com/hotwired/turbo-rails/blob/main/lib/turbo/test_assertions.rb
Additionally, the scaffold generator should be updated to include turbo_stream format tests for create, update, and destroy actions when Turbo is available.
Describe alternatives you've considered
- Using assert_turbo_stream_response from turbo-rails directly, but this is Minitest-only and not available in RSpec
- Manually parsing response.body with Nokogiri in every test
- Third-party gems, but this is core enough to belong in rspec-rails
Additional context
Reference implementation for Rails structured event reporting matchers follows a similar pattern: https://github.com/keshavbiswa/rails/blob/main/activesupport/test/testing/event_reporter_assertions_test.rb