capybara-screenshot-1.0.14/ 0000755 0001750 0001750 00000000000 12766551460 014572 5 ustar pravi pravi capybara-screenshot-1.0.14/CHANGELOG.md 0000644 0001750 0001750 00000023005 12766551460 016403 0 ustar pravi pravi 15 Sep 2016 - 1.0.13 -> 1.0.14
* CI stable again - dropped CI support for older versions of Ruby and JRuby. It is just too painful and there is no evidence that our users need this or that Capybara Screenshot is indeed broken. It is better to have a reliable build system so that PRs can get merged in reliably and easily.
* Fixed an inconsistency in the use of `save_and_open_page_path`
* Improved debugging of Aruba tests so that contributors can easily understand why their builds break
* Path fixes thanks to [Ryan McGarvey](https://github.com/ryanmcgarvey)
23 May 2016 - 1.0.12 -> 1.0.13
* Fixes [mkmf bug 162](https://github.com/mattheworiordan/capybara-screenshot/issues/162) and [mkmf bug 174](https://github.com/mattheworiordan/capybara-screenshot/issues/174)
* Fix for `Capybara.save_path` method existence assumption
29 March 2016 - 1.0.11 -> 1.0.12
* [Aruba upgrade - passing CI](https://github.com/mattheworiordan/capybara-screenshot/pull/156)
* [imgcat support](https://github.com/mattheworiordan/capybara-screenshot/pull/153)
* [Fix for capaybara root when Rails not defined](https://github.com/mattheworiordan/capybara-screenshot/pull/139)
* [Fix using_session_with_screenshot](https://github.com/mattheworiordan/capybara-screenshot/pull/132)
* [Skip screenshot on skipped test](https://github.com/mattheworiordan/capybara-screenshot/pull/131)
* [Don't output screenshot paths if not saved](https://github.com/mattheworiordan/capybara-screenshot/pull/128)
22 July 2015 - 1.0.10 -> 1.0.11
* [Support for Fuubar reporter](https://github.com/mattheworiordan/capybara-screenshot/pull/137)
Thanks to [Kai Schlichting](https://github.com/lacco)
29 June 2015 - 1.0.9 -> 1.0.10
* [Small fix to memoization](https://github.com/mattheworiordan/capybara-screenshot/pull/134) plus [mini refactor](https://github.com/mattheworiordan/capybara-screenshot/commit/1db950bc53c729b26b8881d058a8781d6e7611b8)
Thanks to [Systho](https://github.com/Systho)
6 April 2015 - 1.0.8 -> 1.0.9
-----------
* [Improved file links within screenshot output](https://github.com/mattheworiordan/capybara-screenshot/pull/123)
Thanks to [Jan Lelis](https://github.com/janlelis)
6 April 2015 - 1.0.7 -> 1.0.8
-----------
* Less aggressive pruning
9 March 2015 - 1.0.6 -> 1.0.7
-----------
* Fix capybara-webkit bug, see https://github.com/mattheworiordan/capybara-screenshot/issues/119
* Fix Travis CI builds in Ruby < 2.1 and added Ruby 2.2 support
8 March 2015 - 1.0.5 -> 1.0.6
-----------
* Removed dependency on the colored gem
Thanks to [François Bernier](https://github.com/fbernier)
10 Feburary 2015 - 1.04 -> 1.0.5
-----------
* Added support for appending a random string to the filename
Thanks to [Brad Wedell](https://github.com/streetlogics)
5 January 2015 - 1.0.3 -> 1.0.4
-----------
* Added support for Poltergeist Billy
* Don't initialize a new Capybara::Session in after hook
Thanks to [Neodude](https://github.com/neodude) and [Dominik Masur](https://github.com/dmasur)
1 October 2014 - 1.0.2 -> 1.0.3
-----------
* Added ability to prune screenshots automatically, see https://github.com/mattheworiordan/capybara-screenshot/pull/100
Thanks to [Anton Kolomiychuk](https://github.com/akolomiychuk) for his contribution.
27 September 2014 - 1.0.1 -> 1.0.2
-----------
* Improved documentation to cover RSpec 3's new approach to using `rails_helper` in place of `spec_helper` for Rails tests
* Updated documentation to use Ruby formatting in language blocks
* Removed need to manually `require 'capybara-screenshot'` for RSpec
18 September 2014 - 1.0.0 -> 1.0.1
-----------
* Hot fix for RSpec version issue that assumed RSpec base library was always available, now uses `RSpec::Core::VERSION`
* Improve Travis CI performance and stability
18 September 2014 - 0.3.22 -> 1.0.0
-----------
Because of the broad test coverage now across RSpec, Cucumber, Spinach, Minitest and TestUnit using [Aruba](https://github.com/cucumber/aruba), I feel that this gem is ready for its first major release. New features and refactoring can now reliably be done without the fear of regressions.
The major changes in this 1.0 release are:
* Acceptance test coverage for RSpec, Cucumber, Spinach, Minitest and TestUnit
* Travis CI test coverage across a matrix of old and new versions of the aforementioned testing frameworks, see https://github.com/mattheworiordan/capybara-screenshot/blob/master/.travis.yml
* Support for RSpec 3 using the custom formatters
* Support for sessions using `using_session`, see https://github.com/mattheworiordan/capybara-screenshot/pull/91 for more info
* Support for RSpec DocumentationFormatter
* Considerable refactoring of the test suite
Special thanks goes to [Andrew Brown](https://github.com/dontfidget) who has contributed a huge amount of the code that has helped enable this Gem to have its stable major version release.
22 July 2014 - 0.3.21 -> 0.3.22
-----------
Replaced [colorize](https://rubygems.org/gems/colorize) gem with [colored](https://rubygems.org/gems/colored) due to license issue, see https://github.com/mattheworiordan/capybara-screenshot/issues/93.
22 July 2014 - 0.3.20 -> 0.3.21
-----------
As a result of recent merges and insufficient test coverage, it seems that for test suites other than RSpec the HTML or Image screenshot path was no longer being outputted in the test results. This has now been fixed, and screenshot output format for RSpec and all other test suites has been standardised.
11 July 2014 - 0.3.19 -> 0.3.20
-----------
* Added reporters to improve screenshot info in RSpec output
* Added support for Webkit options such as width and height
Thanks to https://github.com/multiplegeorges and https://github.com/noniq
2 April 2014 - 0.3.18 -> 0.3.19
-----------
* Added support Spinach, thanks to https://github.com/suchitpuri
2 March 2014 - 0.3.16 -> 0.3.17
-----------
* Added support for RSpec 3 and cleaned up the logging so there is less noise within the test results when a driver does not support a particular format.
* Updated Travis to test against Ruby 2.0 and Ruby 2.1
Thanks to https://github.com/noniq
7 January 2014
-----------
Bug fix for Minitest 5, thanks to https://github.com/cschramm
12 September 2013
-----------
Added support for Test Unit, fixed RSpec deprecation warnings and fixed a dependency issue.
Thanks to:
* https://github.com/budnik
* https://github.com/jkraemer
* https://github.com/mariovisic
23 July 2013
-----------
https://github.com/stevenwilkin contributed code to display a warning for [Mechanize](http://mechanize.rubyforge.org/) users.
3 June 2013
-----------
Dropped Ruby 1.8 support for this Gem because of conflicts with Nokogiri requiring a later version of Ruby. Instead, there is a new branch https://github.com/mattheworiordan/capybara-screenshot/tree/ruby-1.8-support which can be used if requiring backwards compatabiltiy.
18 Apr 2013
-----------
Improved documentation, Ruby 1.8.7 support by not allowing Capybara 2.1 to be used, improved Sinatra support.
RSpec screenshot fix to only screenshot when applicable: https://github.com/mattheworiordan/capybara-screenshot/issues/44
07 Jan 2013
-----------
Support for Terminus, thanks to https://github.com/jamesotron
27 Dec 2012
-----------
Previos version bump broke Ruby 1.8.7 support, so Travis CI build added to this Gem and Ruby 1.8.7 support along with JRuby support added.
30 Oct 2012 - Significant version bump 0.3
-----------
After some consideration, and continued problems with load order of capybara-screenshot in relation to other required gems, the commits from @adzap in the pull request https://github.com/mattheworiordan/capybara-screenshot/pull/29 have been incorporated. Moving forwards, for every testing framework you use, you will be required to add an explicit require.
15 Feb 2012
-----------
Merged pull request https://github.com/mattheworiordan/capybara-screenshot/pull/14 to limit when capybara-screenshot is fired for RSpec
30 Jan 2012
-----------
Merged pull request from https://github.com/hlascelles to support Padrino
15 Jan 2012
-----------
Removed unnecessary and annoying warning that a screen shot cannot be taken. This message was being shown when RSpec tests were run that did not even invoke Capybara
13 Jan 2012
-----------
Updated documentation to reflect support for more frameworks, https://github.com/mattheworiordan/capybara-screenshot/issues/9
3 Jan 2012
----------
Removed Cucumber dependency https://github.com/mattheworiordan/capybara-screenshot/issues/7
Allowed PNG save path to be configured using capybara.save_and_open_page_path
3 December 2011
---------------
More robust handling of Minitest for users who have it installed as a dependency
https://github.com/mattheworiordan/capybara-screenshot/issues/5
2 December 2011
---------------
Fixed bug related to teardown hook not being available in Minitest for some reason (possibly version issues).
https://github.com/mattheworiordan/capybara-screenshot/issues/5
24 November 2011
----------------
Added support for:
* More platforms (Poltergeist)
* Removed Rails dependencies (bug)
* Added screenshot capability for Selenium
* Added support for embed for HTML reports
Thanks to [https://github.com/rb2k](https://github.com/rb2k) for 2 [great commits](https://github.com/mattheworiordan/capybara-screenshot/pull/4)
16 November 2011
----------------
Added support for Minitest using teardown hooks
16 November 2011
----------------
Added support for RSpec by adding a RSpec configuration after hook and checking if Capybara is being used.
15 November 2011
----------------
Ensured that tests run other than Cucumber won't fail. Prior to this Cucumber was required.
capybara-screenshot-1.0.14/README.md 0000644 0001750 0001750 00000024442 12766551460 016057 0 ustar pravi pravi capybara-screenshot gem
=======================
[](https://travis-ci.org/mattheworiordan/capybara-screenshot)
[](https://codeclimate.com/github/mattheworiordan/capybara-screenshot)
[](http://badge.fury.io/rb/capybara-screenshot)
#### Capture a screen shot for every test failure automatically!
`capybara-screenshot` used with [Capybara](https://github.com/jnicklas/capybara) and [Cucumber](http://cukes.info/), [Rspec](https://www.relishapp.com/rspec) or [Minitest](https://github.com/seattlerb/minitest), will capture a screen shot for each failure in your test suite. The HTML for the failed page, and a screenshot image (when using [capybara-webkit](https://github.com/thoughtbot/capybara-webkit), [Selenium](http://seleniumhq.org/) or [poltergeist](https://github.com/jonleighton/poltergeist)) is saved into `$APPLICATION_ROOT/tmp/capybara`.
Having screenshots readily available for each test failure is incredibly helpful when trying to quickly diagnose a problem in your failing steps. You can view the source code, and have a screen shot of the page (when applicable), at the time of each failure.
_Please note that Ruby 1.9+ is required to use this Gem. For Ruby 1.8 support, please see the [capybara-screenshot Ruby 1.8 branch](https://github.com/mattheworiordan/capybara-screenshot/tree/ruby-1.8-support)_
Installation
-----
### Step 1: install the gem
Using Bundler, add the following to your Gemfile
```ruby
gem 'capybara-screenshot', :group => :test
```
or install manually using Ruby Gems:
```
gem install capybara-screenshot
```
### Step 2: load capybara-screenshot into your tests
#### Cucumber
In env.rb or a support file, please add:
```ruby
require 'capybara-screenshot/cucumber'
```
#### RSpec
In rails_helper.rb, spec_helper.rb, or a support file, after the require for 'capybara/rspec', please add:
```ruby
# remember: you must require 'capybara/rspec' first
require 'capybara-screenshot/rspec'
```
*Note: As of RSpec Rails 3.0, it is recommended that all your Rails environment code is loaded into `rails_helper.rb` instead of `spec_helper.rb`, and as such, the capybara-screenshot require should be located in `rails_helper.rb`. See the [RSpec Rails 3.0 upgrade notes](https://www.relishapp.com/rspec/rspec-rails/v/3-0/docs/upgrade) for more info.*
#### Minitest
Typically in 'test/test_helper.rb', please add:
```ruby
require 'capybara-screenshot/minitest'
```
Also, consider adding `include Capybara::Screenshot::MiniTestPlugin` to any test classes that fail. For example, to capture screenshots for all failing integration tests in minitest-rails, try something like:
```ruby
class ActionDispatch::IntegrationTest
include Capybara::Screenshot::MiniTestPlugin
# ...
end
```
#### Test::Unit
Typically in 'test/test_helper.rb', please add:
```ruby
require 'capybara-screenshot/testunit'
```
By default, screenshots will be captured for `Test::Unit` tests in the path 'test/integration'. You can add additional paths as:
```ruby
Capybara::Screenshot.testunit_paths << 'test/feature'
```
Manual screenshots
----
If you require more control, you can generate the screenshot on demand rather than on failure. This is useful
if the failure occurs at a point where the screen shot is not as useful for debugging a rendering problem. This
can be more useful if you disable the auto-generate on failure feature with the following config
```ruby
Capybara::Screenshot.autosave_on_failure = false
```
Anywhere the Capybara DSL methods (visit, click etc.) are available so too are the screenshot methods.
```ruby
screenshot_and_save_page
```
Or for screenshot only, which will automatically open the image.
```ruby
screenshot_and_open_image
```
These are just calls on the main library methods.
```ruby
Capybara::Screenshot.screenshot_and_save_page
Capybara::Screenshot.screenshot_and_open_image
```
Driver configuration
--------------------
The gem supports the default rendering method for Capybara to generate the screenshot, which is:
```ruby
page.driver.render(path)
```
There are also some specific driver configurations for Selenium, Webkit, and Poltergeist. See [the definitions here](https://github.com/mattheworiordan/capybara-screenshot/blob/master/lib/capybara-screenshot.rb). The Rack::Test driver, Rails' default, does not allow
rendering, so it has a driver definition as a noop.
Capybara-webkit defaults to a screenshot size of 1000px by 10px. To specify a custom size, use the following option:
```ruby
Capybara::Screenshot.webkit_options = { width: 1024, height: 768 }
```
If a driver is not found the default rendering will be used. If this doesn't work with your driver, then you can
add another driver configuration like so
```ruby
# The driver name should match the Capybara driver config name.
Capybara::Screenshot.register_driver(:exotic_browser_driver) do |driver, path|
driver.super_dooper_render(path)
end
```
If your driver is based on existing browser driver, like Firefox, instead of `.super_dooper_render` do `driver.browser.save_screenshot path`.
Custom screenshot filename
--------------------------
If you want to control the screenshot filename for a specific test library, to inject the test name into it for example,
you can override how the basename is generated for the file like so
```ruby
Capybara::Screenshot.register_filename_prefix_formatter(:rspec) do |example|
"screenshot_#{example.description.gsub(' ', '-').gsub(/^.*\/spec\//,'')}"
end
```
By default capybara-screenshot will append a timestamp to the basename. If you want to disable this behavior set the following option:
```ruby
Capybara::Screenshot.append_timestamp = false
```
Custom screenshot directory
--------------------------
By default, when running under Rails, Sinatra, and Padrino, screenshots are saved into `$APPLICATION_ROOT/tmp/capybara`. Otherwise, they're saved under `Dir.pwd`.
If you want to customize the location, override the file path as:
```ruby
Capybara.save_path = "/file/path"
```
Uploading screenshots to S3
--------------------------
You can configure capybara-screenshot to automatically save your screenshots to an AWS S3 bucket.
First, install the `aws-sdk` gem or add it to your Gemfile
```ruby
gem 'capybara-screenshot', :group => :test
gem 'aws-sdk', :group => :test
```
Next, configure capybara-screenshot with your S3 credentials, the bucket to save to, and an optional region (default: `us-east-1`).
```ruby
Capybara::Screenshot.s3_configuration = {
s3_client_credentials: {
access_key_id: "my_access_key_id",
secret_access_key: "my_secret_access_key",
region: "eu-central-1"
},
bucket_name: "my_screenshots"
}
```
Pruning old screenshots automatically
--------------------------
By default screenshots are saved indefinitely, if you want them to be automatically pruned on a new failure, then you can specify one of the following prune strategies as follows:
```ruby
# Keep only the screenshots generated from the last failing test suite
Capybara::Screenshot.prune_strategy = :keep_last_run
# Keep up to the number of screenshots specified in the hash
Capybara::Screenshot.prune_strategy = { keep: 20 }
```
Information about screenshots in RSpec output
---------------------------------------------
By default, capybara-screenshot extend RSpec’s formatters to include a link to the screenshot and/or saved html page for each failed spec. If you want to disable this feature completely (eg. to avoid problems with CI tools), use:
```ruby
Capybara::Screenshot::RSpec.add_link_to_screenshot_for_failed_examples = false
```
It’s also possible to directly embed the screenshot image in the output if you’re using RSpec’s HtmlFormatter:
```ruby
Capybara::Screenshot::RSpec::REPORTERS["RSpec::Core::Formatters::HtmlFormatter"] = Capybara::Screenshot::RSpec::HtmlEmbedReporter
```
If you want to further customize the information added to RSpec’s output, just implement your own reporter class and customize `Capybara::Screenshot::RSpec::REPORTERS` accordingly. See [rspec.rb](lib/capybara-screenshot/rspec.rb) for more info.
Common problems
---------------
If you have recently upgraded from v0.2, or you find that screen shots are not automatically being generated, then it's most likely you have not included the necessary `require` statement for your testing framework described above. As of version 0.3, without the explicit require, Capybara-Screenshot will not automatically take screen shots. Please re-read the installation instructions above.
Also make sure that you're not calling `Capybara.reset_sessions!` before the screenshot hook runs. For RSpec you want to make sure that you're using `append_after` instead of `after`, for instance:
```ruby
config.append_after(:each) do
Capybara.reset_sessions!
end
```
[Raise an issue on the Capybara-Screenshot issue tracker](https://github.com/mattheworiordan/capybara-screenshot/issues) if you are still having problems.
Repository & Contributing to this Gem
-------------------------------------
#### Bugs
Please raise an issue at [https://github.com/mattheworiordan/capybara-screenshot/issues](https://github.com/mattheworiordan/capybara-screenshot/issues) and ensure you provide sufficient detail to replicate the problem.
#### Contributions
Contributions are welcome. Please fork this gem, and submit a pull request. New features must include test coverage and must pass on all versions of the testing frameworks supported. Run `appraisal` to set up the your Gems. then `appraisal "rake travis:ci"` locally to test your changes against all versions of testing framework gems supported.
#### Rubygems
The gem details on RubyGems.org can be found at [https://rubygems.org/gems/capybara-screenshot](https://rubygems.org/gems/capybara-screenshot)
About
-----
This gem was written by **Matthew O'Riordan**, with contributions from [many kind people](https://github.com/mattheworiordan/capybara-screenshot/network/members).
- [http://mattheworiordan.com](http://mattheworiordan.com)
- [@mattheworiordan](http://twitter.com/#!/mattheworiordan)
- [Linked In](http://www.linkedin.com/in/lemon)
License
-------
Copyright © 2016 Matthew O'Riordan, inc. It is free software, and may be redistributed under the terms specified in the LICENSE file.
capybara-screenshot-1.0.14/gemfiles/ 0000755 0001750 0001750 00000000000 12766551460 016365 5 ustar pravi pravi capybara-screenshot-1.0.14/gemfiles/rspec.3.0.gemfile 0000644 0001750 0001750 00000000317 12766551460 021333 0 ustar pravi pravi # This file was generated by Appraisal
source "http://rubygems.org"
gem "rack", "~> 1.0"
gem "rake", "~> 10.0"
gem "appraisal", "~> 2.0"
gem "aruba", "~> 0.14.0"
gem "rspec", "3.0"
gemspec :path => "../"
capybara-screenshot-1.0.14/gemfiles/cucumber.2.4.gemfile 0000644 0001750 0001750 00000000326 12766551460 022027 0 ustar pravi pravi # This file was generated by Appraisal
source "http://rubygems.org"
gem "rack", "~> 1.0"
gem "rake", "~> 10.0"
gem "appraisal", "~> 2.0"
gem "aruba", "~> 0.14.0"
gem "cucumber", "~>2.4.0"
gemspec :path => "../"
capybara-screenshot-1.0.14/gemfiles/latest.gemfile 0000644 0001750 0001750 00000000274 12766551460 021216 0 ustar pravi pravi # This file was generated by Appraisal
source "http://rubygems.org"
gem "rack", "~> 1.0"
gem "rake", "~> 10.0"
gem "appraisal", "~> 2.0"
gem "aruba", "~> 0.14.0"
gemspec :path => "../"
capybara-screenshot-1.0.14/gemfiles/cucumber.1.3.gemfile 0000644 0001750 0001750 00000000326 12766551460 022025 0 ustar pravi pravi # This file was generated by Appraisal
source "http://rubygems.org"
gem "rack", "~> 1.0"
gem "rake", "~> 10.0"
gem "appraisal", "~> 2.0"
gem "aruba", "~> 0.14.0"
gem "cucumber", "~>1.3.0"
gemspec :path => "../"
capybara-screenshot-1.0.14/gemfiles/spinach.0.8.gemfile 0000644 0001750 0001750 00000000325 12766551460 021650 0 ustar pravi pravi # This file was generated by Appraisal
source "http://rubygems.org"
gem "rack", "~> 1.0"
gem "rake", "~> 10.0"
gem "appraisal", "~> 2.0"
gem "aruba", "~> 0.14.0"
gem "spinach", "~>0.8.0"
gemspec :path => "../"
capybara-screenshot-1.0.14/lib/ 0000755 0001750 0001750 00000000000 12766551460 015340 5 ustar pravi pravi capybara-screenshot-1.0.14/lib/capybara-screenshot/ 0000755 0001750 0001750 00000000000 12766551460 021275 5 ustar pravi pravi capybara-screenshot-1.0.14/lib/capybara-screenshot/pruner.rb 0000644 0001750 0001750 00000002574 12766551460 023145 0 ustar pravi pravi module Capybara
module Screenshot
class Pruner
attr_reader :strategy
def initialize(strategy)
@strategy = strategy
@strategy_proc = case strategy
when :keep_all
lambda { }
when :keep_last_run
lambda { prune_with_last_run_strategy }
when Hash
raise ArgumentError, ":keep key is required" unless strategy[:keep]
raise ArgumentError, ":keep must be a Integer" unless strategy[:keep].kind_of?(Integer)
raise ArgumentError, ":keep value must be number greater than zero" unless strategy[:keep].to_i > 0
lambda { prune_with_numeric_strategy(strategy[:keep].to_i) }
else
fail "Invalid prune strategy #{strategy}. `:keep_all`or `{ keep: 10 }` are valid examples."
end
end
def prune_old_screenshots
strategy_proc.call
end
private
attr_reader :strategy_proc
def wildcard_path
File.expand_path('*.{html,png}', Screenshot.capybara_root)
end
def prune_with_last_run_strategy
FileUtils.rm_rf(Dir.glob(wildcard_path))
end
def prune_with_numeric_strategy(count)
files = Dir.glob(wildcard_path).sort_by do |file_name|
File.mtime(File.expand_path(file_name, Screenshot.capybara_root))
end
FileUtils.rm_rf(files[0...-count])
end
end
end
end
capybara-screenshot-1.0.14/lib/capybara-screenshot/helpers.rb 0000644 0001750 0001750 00000001072 12766551460 023264 0 ustar pravi pravi class CapybaraScreenshot
module Helpers
extend self
COLORS =
{
"black" => 0,
"red" => 1,
"green" => 2,
"yellow" => 3,
"blue" => 4,
"purple" => 5,
"magenta" => 5,
"cyan" => 6,
"white" => 7
}
COLORS.each_pair do |color, value|
define_method color do |text|
"\033[0;#{30+value}m#{text}\033[0m"
end
define_method "bright_#{color}" do |text|
"\033[1;#{30+value}m#{text}\033[0m"
end
end
end
end
capybara-screenshot-1.0.14/lib/capybara-screenshot/s3_saver.rb 0000644 0001750 0001750 00000003471 12766551460 023354 0 ustar pravi pravi require 'aws-sdk'
module Capybara
module Screenshot
class S3Saver
DEFAULT_REGION = 'us-east-1'
def initialize(saver, s3_client, bucket_name)
@saver = saver
@s3_client = s3_client
@bucket_name = bucket_name
end
def self.new_with_configuration(saver, configuration)
default_s3_client_credentials = {
region: DEFAULT_REGION
}
s3_client_credentials = default_s3_client_credentials.merge(
configuration.fetch(:s3_client_credentials)
)
s3_client = Aws::S3::Client.new(s3_client_credentials)
bucket_name = configuration.fetch(:bucket_name)
new(saver, s3_client, bucket_name)
rescue KeyError
raise "Invalid S3 Configuration #{configuration}. Please refer to the documentation for the necessary configurations."
end
def save_and_upload_screenshot
save_and do |local_file_path|
File.open(local_file_path) do |file|
s3_client.put_object(
bucket: bucket_name,
key: File.basename(local_file_path),
body: file
)
end
end
end
alias_method :save, :save_and_upload_screenshot
def method_missing(method, *args)
# Need to use @saver instead of S3Saver#saver attr_reader method because
# using the method goes into infinite loop. Maybe attr_reader implements
# its methods via method_missing?
@saver.send(method, *args)
end
private
attr_reader :saver,
:s3_client,
:bucket_name
def save_and
saver.save
yield(saver.html_path) if block_given? && saver.html_saved?
yield(saver.screenshot_path) if block_given? && saver.screenshot_saved?
end
end
end
end
capybara-screenshot-1.0.14/lib/capybara-screenshot/spinach.rb 0000644 0001750 0001750 00000001514 12766551460 023250 0 ustar pravi pravi require "capybara-screenshot"
Spinach.hooks.before_scenario do |scenario|
Capybara::Screenshot.final_session_name = nil
end
module Capybara::Screenshot::Spinach
def self.fail_with_screenshot(step_data, exception, location, step_definitions)
if Capybara::Screenshot.autosave_on_failure
Capybara.using_session(Capybara::Screenshot.final_session_name) do
filename_prefix = Capybara::Screenshot.filename_prefix_for(:spinach, step_data)
saver = Capybara::Screenshot.new_saver(Capybara, Capybara.page, true, filename_prefix)
saver.save
saver.output_screenshot_path
end
end
end
end
Spinach.hooks.on_failed_step do |*args|
Capybara::Screenshot::Spinach.fail_with_screenshot(*args)
end
Spinach.hooks.on_error_step do |*args|
Capybara::Screenshot::Spinach.fail_with_screenshot(*args)
end
capybara-screenshot-1.0.14/lib/capybara-screenshot/rspec/ 0000755 0001750 0001750 00000000000 12766551460 022411 5 ustar pravi pravi capybara-screenshot-1.0.14/lib/capybara-screenshot/rspec/html_embed_reporter.rb 0000644 0001750 0001750 00000001514 12766551460 026761 0 ustar pravi pravi require 'capybara-screenshot/rspec/base_reporter'
require 'base64'
module Capybara
module Screenshot
module RSpec
module HtmlEmbedReporter
extend BaseReporter
enhance_with_screenshot :extra_failure_content
def extra_failure_content_with_screenshot(exception)
result = extra_failure_content_without_screenshot(exception)
example = @failed_examples.last
# Ignores saved html file, only saved image will be embedded (if present)
if (screenshot = example.metadata[:screenshot]) && screenshot[:image]
image = File.binread(screenshot[:image])
encoded_img = Base64.encode64(image)
result += ""
end
result
end
end
end
end
end
capybara-screenshot-1.0.14/lib/capybara-screenshot/rspec/textmate_link_reporter.rb 0000644 0001750 0001750 00000001012 12766551460 027522 0 ustar pravi pravi require 'capybara-screenshot/rspec/base_reporter'
require 'capybara-screenshot/rspec/html_link_reporter'
require 'shellwords'
module Capybara
module Screenshot
module RSpec
module TextMateLinkReporter
extend BaseReporter
include HtmlLinkReporter
enhance_with_screenshot :extra_failure_content
def attributes_for_screenshot_link(url)
super.merge("onclick" => "TextMate.system('open #{Shellwords.escape(url)}'); return false;")
end
end
end
end
end
capybara-screenshot-1.0.14/lib/capybara-screenshot/rspec/json_reporter.rb 0000644 0001750 0001750 00000000654 12766551460 025636 0 ustar pravi pravi require 'capybara-screenshot/rspec/base_reporter'
module Capybara
module Screenshot
module RSpec
module JsonReporter
extend BaseReporter
enhance_with_screenshot :format_example
def format_example_with_screenshot(example)
format_example_without_screenshot(example).merge({
screenshot: example.metadata[:screenshot]
})
end
end
end
end
end
capybara-screenshot-1.0.14/lib/capybara-screenshot/rspec/text_reporter.rb 0000644 0001750 0001750 00000002322 12766551460 025643 0 ustar pravi pravi require 'capybara-screenshot/rspec/base_reporter'
require 'capybara-screenshot/helpers'
module Capybara
module Screenshot
module RSpec
module TextReporter
extend BaseReporter
if ::RSpec::Core::Version::STRING.to_i <= 2
enhance_with_screenshot :dump_failure_info
else
enhance_with_screenshot :example_failed
end
def dump_failure_info_with_screenshot(example)
dump_failure_info_without_screenshot example
output_screenshot_info(example)
end
def example_failed_with_screenshot(notification)
example_failed_without_screenshot notification
output_screenshot_info(notification.example)
end
private
def output_screenshot_info(example)
return unless (screenshot = example.metadata[:screenshot])
output.puts(long_padding + CapybaraScreenshot::Helpers.yellow("HTML screenshot: file://#{screenshot[:html]}")) if screenshot[:html]
output.puts(long_padding + CapybaraScreenshot::Helpers.yellow("Image screenshot: file://#{screenshot[:image]}")) if screenshot[:image]
end
def long_padding
" "
end
end
end
end
end
capybara-screenshot-1.0.14/lib/capybara-screenshot/rspec/base_reporter.rb 0000644 0001750 0001750 00000001263 12766551460 025574 0 ustar pravi pravi module Capybara
module Screenshot
module RSpec
module BaseReporter
# Automatically set up method aliases (very much like ActiveSupport's `alias_method_chain`)
# when the module gets included.
def enhance_with_screenshot(method)
with_method, without_method = "#{method}_with_screenshot", "#{method}_without_screenshot"
define_singleton_method :included do |mod|
if mod.method_defined?(method) || mod.private_method_defined?(method)
mod.send :alias_method, without_method, method
mod.send :alias_method, method, with_method
end
end
end
end
end
end
end
capybara-screenshot-1.0.14/lib/capybara-screenshot/rspec/html_link_reporter.rb 0000644 0001750 0001750 00000002356 12766551460 026647 0 ustar pravi pravi require 'capybara-screenshot/rspec/base_reporter'
require 'cgi'
require 'uri'
module Capybara
module Screenshot
module RSpec
module HtmlLinkReporter
extend BaseReporter
enhance_with_screenshot :extra_failure_content
def extra_failure_content_with_screenshot(exception)
result = extra_failure_content_without_screenshot(exception)
example = @failed_examples.last
if (screenshot = example.metadata[:screenshot])
result << "
Saved files: " result << link_to_screenshot("HTML page", screenshot[:html]) if screenshot[:html] result << link_to_screenshot("Screenshot", screenshot[:image]) if screenshot[:image] result << "
" end result end def link_to_screenshot(title, path) url = URI.escape("file://#{path}") title = CGI.escape_html(title) attributes = attributes_for_screenshot_link(url).map { |name, val| %{#{name}="#{CGI.escape_html(val)}"} }.join(" ") "#{title}" end def attributes_for_screenshot_link(url) {"href" => url, "style" => "margin-right: 10px; font-weight: bold"} end end end end end capybara-screenshot-1.0.14/lib/capybara-screenshot/saver.rb 0000644 0001750 0001750 00000006716 12766551460 022754 0 ustar pravi pravi require 'capybara-screenshot/helpers' module Capybara module Screenshot class Saver attr_reader :capybara, :page, :file_base_name def initialize(capybara, page, html_save=true, filename_prefix='screenshot') @capybara, @page, @html_save = capybara, page, html_save time_now = Time.now timestamp = "#{time_now.strftime('%Y-%m-%d-%H-%M-%S.')}#{'%03d' % (time_now.usec/1000).to_i}" filename = [filename_prefix] filename << timestamp if Capybara::Screenshot.append_timestamp filename << SecureRandom.hex if Capybara::Screenshot.append_random @file_base_name = filename.join('_') Capybara::Screenshot.prune end def save # if current_path empty then nothing to screen shot as browser has not loaded any URL return if page.current_path.to_s.empty? save_html if @html_save save_screenshot end def save_html path = html_path clear_save_path do if Capybara::VERSION.match(/^\d+/)[0] == '1' capybara.save_page(page.body, "#{path}") else capybara.save_page("#{path}") end end @html_saved = true end def save_screenshot path = screenshot_path clear_save_path do result = Capybara::Screenshot.registered_drivers.fetch(capybara.current_driver) { |driver_name| warn "capybara-screenshot could not detect a screenshot driver for '#{capybara.current_driver}'. Saving with default with unknown results." Capybara::Screenshot.registered_drivers[:default] }.call(page.driver, path) @screenshot_saved = result != :not_supported end end def html_path File.join(Capybara::Screenshot.capybara_root, "#{file_base_name}.html") end def screenshot_path File.join(Capybara::Screenshot.capybara_root, "#{file_base_name}.png") end def html_saved? @html_saved end def screenshot_saved? @screenshot_saved end # If Capybara::Screenshot.capybara_tmp_path is set then # the html_path or screenshot_path can be appended to this path in # some versions of Capybara instead of using it as an absolute path def clear_save_path old_path = Capybara::Screenshot.capybara_tmp_path Capybara::Screenshot.capybara_tmp_path = nil yield ensure Capybara::Screenshot.capybara_tmp_path = old_path end def output_screenshot_path output "HTML screenshot: #{html_path}" if html_saved? output "Image screenshot: #{screenshot_path}" if screenshot_saved? end # Print image to screen, if imgcat is available def display_image system("#{imgcat} #{screenshot_path}") unless imgcat.nil? end private def output(message) puts " #{CapybaraScreenshot::Helpers.yellow(message)}" end def imgcat @imgcat ||= which('imgcat') end # Cross-platform way of finding an executable in the $PATH. # # which('ruby') #=> /usr/bin/ruby def which(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each { |ext| exe = File.join(path, "#{cmd}#{ext}") return exe if File.executable?(exe) && !File.directory?(exe) } end return nil end end end end capybara-screenshot-1.0.14/lib/capybara-screenshot/minitest.rb 0000644 0001750 0001750 00000001633 12766551460 023461 0 ustar pravi pravi require "capybara-screenshot" module Capybara::Screenshot::MiniTestPlugin def before_setup super Capybara::Screenshot.final_session_name = nil end def before_teardown super if self.class.ancestors.map(&:to_s).include?('Capybara::DSL') if Capybara::Screenshot.autosave_on_failure && !passed? && !skipped? Capybara.using_session(Capybara::Screenshot.final_session_name) do filename_prefix = Capybara::Screenshot.filename_prefix_for(:minitest, self) saver = Capybara::Screenshot.new_saver(Capybara, Capybara.page, true, filename_prefix) saver.save saver.output_screenshot_path end end end end end begin Minitest.const_get('Test') class Minitest::Test include Capybara::Screenshot::MiniTestPlugin end rescue NameError => e class MiniTest::Unit::TestCase include Capybara::Screenshot::MiniTestPlugin end end capybara-screenshot-1.0.14/lib/capybara-screenshot/testunit.rb 0000644 0001750 0001750 00000002125 12766551460 023501 0 ustar pravi pravi require 'test/unit/testresult' module Capybara::Screenshot class << self attr_accessor :testunit_paths end self.testunit_paths = [%r{test/integration}] end Test::Unit::TestCase.class_eval do setup do Capybara::Screenshot.final_session_name = nil end end Test::Unit::TestResult.class_eval do private def notify_fault_with_screenshot(fault, *args) notify_fault_without_screenshot fault, *args is_integration_test = fault.location.any? do |location| Capybara::Screenshot.testunit_paths.any? { |path| location.match(path) } end if is_integration_test if Capybara::Screenshot.autosave_on_failure Capybara.using_session(Capybara::Screenshot.final_session_name) do filename_prefix = Capybara::Screenshot.filename_prefix_for(:testunit, fault) saver = Capybara::Screenshot.new_saver(Capybara, Capybara.page, true, filename_prefix) saver.save saver.output_screenshot_path end end end end alias notify_fault_without_screenshot notify_fault alias notify_fault notify_fault_with_screenshot end capybara-screenshot-1.0.14/lib/capybara-screenshot/capybara.rb 0000644 0001750 0001750 00000001433 12766551460 023405 0 ustar pravi pravi require "capybara-screenshot" module Capybara module DSL # Adds class methods to Capybara module and gets mixed into # the current scope during Cucumber and RSpec tests def screenshot_and_save_page Capybara::Screenshot.screenshot_and_save_page end def screenshot_and_open_image Capybara::Screenshot.screenshot_and_open_image end def using_session_with_screenshot(name,&blk) original_session_name = Capybara.session_name Capybara::Screenshot.final_session_name = name using_session_without_screenshot(name,&blk) Capybara::Screenshot.final_session_name = original_session_name end alias_method :using_session_without_screenshot, :using_session alias_method :using_session, :using_session_with_screenshot end end capybara-screenshot-1.0.14/lib/capybara-screenshot/rspec.rb 0000644 0001750 0001750 00000010215 12766551460 022735 0 ustar pravi pravi require "capybara-screenshot" require "capybara-screenshot/rspec/text_reporter" require "capybara-screenshot/rspec/html_link_reporter" require "capybara-screenshot/rspec/html_embed_reporter" require "capybara-screenshot/rspec/json_reporter" require "capybara-screenshot/rspec/textmate_link_reporter" module Capybara module Screenshot module RSpec # Reporters extend RSpec formatters to display information about screenshots for failed # examples. # # Technically, a reporter is a module that gets injected into a RSpec formatter class. # It uses method aliasing to extend some (usually just one) of the formatter's methods. # # Implementing a custom reporter is as simple as creating a module and setting up the # appropriate aliases. Use `BaseReporter.enhance_with_screenshot` if you don't want # to set up the aliases manually: # # module MyReporter # extend Capybara::Screenshot::RSpec::BaseReporter # # # Will replace the formatter's original `dump_failure_info` method with # # `dump_failure_info_with_screenshot` from this module: # enhance_with_screenshot :dump_failure_info # # def dump_failure_info_with_screenshot(example) # dump_failure_info_without_screenshot(example) # call original implementation # ... # your additions here # end # end # # Finally customize `Capybara::Screenshot::RSpec::FORMATTERS` to make sure your reporter # gets injected into the appropriate formatter. REPORTERS = { "RSpec::Core::Formatters::ProgressFormatter" => Capybara::Screenshot::RSpec::TextReporter, "RSpec::Core::Formatters::DocumentationFormatter" => Capybara::Screenshot::RSpec::TextReporter, "RSpec::Core::Formatters::HtmlFormatter" => Capybara::Screenshot::RSpec::HtmlLinkReporter, "RSpec::Core::Formatters::JsonFormatter" => Capybara::Screenshot::RSpec::JsonReporter, "RSpec::Core::Formatters::TextMateFormatter" => Capybara::Screenshot::RSpec::TextMateLinkReporter, # RSpec 2 "RSpec::Mate::Formatters::TextMateFormatter" => Capybara::Screenshot::RSpec::TextMateLinkReporter, # RSpec 3 "Fuubar" => Capybara::Screenshot::RSpec::TextReporter } class << self attr_accessor :add_link_to_screenshot_for_failed_examples def after_failed_example(example) if example.example_group.include?(Capybara::DSL) # Capybara DSL method has been included for a feature we can snapshot Capybara.using_session(Capybara::Screenshot.final_session_name) do if Capybara.page.current_url != '' && Capybara::Screenshot.autosave_on_failure && example.exception filename_prefix = Capybara::Screenshot.filename_prefix_for(:rspec, example) saver = Capybara::Screenshot.new_saver(Capybara, Capybara.page, true, filename_prefix) saver.save example.metadata[:screenshot] = {} example.metadata[:screenshot][:html] = saver.html_path if saver.html_saved? example.metadata[:screenshot][:image] = saver.screenshot_path if saver.screenshot_saved? end end end end end self.add_link_to_screenshot_for_failed_examples = true end end end RSpec.configure do |config| config.before do Capybara::Screenshot.final_session_name = nil end config.after do |example_from_block_arg| # RSpec 3 no longer defines `example`, but passes the example as block argument instead example = config.respond_to?(:expose_current_running_example_as) ? example_from_block_arg : self.example Capybara::Screenshot::RSpec.after_failed_example(example) end config.before(:suite) do if Capybara::Screenshot::RSpec.add_link_to_screenshot_for_failed_examples RSpec.configuration.formatters.each do |formatter| next unless (reporter_module = Capybara::Screenshot::RSpec::REPORTERS[formatter.class.to_s]) formatter.singleton_class.send :include, reporter_module end end end end capybara-screenshot-1.0.14/lib/capybara-screenshot/cucumber.rb 0000644 0001750 0001750 00000001754 12766551460 023436 0 ustar pravi pravi require "capybara-screenshot" Before do |scenario| Capybara::Screenshot.final_session_name = nil end After do |scenario| if Capybara::Screenshot.autosave_on_failure && scenario.failed? Capybara.using_session(Capybara::Screenshot.final_session_name) do filename_prefix = Capybara::Screenshot.filename_prefix_for(:cucumber, scenario) saver = Capybara::Screenshot.new_saver(Capybara, Capybara.page, true, filename_prefix) saver.save saver.output_screenshot_path # Trying to embed the screenshot into our output." if File.exist?(saver.screenshot_path) require "base64" #encode the image into it's base64 representation image = open(saver.screenshot_path, 'rb') {|io|io.read} saver.display_image #this will embed the image in the HTML report, embed() is defined in cucumber encoded_img = Base64.encode64(image) embed(encoded_img, 'image/png;base64', "Screenshot of the error") end end end end capybara-screenshot-1.0.14/lib/capybara-screenshot/version.rb 0000644 0001750 0001750 00000000105 12766551460 023303 0 ustar pravi pravi module Capybara module Screenshot VERSION = '1.0.14' end end capybara-screenshot-1.0.14/lib/capybara-screenshot.rb 0000644 0001750 0001750 00000013005 12766551460 021621 0 ustar pravi pravi module Capybara module Screenshot class << self attr_accessor :autosave_on_failure attr_accessor :registered_drivers attr_accessor :filename_prefix_formatters attr_accessor :append_timestamp attr_accessor :append_random attr_accessor :webkit_options attr_writer :final_session_name attr_accessor :prune_strategy attr_accessor :s3_configuration end self.autosave_on_failure = true self.registered_drivers = {} self.filename_prefix_formatters = {} self.append_timestamp = true self.append_random = false self.webkit_options = {} self.prune_strategy = :keep_all self.s3_configuration = {} def self.append_screenshot_path=(value) $stderr.puts "WARNING: Capybara::Screenshot.append_screenshot_path is deprecated. " + "Please use Capybara::Screenshot::RSpec.add_link_to_screenshot_for_failed_examples instead." RSpec.add_link_to_screenshot_for_failed_examples = value end def self.screenshot_and_save_page saver = new_saver(Capybara, Capybara.page) if saver.save {:html => saver.html_path, :image => saver.screenshot_path} end end def self.screenshot_and_open_image require "launchy" saver = new_saver(Capybara, Capybara.page, false) if saver.save Launchy.open saver.screenshot_path {:html => nil, :image => saver.screenshot_path} end end class << self alias screen_shot_and_save_page screenshot_and_save_page alias screen_shot_and_open_image screenshot_and_open_image end def self.filename_prefix_for(test_type, test) filename_prefix_formatters.fetch(test_type) { |key| filename_prefix_formatters[:default] }.call(test) end def self.capybara_root @capybara_root ||= if defined?(::Rails) && ::Rails.root.present? ::Rails.root.join capybara_tmp_path elsif defined?(Padrino) File.expand_path(capybara_tmp_path, Padrino.root) elsif defined?(Sinatra) File.join(Sinatra::Application.root, capybara_tmp_path) else capybara_tmp_path end.to_s end def self.register_driver(driver, &block) self.registered_drivers[driver] = block end def self.register_filename_prefix_formatter(test_type, &block) self.filename_prefix_formatters[test_type] = block end def self.final_session_name @final_session_name || Capybara.session_name || :default end # Prune screenshots based on prune_strategy # Will run only once unless force:true def self.prune(options = {}) reset_prune_history if options[:force] Capybara::Screenshot::Pruner.new(Capybara::Screenshot.prune_strategy).prune_old_screenshots unless @pruned_previous_screenshots @pruned_previous_screenshots = true end # Reset prune history allowing further prunining on next failure def self.reset_prune_history @pruned_previous_screenshots = nil end def self.new_saver(*args) saver = Saver.new(*args) unless s3_configuration.empty? require 'capybara-screenshot/s3_saver' saver = S3Saver.new_with_configuration(saver, s3_configuration) end return saver end private # If the path isn't set, default to the current directory def self.capybara_tmp_path # `#save_and_open_page_path` is deprecated # https://github.com/jnicklas/capybara/blob/48ab1ede946dec2250a2d1d8cbb3313f25096456/History.md#L37 if Capybara.respond_to?(:save_path) Capybara.save_path else Capybara.save_and_open_page_path end || '.' end # Configure the path unless '.' def self.capybara_tmp_path=(path) return if path == '.' # `#save_and_open_page_path` is deprecated # https://github.com/jnicklas/capybara/blob/48ab1ede946dec2250a2d1d8cbb3313f25096456/History.md#L37 if Capybara.respond_to?(:save_path) Capybara.save_path = path else Capybara.save_and_open_page_path = path end end end end # Register driver renderers. # The block should return `:not_supported` if a screenshot could not be saved. Capybara::Screenshot.class_eval do register_driver(:default) do |driver, path| driver.render(path) end register_driver(:rack_test) do |driver, path| :not_supported end register_driver(:mechanize) do |driver, path| :not_supported end register_driver(:selenium) do |driver, path| driver.browser.save_screenshot(path) end register_driver(:poltergeist) do |driver, path| driver.render(path, :full => true) end register_driver(:poltergeist_billy) do |driver, path| driver.render(path, :full => true) end webkit_block = proc do |driver, path| if driver.respond_to?(:save_screenshot) driver.save_screenshot(path, webkit_options) else driver.render(path) end end register_driver :webkit, &webkit_block register_driver :webkit_debug, &webkit_block register_driver(:terminus) do |driver, path| if driver.respond_to?(:save_screenshot) driver.save_screenshot(path) else :not_supported end end end # Register filename prefix formatters Capybara::Screenshot.class_eval do register_filename_prefix_formatter(:default) do |test| 'screenshot' end end require 'capybara/dsl' require 'capybara/util/save_and_open_page' if Capybara::VERSION.match(/^\d+/)[0] == '1' # no longer needed in Capybara version 2 require 'capybara-screenshot/saver' require 'capybara-screenshot/capybara' require 'capybara-screenshot/pruner' capybara-screenshot-1.0.14/.travis.yml 0000644 0001750 0001750 00000000377 12766551460 016712 0 ustar pravi pravi language: ruby script: "rake travis:ci" rvm: - 2.0.0 - 2.1.10 - 2.2.1 - 2.3.1 gemfile: - gemfiles/cucumber.1.3.gemfile - gemfiles/cucumber.2.4.gemfile - gemfiles/latest.gemfile - gemfiles/rspec.3.0.gemfile - gemfiles/spinach.0.8.gemfile capybara-screenshot-1.0.14/.gitignore 0000644 0001750 0001750 00000000116 12766551460 016560 0 ustar pravi pravi *.gem .bundle Gemfile.lock gemfiles/*.lock pkg/* .rvmrc bin tmp .ruby-version capybara-screenshot-1.0.14/Appraisals 0000644 0001750 0001750 00000000446 12766551460 016620 0 ustar pravi pravi appraise "rspec.3.0" do gem "rspec", "3.0" end appraise "cucumber.1.3" do gem "cucumber", "~>1.3.0" end appraise "cucumber.2.4" do gem "cucumber", "~>2.4.0" end appraise "spinach.0.8" do gem "spinach", "~>0.8.0" end appraise "latest" do # will get latest versions of all gems end capybara-screenshot-1.0.14/LICENSE 0000644 0001750 0001750 00000002053 12766551460 015577 0 ustar pravi pravi Copyright (c) 2011 Matthew O'Riordan, inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. capybara-screenshot-1.0.14/capybara-screenshot.gemspec 0000644 0001750 0001750 00000002742 12766551460 022101 0 ustar pravi pravi # -*- 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.license = 'MIT' s.rubyforge_project = "capybara-screenshot" if RUBY_VERSION < "1.9" s.add_dependency 'capybara', ['>= 1.0', '< 2'] else s.add_dependency 'capybara', ['>= 1.0', '< 3'] end s.add_dependency 'launchy' s.add_development_dependency 'rspec' s.add_development_dependency 'timecop' s.add_development_dependency 'cucumber' s.add_development_dependency 'aruba' s.add_development_dependency 'sinatra' s.add_development_dependency 'test-unit' s.add_development_dependency 'spinach' s.add_development_dependency 'minitest' s.add_development_dependency 'aws-sdk' 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 capybara-screenshot-1.0.14/Rakefile 0000644 0001750 0001750 00000001322 12766551460 016235 0 ustar pravi pravi require 'rubygems' require 'bundler/setup' Bundler::GemHelper.install_tasks require 'rspec/core/rake_task' rspec_rake_task = RSpec::Core::RakeTask.new(:spec) task default: [:spec] def target_gem gem_file = ENV['BUNDLE_GEMFILE'] || '' targets = %w(cucumber spinach rspec) target = gem_file.match(/(#{targets.join('|')})/) if target && targets.include?(target[1]) target[1].to_sym else [] end end namespace :travis do task :ci => target_gem do Rake::Task['spec'].invoke end task :cucumber do rspec_rake_task.pattern = 'spec/cucumber' end task :spinach do rspec_rake_task.pattern = 'spec/spinach' end task :rspec do rspec_rake_task.pattern = 'spec/rspec' end end capybara-screenshot-1.0.14/Gemfile 0000644 0001750 0001750 00000000306 12766551460 016064 0 ustar pravi pravi source "http://rubygems.org" # Specify your gem's dependencies in capybara-screenshot.gemspec gemspec gem 'rack', '~> 1.0' gem 'rake', '~> 10.0' gem 'appraisal', '~> 2.0' gem 'aruba', '~> 0.14.0' capybara-screenshot-1.0.14/.rspec 0000644 0001750 0001750 00000000037 12766551460 015707 0 ustar pravi pravi --color --format documentation capybara-screenshot-1.0.14/spec/ 0000755 0001750 0001750 00000000000 12766551460 015524 5 ustar pravi pravi capybara-screenshot-1.0.14/spec/spinach/ 0000755 0001750 0001750 00000000000 12766551460 017151 5 ustar pravi pravi capybara-screenshot-1.0.14/spec/spinach/spinach_spec.rb 0000644 0001750 0001750 00000004023 12766551460 022134 0 ustar pravi pravi require "spec_helper" describe "Using Capybara::Screenshot with Spinach" do include CommonSetup before do setup_aruba end def run_failing_case(failure_message, code) write_file('steps/failure.rb', <<-RUBY) #{ensure_load_paths_valid} require 'spinach/support/spinach_failure.rb' #{setup_test_app} RUBY write_file('spinach.feature', code) cmd = 'bundle exec spinach -f .' run_simple_with_retry cmd, false expect(last_command_started.output).to match(failure_message) end it "saves a screenshot on failure" do run_failing_case(%q{Unable to find link or button "you'll never find me"}, <<-GHERKIN) Feature: Failure Scenario: Failure Given I visit "/" And I click on a missing link GHERKIN expect('tmp/my_screenshot.html').to have_file_content('This is the root page') end it "saves a screenshot on an error" do run_failing_case(%q{you can't handle me}, <<-GHERKIN) Feature: Failure Scenario: Failure Given I visit "/" And I trigger an unhandled exception GHERKIN expect('tmp/my_screenshot.html').to have_file_content('This is the root page') end it "saves a screenshot for the correct session for failures using_session" do run_failing_case(%q{Unable to find link or button "you'll never find me"}, <<-GHERKIN) Feature: Failure Scenario: Failure in different session Given I visit "/" And I click on a missing link on a different page in a different session GHERKIN expect('tmp/my_screenshot.html').to have_file_content('This is a different page') end it 'on failure it prunes previous screenshots when strategy is set' do create_screenshot_for_pruning configure_prune_strategy :last_run run_failing_case(%q{Unable to find link or button "you'll never find me"}, <<-GHERKIN) Feature: Failure Scenario: Failure Given I visit "/" And I click on a missing link GHERKIN assert_screenshot_pruned end end capybara-screenshot-1.0.14/spec/spinach/support/ 0000755 0001750 0001750 00000000000 12766551460 020665 5 ustar pravi pravi capybara-screenshot-1.0.14/spec/spinach/support/spinach_failure.rb 0000644 0001750 0001750 00000002273 12766551460 024352 0 ustar pravi pravi require 'capybara' require 'capybara/rspec' require 'capybara-screenshot' require 'capybara-screenshot/spinach' require 'spinach/capybara' require 'support/test_app' Spinach.config.failure_exceptions = [Capybara::ElementNotFound] class Spinach::Features::Failure < Spinach::FeatureSteps include ::Capybara::DSL before do ::Capybara::Screenshot.register_filename_prefix_formatter(:spinach) do |failed_step| raise 'expected failing step' if !@expected_failed_step.nil? && !failed_step.name.include?(@expected_failed_step) 'my_screenshot' end end step 'I visit "/"' do visit '/' end step 'I click on a missing link' do @expected_failed_step = 'I click on a missing link' click_on "you'll never find me" end step 'I trigger an unhandled exception' do @expected_failed_step = "I trigger an unhandled exception" raise "you can't handle me" end step 'I click on a missing link on a different page in a different session' do using_session :different_session do visit '/different_page' @expected_failed_step = 'I click on a missing link on a different page in a different session' click_on "you'll never find me" end end end capybara-screenshot-1.0.14/spec/rspec/ 0000755 0001750 0001750 00000000000 12766551460 016640 5 ustar pravi pravi capybara-screenshot-1.0.14/spec/rspec/rspec_spec.rb 0000644 0001750 0001750 00000011571 12766551460 021320 0 ustar pravi pravi require 'spec_helper' describe Capybara::Screenshot::RSpec, :type => :aruba do describe "used with RSpec" do include CommonSetup before do setup_aruba Capybara::Screenshot.capybara_tmp_path = expand_path('tmp') end def run_failing_case(code, error_message, format=nil) run_case code, format: format if error_message.kind_of?(Regexp) expect(last_command_started.output).to match(error_message) else expect(last_command_started.output).to include(error_message) end end def run_case(code, options = {}) write_file('spec/test_failure.rb', <<-RUBY) #{ensure_load_paths_valid} require 'rspec' require 'capybara' require 'capybara/rspec' require 'capybara-screenshot' require 'capybara-screenshot/rspec' #{setup_test_app} #{code} RUBY cmd = cmd_with_format(options[:format]) run_simple_with_retry cmd, false expect(last_command_started.output).to match('0 failures') if options[:assert_all_passed] end def cmd_with_format(format) "rspec #{"--format #{format} " if format}#{expand_path('spec/test_failure.rb')}" end it 'saves a screenshot on failure' do run_failing_case <<-RUBY, %q{Unable to find link or button "you'll never find me"} feature 'screenshot with failure' do scenario 'click on a missing link' do visit '/' expect(page.body).to include('This is the root page') click_on "you'll never find me" end end RUBY expect(expand_path('tmp/screenshot.html')).to_not have_file_content('This is the root page') end formatters = { progress: 'HTML screenshot:', documentation: 'HTML screenshot:', html: %r{]*>HTML page}, json: '"screenshot":{"' } # Textmate formatter is only included in RSpec 2 if RSpec::Core::Version::STRING.to_i == 2 formatters[:textmate] = %r{TextMate\.system\(.*open file://\./tmp/screenshot.html} end formatters.each do |formatter, error_message| it "uses the associated #{formatter} formatter" do run_failing_case <<-RUBY, error_message, formatter feature 'screenshot with failure' do scenario 'click on a missing link' do visit '/' click_on "you'll never find me" end end RUBY expect('tmp/screenshot.html').to have_file_content('This is the root page') end end it "does not save a screenshot for tests that don't use Capybara" do run_failing_case <<-RUBY, %q{expected: false} describe 'failing test' do it 'fails intentionally' do expect(true).to eql(false) end end RUBY expect('tmp/screenshot.html').to_not be_an_existing_file end it 'saves a screenshot for the correct session for failures using_session' do run_failing_case <<-RUBY, %q{Unable to find link or button "you'll never find me"} feature 'screenshot with failure' do scenario 'click on a missing link' do visit '/' expect(page.body).to include('This is the root page') using_session :different_session do visit '/different_page' expect(page.body).to include('This is a different page') click_on "you'll never find me" end end end RUBY expect('tmp/screenshot.html').to have_file_content(/is/) end context 'pruning' do before do create_screenshot_for_pruning configure_prune_strategy :last_run end it 'on failure it prunes previous screenshots when strategy is set' do run_failing_case <<-RUBY, 'HTML screenshot:', :progress feature 'screenshot with failure' do scenario 'click on a missing link' do visit '/' click_on "you'll never find me" end end RUBY assert_screenshot_pruned end it 'on success it never prunes' do run_case <<-CUCUMBER, assert_all_passed: true feature 'screenshot without failure' do scenario 'click on a link' do visit '/' end end CUCUMBER assert_screenshot_not_pruned end end context 'no pruning by default' do before do create_screenshot_for_pruning end it 'on failure it leaves existing screenshots' do run_failing_case <<-RUBY, 'HTML screenshot:', :progress feature 'screenshot with failure' do scenario 'click on a missing link' do visit '/' click_on "you'll never find me" end end RUBY assert_screenshot_not_pruned end end end end capybara-screenshot-1.0.14/spec/spec_helper.rb 0000644 0001750 0001750 00000002510 12766551460 020340 0 ustar pravi pravi # This file was generated by the `rspec --init` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # Require this file using `require "spec_helper.rb"` to ensure that it is only # loaded once. # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration $: << '../lib' require 'rspec' require 'capybara-screenshot' require 'capybara-screenshot/rspec' require 'timecop' RSpec.configure do |config| if RSpec::Core::Version::STRING.to_i == 2 config.treat_symbols_as_metadata_keys_with_true_values = true end config.run_all_when_everything_filtered = true config.filter_run :focus config.before do @aruba_timeout_seconds = 60 end if RUBY_PLATFORM == 'java' end Capybara.app = lambda { |env| [200, {}, ["OK"]] } $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) if RUBY_VERSION < '1.9.3' ::Dir.glob(::File.expand_path('../support/*.rb', __FILE__)).each { |f| require File.join(File.dirname(f), File.basename(f, '.rb')) } ::Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__)).each { |f| require File.join(File.dirname(f), File.basename(f, '.rb')) } else ::Dir.glob(::File.expand_path('../support/*.rb', __FILE__)).each { |f| require_relative f } ::Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__)).each { |f| require_relative f } end capybara-screenshot-1.0.14/spec/feature/ 0000755 0001750 0001750 00000000000 12766551460 017157 5 ustar pravi pravi capybara-screenshot-1.0.14/spec/feature/testunit_spec.rb 0000644 0001750 0001750 00000005023 12766551460 022375 0 ustar pravi pravi require "spec_helper" describe "Using Capybara::Screenshot with Test::Unit" do include CommonSetup before do setup_aruba end def run_failing_case(code, integration_path = '.') write_file("#{integration_path}/test_failure.rb", <<-RUBY) #{ensure_load_paths_valid} require 'test/unit' require 'capybara' require 'capybara/rspec' require 'capybara-screenshot' require 'capybara-screenshot/testunit' #{setup_test_app} Capybara::Screenshot.register_filename_prefix_formatter(:testunit) do | fault | raise "expected fault" unless fault.exception.message.include? %q{Unable to find link or button "you'll never find me"} 'my_screenshot' end class TestFailure < Test::Unit::TestCase include Capybara::DSL def test_failure #{code} end end RUBY cmd = "bundle exec ruby #{integration_path}/test_failure.rb" run_simple_with_retry cmd, false expect(last_command_started.output).to include %q{Unable to find link or button "you'll never find me"} end it "saves a screenshot on failure for any test in path 'test/integration'" do run_failing_case <<-RUBY, 'test/integration' visit '/' assert(page.body.include?('This is the root page')) click_on "you'll never find me" RUBY expect('tmp/my_screenshot.html').to have_file_content('This is the root page') end it "does not generate a screenshot for tests that are not in 'test/integration'" do run_failing_case <<-RUBY, 'test/something-else' visit '/' assert(page.body.include?('This is the root page')) click_on "you'll never find me" RUBY expect('tmp/my_screenshot.html').to_not be_an_existing_file end it 'saves a screenshot for the correct session for failures using_session' do run_failing_case <<-RUBY, 'test/integration' visit '/' assert(page.body.include?('This is the root page')) using_session :different_session do visit '/different_page' assert(page.body.include?('This is a different page')) click_on "you'll never find me" end RUBY expect('tmp/my_screenshot.html').to have_file_content('This is a different page') end it 'prunes screenshots on failure' do create_screenshot_for_pruning configure_prune_strategy :last_run run_failing_case <<-RUBY, 'test/integration' visit '/' assert(page.body.include?('This is the root page')) click_on "you'll never find me" RUBY assert_screenshot_pruned end end capybara-screenshot-1.0.14/spec/feature/minitest_spec.rb 0000644 0001750 0001750 00000004541 12766551460 022356 0 ustar pravi pravi require "spec_helper" describe "Using Capybara::Screenshot with MiniTest" do include CommonSetup before do setup_aruba end def run_failing_case(code) write_file('test_failure.rb', <<-RUBY) #{ensure_load_paths_valid} require 'minitest/autorun' require 'capybara' require 'capybara-screenshot' require 'capybara-screenshot/minitest' #{setup_test_app} Capybara::Screenshot.register_filename_prefix_formatter(:minitest) do |test_case| test_name = test_case.respond_to?(:name) ? test_case.name : test_case.__name__ raise "expected fault" unless test_name.include? 'test_failure' 'my_screenshot' end #{code} RUBY cmd = 'bundle exec ruby test_failure.rb' run_simple_with_retry cmd, false expect(last_command_started.output).to include %q{Unable to find link or button "you'll never find me"} end it 'saves a screenshot on failure' do run_failing_case <<-RUBY class TestFailure < MiniTest::Unit::TestCase include Capybara::DSL def test_failure visit '/' assert(page.body.include?('This is the root page')) click_on "you'll never find me" end end RUBY expect('tmp/my_screenshot.html').to have_file_content('This is the root page') end it 'saves a screenshot for the correct session for failures using_session' do run_failing_case <<-RUBY class TestFailure < Minitest::Unit::TestCase include Capybara::DSL def test_failure visit '/' assert(page.body.include?('This is the root page')) using_session :different_session do visit '/different_page' assert(page.body.include?('This is a different page')) click_on "you'll never find me" end end end RUBY expect('tmp/my_screenshot.html').to have_file_content('This is a different page') end it 'prunes screenshots on failure' do create_screenshot_for_pruning configure_prune_strategy :last_run run_failing_case <<-RUBY class TestFailure < Minitest::Unit::TestCase include Capybara::DSL def test_failure visit '/' assert(page.body.include?('This is the root page')) click_on "you'll never find me" end end RUBY assert_screenshot_pruned end end capybara-screenshot-1.0.14/spec/support/ 0000755 0001750 0001750 00000000000 12766551460 017240 5 ustar pravi pravi capybara-screenshot-1.0.14/spec/support/common_setup.rb 0000644 0001750 0001750 00000003604 12766551460 022300 0 ustar pravi pravi module CommonSetup def self.included(target) target.class_eval do include Aruba::Api end target.let(:gem_root) { File.expand_path('../..', File.dirname(__FILE__)) } target.let(:ensure_load_paths_valid) do <<-RUBY %w(lib spec).each do |include_folder| $LOAD_PATH.unshift(File.join('#{gem_root}', include_folder)) end RUBY end target.let(:screenshot_path) { 'tmp' } target.let(:screenshot_for_pruning_path) { "#{screenshot_path}/old_screenshot.html" } target.let(:setup_test_app) do <<-RUBY require 'support/test_app' Capybara::Screenshot.capybara_tmp_path = '#{screenshot_path}' Capybara.app = TestApp Capybara::Screenshot.append_timestamp = false #{@additional_setup_steps} RUBY end target.before do if ENV['BUNDLE_GEMFILE'] && ENV['BUNDLE_GEMFILE'].match(/^\.|^[^\/\.]/) ENV['BUNDLE_GEMFILE'] = File.join(gem_root, ENV['BUNDLE_GEMFILE']) end end target.after(:each) do |example| if example.exception puts "Output from failed Aruba test:" puts all_output.split(/\n/).map { |line| " #{line}"} puts "" end end def run_simple_with_retry(*args) run_simple(*args) rescue ChildProcess::TimeoutError => e puts "run_simple(#{args.join(', ')}) failed. Will retry once. `#{e.message}`" run_simple(*args) end def configure_prune_strategy(strategy) @additional_setup_steps = "Capybara::Screenshot.prune_strategy = :keep_last_run" end def create_screenshot_for_pruning write_file screenshot_for_pruning_path, '' end def assert_screenshot_pruned expect(screenshot_for_pruning_path).to_not be_an_existing_file end def assert_screenshot_not_pruned expect(screenshot_for_pruning_path).to be_an_existing_file end end end capybara-screenshot-1.0.14/spec/support/test_app.rb 0000644 0001750 0001750 00000000313 12766551460 021401 0 ustar pravi pravi require 'sinatra/base' Sinatra::Application.root = '.' class TestApp < Sinatra::Base get '/' do 'This is the root page' end get '/different_page' do 'This is a different page' end end capybara-screenshot-1.0.14/spec/support/html_reporter_context.rb 0000644 0001750 0001750 00000001473 12766551460 024224 0 ustar pravi pravi shared_context 'html reporter' do def set_example(example) @reporter.instance_variable_set :@failed_examples, [example] end before do # Mocking `RSpec::Core::Formatters::HtmlFormatter`, but only implementing the things that # are actually used in `HtmlLinkReporter#extra_failure_content_with_screenshot`. @reporter_class = Class.new do def extra_failure_content(exception) "original content" end end @reporter = @reporter_class.new @reporter.singleton_class.send :include, described_class end context 'when there is no screenshot' do before do set_example double("example", metadata: {}) end it 'doesnt change the original content of the reporter' do expect(@reporter.extra_failure_content(nil)).to eql("original content") end end end capybara-screenshot-1.0.14/spec/support/aruba.rb 0000644 0001750 0001750 00000000107 12766551460 020655 0 ustar pravi pravi require 'aruba/rspec' require 'aruba/api' require 'aruba/config/jruby' capybara-screenshot-1.0.14/spec/unit/ 0000755 0001750 0001750 00000000000 12766551460 016503 5 ustar pravi pravi capybara-screenshot-1.0.14/spec/unit/s3_saver_spec.rb 0000644 0001750 0001750 00000010005 12766551460 021563 0 ustar pravi pravi require 'spec_helper' require 'capybara-screenshot/s3_saver' describe Capybara::Screenshot::S3Saver do let(:saver) { double('saver') } let(:bucket_name) { double('bucket_name') } let(:s3_client) { double('s3_client') } let(:s3_saver) { Capybara::Screenshot::S3Saver.new(saver, s3_client, bucket_name) } describe '.new_with_configuration' do let(:access_key_id) { double('access_key_id') } let(:secret_access_key) { double('secret_access_key') } let(:s3_client_credentials_using_defaults) { { access_key_id: access_key_id, secret_access_key: secret_access_key } } let(:region) { double('region') } let(:s3_client_credentials) { s3_client_credentials_using_defaults.merge(region: region) } it 'destructures the configuration into its components' do allow(Aws::S3::Client).to receive(:new).and_return(s3_client) allow(Capybara::Screenshot::S3Saver).to receive(:new) Capybara::Screenshot::S3Saver.new_with_configuration(saver, { s3_client_credentials: s3_client_credentials, bucket_name: bucket_name }) expect(Aws::S3::Client).to have_received(:new).with(s3_client_credentials) expect(Capybara::Screenshot::S3Saver).to have_received(:new).with(saver, s3_client, bucket_name) end it 'defaults the region to us-east-1' do default_region = 'us-east-1' allow(Aws::S3::Client).to receive(:new).and_return(s3_client) allow(Capybara::Screenshot::S3Saver).to receive(:new) Capybara::Screenshot::S3Saver.new_with_configuration(saver, { s3_client_credentials: s3_client_credentials_using_defaults, bucket_name: bucket_name }) expect(Aws::S3::Client).to have_received(:new).with( s3_client_credentials.merge(region: default_region) ) expect(Capybara::Screenshot::S3Saver).to have_received(:new).with(saver, s3_client, bucket_name) end end describe '#save' do before do allow(saver).to receive(:html_saved?).and_return(false) allow(saver).to receive(:screenshot_saved?).and_return(false) allow(saver).to receive(:save) end it 'calls save on the underlying saver' do expect(saver).to receive(:save) s3_saver.save end it 'uploads the html' do html_path = '/foo/bar.html' expect(saver).to receive(:html_path).and_return(html_path) expect(saver).to receive(:html_saved?).and_return(true) html_file = double('html_file') expect(File).to receive(:open).with(html_path).and_yield(html_file) expect(s3_client).to receive(:put_object).with( bucket: bucket_name, key: 'bar.html', body: html_file ) s3_saver.save end it 'uploads the screenshot' do screenshot_path = '/baz/bim.jpg' expect(saver).to receive(:screenshot_path).and_return(screenshot_path) expect(saver).to receive(:screenshot_saved?).and_return(true) screenshot_file = double('screenshot_file') expect(File).to receive(:open).with(screenshot_path).and_yield(screenshot_file) expect(s3_client).to receive(:put_object).with( bucket: bucket_name, key: 'bim.jpg', body: screenshot_file ) s3_saver.save end end # Needed because we cannot depend on Verifying Doubles # in older RSpec versions describe 'an actual saver' do it 'implements the methods needed by the s3 saver' do instance_methods = Capybara::Screenshot::Saver.instance_methods expect(instance_methods).to include(:save) expect(instance_methods).to include(:html_saved?) expect(instance_methods).to include(:html_path) expect(instance_methods).to include(:screenshot_saved?) expect(instance_methods).to include(:screenshot_path) end end describe 'any other method' do it 'transparently passes through to the saver' do allow(saver).to receive(:foo_bar) args = double('args') s3_saver.foo_bar(*args) expect(saver).to have_received(:foo_bar).with(*args) end end end capybara-screenshot-1.0.14/spec/unit/capybara-screenshot_rspec_spec.rb 0000644 0001750 0001750 00000003521 12766551460 025174 0 ustar pravi pravi require 'spec_helper' describe Capybara::Screenshot::RSpec do describe '.after_failed_example' do context 'for a failed example in a feature that can be snapshotted' do before do allow(Capybara.page).to receive(:current_url).and_return("http://test.local") allow(Capybara::Screenshot::Saver).to receive(:new).and_return(mock_saver) end let(:example_group) { Module.new.send(:include, Capybara::DSL) } let(:example) { double("example", exception: Exception.new, example_group: example_group, metadata: {}) } let(:mock_saver) do Capybara::Screenshot::Saver.new(Capybara, Capybara.page).tap do |saver| allow(saver).to receive(:save) end end it 'instantiates a saver and calls `save` on it' do expect(mock_saver).to receive(:save) described_class.after_failed_example(example) end it 'extends the metadata with an empty hash for screenshot metadata' do described_class.after_failed_example(example) expect(example.metadata).to have_key(:screenshot) expect(example.metadata[:screenshot]).to eql({}) end context 'when a html file gets saved' do before { allow(mock_saver).to receive(:html_saved?).and_return(true) } it 'adds the html file path to the screenshot metadata' do described_class.after_failed_example(example) expect(example.metadata[:screenshot][:html]).to match("./screenshot") end end context 'when an image gets saved' do before { allow(mock_saver).to receive(:screenshot_saved?).and_return(true) } it 'adds the image path to the screenshot metadata' do described_class.after_failed_example(example) expect(example.metadata[:screenshot][:image]).to match("./screenshot") end end end end end capybara-screenshot-1.0.14/spec/unit/saver_spec.rb 0000644 0001750 0001750 00000023544 12766551460 021172 0 ustar pravi pravi require 'spec_helper' describe Capybara::Screenshot::Saver do before(:all) do @original_drivers = Capybara::Screenshot.registered_drivers Capybara::Screenshot.registered_drivers[:default] = lambda {|driver, path| driver.render(path) } end after(:all) do Capybara::Screenshot.registered_drivers = @original_drivers end before do allow(Capybara::Screenshot).to receive(:capybara_root).and_return(capybara_root) Timecop.freeze(Time.local(2012, 6, 7, 8, 9, 10, 0)) end let(:capybara_root) { '/tmp' } let(:timestamp) { '2012-06-07-08-09-10.000' } let(:file_basename) { "screenshot_#{timestamp}" } let(:screenshot_path) { "#{capybara_root}/#{file_basename}.png" } let(:driver_mock) { double('Capybara driver').as_null_object } let(:page_mock) { double('Capybara session page', :body => 'body', :driver => driver_mock).as_null_object.tap do |m| allow(m).to receive(:current_path).and_return('/') end } let(:capybara_mock) { double(Capybara).as_null_object.tap do |m| allow(m).to receive(:current_driver).and_return(:default) end } let(:saver) { Capybara::Screenshot::Saver.new(capybara_mock, page_mock) } context 'html filename with Capybara Version 1' do before do stub_const("Capybara::VERSION", '1') end it 'has a default format of "screenshot_Y-M-D-H-M-S.ms.html"' do expect(capybara_mock).to receive(:save_page).with('body', File.join(capybara_root, "#{file_basename}.html")) saver.save end it 'uses name argument as prefix' do saver = Capybara::Screenshot::Saver.new(capybara_mock, page_mock, true, 'custom-prefix') expect(capybara_mock).to receive(:save_page).with('body', File.join(capybara_root, "custom-prefix_#{timestamp}.html")) saver.save end end context 'html filename with Capybara Version 2' do before do stub_const("Capybara::VERSION", '2') end it 'has a default format of "screenshot_Y-M-D-H-M-S.ms.html"' do expect(capybara_mock).to receive(:save_page).with(File.join(capybara_root, "#{file_basename}.html")) saver.save end it 'uses name argument as prefix' do saver = Capybara::Screenshot::Saver.new(capybara_mock, page_mock, true, 'custom-prefix') expect(capybara_mock).to receive(:save_page).with(File.join(capybara_root, "custom-prefix_#{timestamp}.html")) saver.save end end context 'screenshot image path' do it 'is in capybara root output' do expect(driver_mock).to receive(:render).with(/^#{capybara_root}\//) saver.save end it 'has a default filename format of "screenshot_Y-M-D-H-M-S.ms.png"' do expect(driver_mock).to receive(:render).with(/#{file_basename}\.png$/) saver.save end it "does not append timestamp if append_timestamp is false " do default_config = Capybara::Screenshot.append_timestamp Capybara::Screenshot.append_timestamp = false expect(driver_mock).to receive(:render).with(/screenshot.png$/) saver.save Capybara::Screenshot.append_timestamp = default_config end it 'uses filename prefix argument as basename prefix' do saver = Capybara::Screenshot::Saver.new(capybara_mock, page_mock, true, 'custom-prefix') expect(driver_mock).to receive(:render).with(/#{capybara_root}\/custom-prefix_#{timestamp}\.png$/) saver.save end end it 'does not save html if false passed as html argument' do saver = Capybara::Screenshot::Saver.new(capybara_mock, page_mock, false) expect(capybara_mock).to_not receive(:save_page) saver.save expect(saver).to_not be_html_saved end it 'does not save if current_path is empty' do allow(page_mock).to receive(:current_path).and_return(nil) expect(capybara_mock).to_not receive(:save_page) expect(driver_mock).to_not receive(:render) saver.save expect(saver).to_not be_screenshot_saved expect(saver).to_not be_html_saved end context 'when saving a screenshot fails' do it 'still restores the original value of Capybara.save_and_open_page_path' do Capybara::Screenshot.capybara_tmp_path = 'tmp/bananas' expect(capybara_mock).to receive(:save_page).and_raise expect { saver.save }.to raise_error(RuntimeError) if Capybara.respond_to?(:save_path) expect(Capybara.save_path).to eq('tmp/bananas') else expect(Capybara.save_and_open_page_path).to eq('tmp/bananas') end end end describe '#output_screenshot_path' do let(:saver) { Capybara::Screenshot::Saver.new(capybara_mock, page_mock) } before do allow(saver).to receive(:html_path) { 'page.html' } allow(saver).to receive(:screenshot_path) { 'screenshot.png' } end it 'outputs the path for the HTML screenshot' do allow(saver).to receive(:html_saved?).and_return(true) expect(saver).to receive(:output).with("HTML screenshot: page.html") saver.output_screenshot_path end it 'outputs the path for the Image screenshot' do allow(saver).to receive(:screenshot_saved?).and_return(true) expect(saver).to receive(:output).with("Image screenshot: screenshot.png") saver.output_screenshot_path end end describe "with selenium driver" do before do allow(capybara_mock).to receive(:current_driver).and_return(:selenium) end it 'saves via browser' do browser_mock = double('browser') expect(driver_mock).to receive(:browser).and_return(browser_mock) expect(browser_mock).to receive(:save_screenshot).with(screenshot_path) saver.save expect(saver).to be_screenshot_saved end end describe "with poltergeist driver" do before do allow(capybara_mock).to receive(:current_driver).and_return(:poltergeist) end it 'saves driver render with :full => true' do expect(driver_mock).to receive(:render).with(screenshot_path, {:full => true}) saver.save expect(saver).to be_screenshot_saved end end describe "with poltergeist_billy driver" do before do allow(capybara_mock).to receive(:current_driver).and_return(:poltergeist_billy) end it 'saves driver render with :full => true' do expect(driver_mock).to receive(:render).with(screenshot_path, {:full => true}) saver.save expect(saver).to be_screenshot_saved end end describe "with webkit driver" do before do allow(capybara_mock).to receive(:current_driver).and_return(:webkit) end context 'has render method' do before do allow(driver_mock).to receive(:respond_to?).with(:'save_screenshot').and_return(false) end it 'saves driver render' do expect(driver_mock).to receive(:render).with(screenshot_path) saver.save expect(saver).to be_screenshot_saved end end context 'has save_screenshot method' do let(:webkit_options){ {width: 800, height: 600} } before do allow(driver_mock).to receive(:respond_to?).with(:'save_screenshot').and_return(true) end it 'saves driver render' do expect(driver_mock).to receive(:save_screenshot).with(screenshot_path, {}) saver.save expect(saver).to be_screenshot_saved end it 'passes webkit_options to driver' do allow(Capybara::Screenshot).to receive(:webkit_options).and_return( webkit_options ) expect(driver_mock).to receive(:save_screenshot).with(screenshot_path, webkit_options) saver.save expect(saver).to be_screenshot_saved end end end describe "with webkit debug driver" do before do allow(capybara_mock).to receive(:current_driver).and_return(:webkit_debug) end context 'has render method' do before do allow(driver_mock).to receive(:respond_to?).with(:'save_screenshot').and_return(false) end it 'saves driver render' do expect(driver_mock).to receive(:render).with(screenshot_path) saver.save expect(saver).to be_screenshot_saved end end context 'has save_screenshot method' do let(:webkit_options){ {width: 800, height: 600} } before do allow(driver_mock).to receive(:respond_to?).with(:'save_screenshot').and_return(true) end it 'saves driver render' do expect(driver_mock).to receive(:save_screenshot).with(screenshot_path, {}) saver.save expect(saver).to be_screenshot_saved end it 'passes webkit_options to driver' do allow(Capybara::Screenshot).to receive(:webkit_options).and_return( webkit_options ) expect(driver_mock).to receive(:save_screenshot).with(screenshot_path, webkit_options) saver.save expect(saver).to be_screenshot_saved end end end describe "with unknown driver" do before do allow(capybara_mock).to receive(:current_driver).and_return(:unknown) allow(saver).to receive(:warn).and_return(nil) end it 'saves driver render' do expect(driver_mock).to receive(:render).with(screenshot_path) saver.save expect(saver).to be_screenshot_saved end it 'outputs warning about unknown results' do # Not pure mock testing expect(saver).to receive(:warn).with(/screenshot driver for 'unknown'.*unknown results/).and_return(nil) saver.save expect(saver).to be_screenshot_saved end describe "with rack_test driver" do before do allow(capybara_mock).to receive(:current_driver).and_return(:rack_test) end it 'indicates that a screenshot could not be saved' do saver.save expect(saver).to_not be_screenshot_saved end end describe "with mechanize driver" do before do allow(capybara_mock).to receive(:current_driver).and_return(:mechanize) end it 'indicates that a screenshot could not be saved' do saver.save expect(saver).to_not be_screenshot_saved end end end end capybara-screenshot-1.0.14/spec/unit/base_reporter_spec.rb 0000644 0001750 0001750 00000001303 12766551460 022673 0 ustar pravi pravi require 'spec_helper' describe Capybara::Screenshot::RSpec::BaseReporter do describe '#enhance_with_screenshot' do it 'makes the original method available under an alias and replaces it with the enhanced method' do reporter_module = Module.new do extend Capybara::Screenshot::RSpec::BaseReporter enhance_with_screenshot :foo def foo_with_screenshot [foo_without_screenshot, :enhanced] end end klass = Class.new do def foo :original end end expect(klass.new.foo).to eql(:original) klass.send :include, reporter_module expect(klass.new.foo).to eql([:original, :enhanced]) end end end capybara-screenshot-1.0.14/spec/unit/capybara-screenshot_spec.rb 0000644 0001750 0001750 00000007622 12766551460 024006 0 ustar pravi pravi require 'spec_helper' describe Capybara::Screenshot do describe '.register_driver' do before(:all) do @original_drivers = Capybara::Screenshot.registered_drivers.dup end after(:all) do Capybara::Screenshot.registered_drivers = @original_drivers end it 'stores driver with block' do block = lambda {} Capybara::Screenshot.register_driver :foo, &block expect(Capybara::Screenshot.registered_drivers[:foo]).to eql(block) end end describe '.register_filename_prefix_formatter' do before(:all) do @original_formatters = Capybara::Screenshot.filename_prefix_formatters.dup end after(:all) do Capybara::Screenshot.filename_prefix_formatters = @original_formatters end it 'stores test type with block' do block = lambda { |arg| } Capybara::Screenshot.register_filename_prefix_formatter :foo, &block expect(Capybara::Screenshot.filename_prefix_formatters[:foo]).to eql(block) end describe '.filename_prefix_for' do it 'returns "configured formatter" for specified formatter' do Capybara::Screenshot.register_filename_prefix_formatter(:foo) { |arg| 'custom_path' } expect(Capybara::Screenshot.filename_prefix_for(:foo, double('test'))).to eql('custom_path') end end end describe '.filename_prefix_for' do it 'returns "screenshot" for undefined formatter' do expect(Capybara::Screenshot.filename_prefix_for(:foo, double('test'))).to eql('screenshot') end end describe '.append_screenshot_path' do it 'prints a deprecation message and delegates to RSpec.add_link_to_screenshot_for_failed_examples' do begin original_stderr = $stderr $stderr = StringIO.new expect { Capybara::Screenshot.append_screenshot_path = false }.to change { Capybara::Screenshot::RSpec.add_link_to_screenshot_for_failed_examples }.from(true).to(false) expect($stderr.string).to include("append_screenshot_path is deprecated") ensure $stderr = original_stderr end end end describe '.new_saver' do it 'passes through to get a new Saver if the user has not configured s3' do saver_double = double('saver') args = double('args') expect(Capybara::Screenshot::Saver).to receive(:new).with(args).and_return(saver_double) expect(Capybara::Screenshot.new_saver(args)).to eq(saver_double) end it 'wraps the returned saver in an S3 saver if it has been configured' do require 'capybara-screenshot/s3_saver' saver_double = double('saver') args = double('args') s3_saver_double = double('s3_saver') s3_configuration = { hello: 'world' } Capybara::Screenshot.s3_configuration = s3_configuration expect(Capybara::Screenshot::Saver).to receive(:new).with(args).and_return(saver_double) expect(Capybara::Screenshot::S3Saver).to receive(:new_with_configuration).with(saver_double, s3_configuration).and_return(s3_saver_double) expect(Capybara::Screenshot.new_saver(args)).to eq(s3_saver_double) end end describe '#prune' do before do Capybara::Screenshot.reset_prune_history end it 'prunes once by default' do expect(Capybara::Screenshot::Pruner).to receive(:new).and_call_original.once 3.times { Capybara::Screenshot.prune } end it 'prunes every time if option force: true' do expect(Capybara::Screenshot::Pruner).to receive(:new).and_call_original.exactly(3).times 3.times { Capybara::Screenshot.prune(force: true) } end context 'prune strategy' do let(:prune_strategy) { { keep: 100 } } before do Capybara::Screenshot.prune_strategy = prune_strategy end it 'is passed to initializer' do expect(Capybara::Screenshot::Pruner).to receive(:new).with(prune_strategy).and_call_original Capybara::Screenshot.prune end end end end capybara-screenshot-1.0.14/spec/unit/rspec_reporters/ 0000755 0001750 0001750 00000000000 12766551460 021724 5 ustar pravi pravi capybara-screenshot-1.0.14/spec/unit/rspec_reporters/html_embed_reporter_spec.rb 0000644 0001750 0001750 00000001277 12766551460 027314 0 ustar pravi pravi require 'spec_helper' describe Capybara::Screenshot::RSpec::HtmlEmbedReporter do include_context 'html reporter' context 'when an image was saved' do before do set_example double("example", metadata: {screenshot: {image: "path/to/image"}}) end it 'embeds the image base64 encoded into the content' do expect(File).to receive(:binread).with("path/to/image").and_return("image data") encoded_image_data = Base64.encode64('image data') content_without_styles = @reporter.extra_failure_content(nil).gsub(/ ?style='.*?' ?/, "") expect(content_without_styles).to eql("original contentSaved files: HTML page
}) end end context 'when a html file and an image were saved' do before do set_example double("example", metadata: {screenshot: {html: "path/to/html", image: "path/to/an image"}}) end it 'appends links to both files to the original content' do content_without_styles = @reporter.extra_failure_content(nil).gsub(/ ?style=".*?" ?/, "") expect(content_without_styles).to eql(%{original contentSaved files: HTML pageScreenshot
}) end end end capybara-screenshot-1.0.14/spec/unit/rspec_reporters/textmate_link_reporter_spec.rb 0000644 0001750 0001750 00000003747 12766551460 030070 0 ustar pravi pravi require 'spec_helper' describe Capybara::Screenshot::RSpec::TextMateLinkReporter do include_context 'html reporter' context 'when a html file was saved' do before do set_example double("example", metadata: {screenshot: {html: "path/to/a html file"}}) end it 'appends a link to the html to the original content' do content_without_styles = @reporter.extra_failure_content(nil).gsub(/ ?style=".*?"/, "") # Single quotes are handled differently by CGI.escape_html in Ruby 1.9 / Ruby 2, so to be # compatible with both versions we can't hard code the final escaped string. expected_onclick_handler = CGI.escape_html("TextMate.system('open file://path/to/a\\%20html\\%20file'); return false;") expect(content_without_styles).to eql(%{original content} + %{Saved files: HTML page
} ) end end context 'when a html file and an image were saved' do before do set_example double("example", metadata: {screenshot: {html: "path/to/html", image: "path/to/an image"}}) end it 'appends links to both files to the original content' do content_without_styles = @reporter.extra_failure_content(nil).gsub(/ ?style=".*?"/, "") # Single quotes are handled differently by CGI.escape_html in Ruby 1.9 / Ruby 2, so to be # compatible with both versions we can't hard code the final escaped string. expected_onclick_handler_1 = CGI.escape_html("TextMate.system('open file://path/to/html'); return false;") expected_onclick_handler_2 = CGI.escape_html("TextMate.system('open file://path/to/an\\%20image'); return false;") expect(content_without_styles).to eql(%{original content} + %{Saved files: HTML page} + %{Screenshot
} ) end end end capybara-screenshot-1.0.14/spec/unit/capybara_spec.rb 0000644 0001750 0001750 00000002742 12766551460 021631 0 ustar pravi pravi require 'capybara-screenshot' require 'capybara/dsl' describe Capybara do it 'adds screen shot methods to the Capybara module' do expect(::Capybara).to respond_to(:screenshot_and_save_page) expect(::Capybara).to respond_to(:screenshot_and_open_image) end context 'request type example', :type => :request do it 'has access to screen shot instance methods' do expect(subject).to respond_to(:screenshot_and_save_page) expect(subject).to respond_to(:screenshot_and_open_image) end end describe 'using_session' do include Capybara::DSL it 'saves the name of the final session' do expect(Capybara::Screenshot).to receive(:final_session_name=).with(:different_session) expect { using_session :different_session do expect(0).to eq 1 end }.to raise_exception ::RSpec::Expectations::ExpectationNotMetError end end end describe 'final_session_name' do subject { Capybara::Screenshot.clone } describe 'when the final session name has been set' do before do subject.final_session_name = 'my-failing-session' end it 'returns the name' do expect(subject.final_session_name).to eq 'my-failing-session' end end describe 'when the final session name has not been set' do it 'returns the current session name' do allow(Capybara).to receive(:session_name).and_return('my-current-session') expect(subject.final_session_name).to eq 'my-current-session' end end end capybara-screenshot-1.0.14/spec/unit/pruner_spec.rb 0000644 0001750 0001750 00000005602 12766551460 021360 0 ustar pravi pravi require 'spec_helper' describe Capybara::Screenshot::Pruner do describe '#initialize' do let(:pruner) { Capybara::Screenshot::Pruner.new(strategy) } context 'accepts generic strategies:' do [:keep_all, :keep_last_run].each do |strategy_sym| let(:strategy) { strategy_sym } it ":#{strategy_sym}" do expect(pruner.strategy).to eq(strategy) end end end context 'keep:int' do let(:strategy) { { keep: 50 } } it 'is a suitable strategy' do expect(pruner.strategy).to eq(strategy) end end context 'invalid strategy' do context 'symbol' do let(:strategy) { :invalid_strategy } it 'raises an error' do expect { pruner }.to raise_error(/Invalid prune strategy/) end end context 'keep:sym' do let(:strategy) { { keep: :symbol } } it 'raises an error' do expect { pruner }.to raise_error(/must be a Integer/) end end end end describe '#prune_old_screenshots' do let(:capybara_root) { Capybara::Screenshot.capybara_root } let(:remaining_files) { Dir.glob(File.expand_path('*', capybara_root)).sort } let(:files_created) { [] } let(:files_count) { 8 } let(:pruner) { Capybara::Screenshot::Pruner.new(strategy) } before do allow(Capybara::Screenshot).to receive(:capybara_root).and_return(Dir.mktmpdir.to_s) files_count.times do |i| files_created << FileUtils.touch("#{capybara_root}/#{i}.#{i % 2 == 0 ? 'png' : 'html'}").first.tap do |file_name| File.utime(Time.now, Time.now - files_count + i, file_name) end end pruner.prune_old_screenshots end after do FileUtils.rm_rf capybara_root end context 'with :keep_all strategy' do let(:strategy) { :keep_all } it 'should not remove screens' do expect(remaining_files).to eq(files_created) end end context 'with :keep_last_run strategy' do let(:strategy) { :keep_last_run } it 'should remove all screens' do expect(remaining_files).to be_empty end context 'when dir is missing' do before { FileUtils.rm_rf(Capybara::Screenshot.capybara_root) } it 'should not raise error' do expect { pruner.prune_old_screenshots }.to_not raise_error end end end context 'with :keep strategy' do let(:keep_count) { 3 } let(:strategy) { { keep: keep_count } } it 'should keep specified number of screens' do expect(remaining_files).to eq(files_created.last(keep_count)) end context 'when dir is missing' do before { FileUtils.rm_rf(Capybara::Screenshot.capybara_root) } it 'should not raise error when dir is missing' do expect { pruner.prune_old_screenshots }.to_not raise_error end end end end end capybara-screenshot-1.0.14/spec/cucumber/ 0000755 0001750 0001750 00000000000 12766551460 017331 5 ustar pravi pravi capybara-screenshot-1.0.14/spec/cucumber/step_definitions/ 0000755 0001750 0001750 00000000000 12766551460 022677 5 ustar pravi pravi capybara-screenshot-1.0.14/spec/cucumber/step_definitions/step_definitions.rb 0000644 0001750 0001750 00000000630 12766551460 026571 0 ustar pravi pravi When(/^I click on a missing link$/) do click_on "you'll never find me" end When(/^I click on a missing link on a different page in a different session$/) do using_session :different_session do visit '/different_page' click_on "you'll never find me" end end When(/^I visit "([^"]*)"$/) do |path| visit path end Then(/^I trigger an unhandled exception/) do raise "you can't handle me" end capybara-screenshot-1.0.14/spec/cucumber/cucumber_spec.rb 0000644 0001750 0001750 00000005472 12766551460 022505 0 ustar pravi pravi require "spec_helper" describe "Using Capybara::Screenshot with Cucumber" do include CommonSetup before do setup_aruba end let(:cmd) { 'cucumber' } def run_failing_case(failure_message, code) run_case code expect(last_command_started.output).to match(failure_message) end def run_case(code, options = {}) write_file('features/support/env.rb', <<-RUBY) #{ensure_load_paths_valid} require 'cucumber/support/env.rb' #{setup_test_app} RUBY write_file('features/step_definitions/step_definitions.rb', <<-RUBY) %w(lib spec).each do |include_folder| $LOAD_PATH.unshift(File.join('#{gem_root}', include_folder)) end require 'cucumber/step_definitions/step_definitions.rb' RUBY write_file('features/cucumber.feature', code) run_simple_with_retry cmd, false expect(last_command_started.output).to_not match(/failed|failure/i) if options[:assert_all_passed] end it 'saves a screenshot on failure' do run_failing_case %q{Unable to find link or button "you'll never find me"}, <<-CUCUMBER Feature: Failure Scenario: Failure Given I visit "/" And I click on a missing link CUCUMBER expect('tmp/my_screenshot.html').to have_file_content('This is the root page') end it 'saves a screenshot on an error' do run_failing_case %q{you can't handle me}, <<-CUCUMBER Feature: Failure Scenario: Failure Given I visit "/" And I trigger an unhandled exception CUCUMBER expect('tmp/my_screenshot.html').to have_file_content('This is the root page') end it 'saves a screenshot for the correct session for failures using_session' do run_failing_case(%q{Unable to find link or button "you'll never find me"}, <<-CUCUMBER) Feature: Failure Scenario: Failure in different session Given I visit "/" And I click on a missing link on a different page in a different session CUCUMBER expect('tmp/my_screenshot.html').to have_file_content('This is a different page') end context 'pruning' do before do create_screenshot_for_pruning configure_prune_strategy :last_run end it 'on failure it prunes previous screenshots when strategy is set' do run_failing_case %q{Unable to find link or button "you'll never find me"}, <<-CUCUMBER Feature: Prune Scenario: Screenshots are pruned if strategy is set Given I visit "/" And I click on a missing link CUCUMBER assert_screenshot_pruned end it 'on success it never prunes' do run_case <<-CUCUMBER, assert_all_passed: true Feature: Prune Scenario: Screenshots are pruned if strategy is set Given I visit "/" CUCUMBER assert_screenshot_not_pruned end end end capybara-screenshot-1.0.14/spec/cucumber/support/ 0000755 0001750 0001750 00000000000 12766551460 021045 5 ustar pravi pravi capybara-screenshot-1.0.14/spec/cucumber/support/env.rb 0000644 0001750 0001750 00000000625 12766551460 022165 0 ustar pravi pravi require 'capybara/cucumber' require 'capybara-screenshot' require 'capybara-screenshot/cucumber' require 'aruba/cucumber' require 'aruba/config/jruby' Capybara::Screenshot.register_filename_prefix_formatter(:cucumber) do |fault| 'my_screenshot' end Before do @aruba_timeout_seconds = 60 end if RUBY_PLATFORM == 'java' After('@restore-capybara-default-session') do Capybara.session_name = nil end