Skip to content

Add Turbo/Hotwire testing support with matchers for turbo streams and frames #2887

@bastin27

Description

@bastin27

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions