Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit db935a89f72519d6239c2036359f91b394927383 0 parents
@mattheworiordan authored
5 .gitignore
@@ -0,0 +1,5 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
+.rvmrc
0  CHANGELOG.md
No changes.
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in capybara-screenshot.gemspec
+gemspec
0  README.md
No changes.
2  Rakefile
@@ -0,0 +1,2 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
25 capybara-screenshot.gemspec
@@ -0,0 +1,25 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "capybara-screenshot/version"
+
+Gem::Specification.new do |s|
+ s.name = "capybara-screenshot"
+ s.version = Capybara::Screenshot::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Matthew O'Riordan"]
+ s.email = ["matthew.oriordan@gmail.com"]
+ s.homepage = "http://github.com/mattheworiordan/capybara-screenshot"
+ s.summary = %q{Automatically create snapshots when Cucumber steps fail with Capybara and Rails}
+ s.description = %q{When a Cucumber step fails, it is useful to create a screenshot image and HTML file of the current page}
+
+ s.rubyforge_project = "capybara-screenshot"
+
+ s.add_dependency 'cucumber', '>= 1.0'
+ s.add_dependency 'capybara', '>= 1.0'
+ s.add_development_dependency 'rspec', '~> 2.6'
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+end
12 lib/capybara-screenshot.rb
@@ -0,0 +1,12 @@
+require 'capybara-screenshot/world'
+
+module Capybara
+ module Screenshot
+ end
+end
+
+World(Capybara::Screenshot::World)
+
+After do |scenario|
+ screen_shot_and_save_page if scenario.failed?
+end
5 lib/capybara-screenshot/version.rb
@@ -0,0 +1,5 @@
+module Capybara
+ module Screenshot
+ VERSION = "0.0.1"
+ end
+end
16 lib/capybara-screenshot/world.rb
@@ -0,0 +1,16 @@
+module Capybara
+ module Screenshot
+ module World
+ def screen_shot_and_save_page
+ require 'capybara/util/save_and_open_page'
+ path = "/#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}"
+ puts "After body from within Gem: #{page.body}"
+ Capybara.save_page body, "#{path}.html"
+ if page.driver.respond_to?(:render)
+ page.driver.render Rails.root.join "#{Capybara.save_and_open_page_path}" "#{path}.png"
+ puts "Saved screen shot, #{Capybara.save_and_open_page_path}/#{path}.png"
+ end
+ end
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.