Last active
August 29, 2015 13:57
-
-
Save coryf/9369292 to your computer and use it in GitHub Desktop.
Poltergeist RSpec screenshot
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
# 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