3

I am doing a rspec test for a controller action that use turbo stream :

  describe 'GET /CONTROLLER_NAME' do

    it 'return a turbo stream answer' do
      get :index, as: :turbo_stream
      expect(response).to eq Mime[:turbo_stream]
    end
  end

end

Failure/Error: expect(response).to eq Mime[:turbo_stream]

       expected: #<Mime::Type:0x00007f7d9c2e1ff0 @synonyms=[], @symbol=:turbo_stream, @string="text/vnd.turbo-stream.html", @hash=2866392594387537360>
            got: #<ActionDispatch::TestResponse:0x00007f7d976945f8 @mon_data=#<Monitor:0x00007f7d97694580>, @mon_data_...oller::TestRequest GET "http://test.host/CONTROLLER_NAME.turbo_stream" for 0.0.0.0>>

How do you make a get query with turbo stream in a controller test?

Syl
  • 3,719
  • 6
  • 35
  • 59

1 Answers1

10

you should check response.media_type to be Mime[:turbo_stream] instead of just request. check turbo stream test helpers

  describe 'GET /CONTROLLER_NAME' do
    it 'return a turbo stream answer' do
      get :index, as: :turbo_stream
      expect(response.media_type).to eq Mime[:turbo_stream]
    end
  end

Sampat Badhe
  • 8,710
  • 7
  • 33
  • 49