Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An equivalent to capybara save_and_open_page for request specs
# frozen_string_literal: true
RSpec.shared_context "save_and_open_page for request" do
def asset_host
"http://localhost:3000"
end
def save_and_open_page
Dir.mkdir(Rails.root.join("tmp/requests")) unless Dir.exist?(Rails.root.join("tmp/requests"))
file = Rails.root.join("tmp/requests/screenshot-#{Time.now.to_s(:number)}.html")
File.open(file, "wb") do |f|
f.write(response.body.gsub(/\<head\>/, "<head><base href='#{asset_host}'/>"))
end
Launchy.open("file:#{file}")
end
end
RSpec.configure do |config|
config.include_context "save_and_open_page for request", type: :request
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.