I\'m using URI.encode to generate HTML data URLs:
URI.encode
visit "data:text/html,#{URI::encode(html)}"