Hotwire Discussion

Looking for resources on how to use RSpec with Hotwire

Building an app with Hotwire for the first time. I think I finally wrapped my head around the unique way it forces you to structure view markup, but now I need to write some tests and I haven’t been able to find a guide on using RSpec with Hotwire.

Can anyone refer me to some good resources?


Good to know that you’re starting to use it!

First thing is separate the two scenarios:

  1. Turbo frame
    Normally the important things to check on frames is that you’re not rendering the layout and that you’re returning the turbo_frame.
expect(response).to have_http_status(:ok)
expect(response).to render_template(layout: false)
expect(response.body).to include('<turbo-frame id="frame_id">')
  1. Turbo stream
    You can check the turbo stream test helpers that they created on turbo-rails, and use those kind of checks on the specs of actions that respond to turbo_streams.
    Here something like that for rspec:
    expect(response).to have_http_status(:ok)
    expect(response.media_type).to eq Mime[:turbo_stream]
    expect(response).to render_template(layout: false)
    expect(response.body).to include('<turbo-stream action="append" target="flash">')
    And remember add the , as: :turbo_stream on the action when you execute it.

This is what I use most of the time to test turbo interactions with rspec


Thank you for that clear, concise response. This is very helpful!