forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
save_and_open_page
helper to IntegrationTest
`save_and_open_page` is a capybara helper that lets developers inspect the status of the page at any given point in their test. This is helpful when trying to keep a short feedback loop while working on a test. This change adds a similar helper with matching signature to integration tests.
- Loading branch information
Showing
6 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
35 changes: 35 additions & 0 deletions
35
actionpack/lib/action_dispatch/testing/test_helpers/page_dump_helper.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
module ActionDispatch | ||
module TestHelpers | ||
module PageDumpHelper | ||
class InvalidResponse < StandardError; end | ||
|
||
# Saves the content of response body to a file and tries to open it in your browser. | ||
# Launchy must be present in your Gemfile for the page to open automatically. | ||
def save_and_open_page(path = html_dump_defaul_path) | ||
save_page(path).tap { |s_path| open_file(s_path) } | ||
end | ||
|
||
private | ||
def save_page(path = html_dump_defaul_path) | ||
raise InvalidResponse.new("Response is a redirection!") if response.redirection? | ||
path = Pathname.new(path) | ||
path.dirname.mkpath | ||
File.write(path, response.body) | ||
path | ||
end | ||
|
||
def open_file(path) | ||
require "launchy" | ||
Launchy.open(path) | ||
rescue LoadError | ||
warn "File saved to #{path}.\nPlease install the launchy gem to open the file automatically." | ||
end | ||
|
||
def html_dump_defaul_path | ||
Rails.root.join("tmp/html_dump", "#{method_name}_#{DateTime.current.to_i}.html").to_s | ||
end | ||
end | ||
end | ||
end |
This file contains 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