Skip to content

Instantly share code, notes, and snippets.

@slayer
Last active June 21, 2022 19:18
Show Gist options
  • Save slayer/51f8c00f2c9ad3f5fcbb36e8b72e28b8 to your computer and use it in GitHub Desktop.
Save slayer/51f8c00f2c9ad3f5fcbb36e8b72e28b8 to your computer and use it in GitHub Desktop.
Rails Rspec helper for turbo (hotwire)
require 'rails_helper'
RSpec.describe SomeController, type: :controller do
context 'turbo' do
include_context 'turbo_requests'
it 'should be successful' do
post :action
expect(response).to be_successful
end
end
end
# spec/support/turbo_helper.rb
shared_context 'turbo_requests' do
# perform requests as turbolinks
before do
request.headers['HTTP_TURBO_FRAME'] = 'true'
request.headers['HTTP_ACCEPT'] = "text/vnd.turbo-stream.html, text/html, application/xhtml+xml"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment