Last active
August 29, 2015 14:06
-
-
Save henrik/c72e55d6bb808b4ec50d to your computer and use it in GitHub Desktop.
show_screenshot helper for PhantomJS tests.
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
public/screenshot-*.png |
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
describe "Things" do | |
it "does stuff", :js do | |
visit my_path | |
show_screenshot # Writes screenshot-4.png, for line 4. | |
show_screenshot :my_name # Writes screenshot-my_name.png | |
end | |
end |
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
module FeatureHelpers | |
def show_screenshot(given_suffix = :default_suffix) | |
if given_suffix == :default_suffix | |
# The line may be e.g. "/dir/my_spec.rb:123:in …" | |
called_from_line = caller.first[/.*?:(\d+):/, 1] | |
suffix = "line-#{called_from_line}" | |
else | |
suffix = given_suffix | |
end | |
file_name = "screenshot-#{suffix}.png" | |
url = "http://our-app.dev/#{file_name}" | |
# https://github.com/teampoltergeist/poltergeist#taking-screenshots-with-some-extensions | |
save_screenshot(Rails.root.join("public/#{file_name}"), full: true) | |
# https://github.com/busyloop/lolcat - Colorizes the output, in our case like a rainbow. | |
Lol.println("Screenshot can be found at: #{url}", os: 10, freq: 0.1, spread: 1) | |
end | |
end | |
RSpec.configure do |config| | |
config.include FeatureHelpers, type: :feature | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We write to
public
and output a URL since we develop inside a VM. If you develop on OS X straight on the host machine, you could e.g. write to/tmp
and evenopen /tmp/file.png
to auto-open it.