Skip to content

Instantly share code, notes, and snippets.

@turadg
Last active December 15, 2015 20:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save turadg/5322430 to your computer and use it in GitHub Desktop.
Save turadg/5322430 to your computer and use it in GitHub Desktop.
Poltergeist screenshot helper for Rspec
# spec/support/poltergeist_screenshot_helper.rb
module PoltergeistScreenshotHelper
# FROM http://blog.jerodsanto.net/2012/12/capybara-and-poltergeist-snap/
def snap!(options={})
path = options.fetch :path, "~/.Trash"
file = options.fetch :file, "#{Time.now.to_i}.png"
full = options.fetch :full, true
path = File.expand_path path
path = "/tmp" if !File.exists?(path)
uri = File.join path, file
page.driver.render uri, full: full
system "open #{uri}"
end
end
RSpec.configure do |config|
config.include PoltergeistScreenshotHelper, :type => :request
config.include PoltergeistScreenshotHelper, :type => :feature
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment