capybara nokogiri system/request test debugging

Edit
equivalent Web Development
Public
Rails
RSpec
module RequestTestHelpers
def turbo_stream_page
# turbo_stream wraps response in <template> tag, Capybara ignore template tags
template_content = Nokogiri::HTML(response.body).css('turbo-stream template').inner_html
Capybara.string(template_content)
end

def follow_redirects_until_finished!
while response.status == 302 || response.status == 301
follow_redirect!
end
end

# just debugging to show the HTML of the response
def _xx(css='body')
puts Nokogiri::HTML(body).css(css).to_xhtml(indent: 2)
end
end



Important



Nokogiri(response.body).css('template').inner_html

is different than


Nokogiri::HTML(response.body).css('turbo-stream template')


Former will not work if response reply with multiple template updates (multiple turbo_stream.update in turbo_stream.erb.file)

Payment successful

Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur amet labore.