Created
February 23, 2019 10:19
-
-
Save timdiggins/cdae6ff2b59af5a78383eb9ac1bfe3b5 to your computer and use it in GitHub Desktop.
An equivalent to capybara save_and_open_page for request specs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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