Skip to content

Instantly share code, notes, and snippets.

@coryf
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coryf/9369292 to your computer and use it in GitHub Desktop.
Save coryf/9369292 to your computer and use it in GitHub Desktop.
Poltergeist RSpec screenshot
# spec/support/screenshot.rb
RSpec.configure do |config|
# A work-around to support accessing the current example that works in both
# RSpec 2 and RSpec 3.
fetch_current_example = RSpec.respond_to?(:current_example) ?
proc { RSpec.current_example } : proc { |context| context.example }
config.after do
example = fetch_current_example.call(self)
if screenshot = example.metadata[:screenshot]
filename = if screenshot.is_a? String
screenshot
else
example.full_description.parameterize('_')
end
page.save_screenshot("spec/images/#{filename}.png", full: true)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment