capybara-screenshot 1.0.13 → 1.0.26

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +11 -12
  3. data/Appraisals +14 -16
  4. data/CHANGELOG.md +69 -0
  5. data/Gemfile +4 -3
  6. data/README.md +96 -30
  7. data/capybara-screenshot.gemspec +12 -5
  8. data/gemfiles/cucumber.1.3.gemfile +12 -0
  9. data/gemfiles/cucumber.2.4.gemfile +12 -0
  10. data/gemfiles/latest.gemfile +5 -2
  11. data/gemfiles/rspec.3.0.gemfile +5 -2
  12. data/gemfiles/rspec.3.3.gemfile +12 -0
  13. data/gemfiles/spinach.0.8.gemfile +12 -0
  14. data/lib/capybara-screenshot/callbacks.rb +44 -0
  15. data/lib/capybara-screenshot/capybara.rb +26 -10
  16. data/lib/capybara-screenshot/cucumber.rb +12 -5
  17. data/lib/capybara-screenshot/minitest.rb +1 -1
  18. data/lib/capybara-screenshot/pruner.rb +5 -1
  19. data/lib/capybara-screenshot/rspec/base_reporter.rb +1 -2
  20. data/lib/capybara-screenshot/rspec/html_embed_reporter.rb +14 -3
  21. data/lib/capybara-screenshot/rspec/html_link_reporter.rb +1 -1
  22. data/lib/capybara-screenshot/rspec/text_reporter.rb +2 -2
  23. data/lib/capybara-screenshot/rspec.rb +25 -3
  24. data/lib/capybara-screenshot/s3_saver.rb +39 -11
  25. data/lib/capybara-screenshot/saver.rb +60 -15
  26. data/lib/capybara-screenshot/version.rb +1 -1
  27. data/lib/capybara-screenshot.rb +38 -3
  28. data/spec/cucumber/cucumber_spec.rb +4 -8
  29. data/spec/feature/minitest_spec.rb +2 -6
  30. data/spec/feature/testunit_spec.rb +3 -7
  31. data/spec/rspec/rspec_spec.rb +36 -8
  32. data/spec/spinach/spinach_spec.rb +4 -8
  33. data/spec/support/aruba.rb +0 -1
  34. data/spec/support/common_setup.rb +13 -5
  35. data/spec/unit/capybara-screenshot_spec.rb +2 -1
  36. data/spec/unit/capybara_spec.rb +13 -0
  37. data/spec/unit/pruner_spec.rb +2 -2
  38. data/spec/unit/rspec_reporters/html_embed_reporter_spec.rb +13 -0
  39. data/spec/unit/rspec_reporters/text_reporter_spec.rb +6 -6
  40. data/spec/unit/s3_saver_spec.rb +196 -14
  41. data/spec/unit/saver_spec.rb +132 -16
  42. metadata +19 -17
  43. data/gemfiles/cucumber.1.2.gemfile +0 -9
  44. data/gemfiles/cucumber.1.3.0.gemfile +0 -9
  45. data/gemfiles/rspec.2.14.gemfile +0 -9
  46. data/gemfiles/rspec.2.99.gemfile +0 -9
  47. data/gemfiles/spinach.0.7.gemfile +0 -9
  48. data/gemfiles/spinach.0.8.0.gemfile +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a2c4277a621182718153bba9b9bae60234ddfd17
4
- data.tar.gz: 6af401d8ae56c2849916c0145f0f0ce928cc92ac
2
+ SHA256:
3
+ metadata.gz: b73d3b8338a3c2f426d7835f4396565c0bfe28b939f610337c331099f93f52b5
4
+ data.tar.gz: c5ec9f343c703e5ac2700b84dcde63a094c3609787ea7b1cfbbd1f470a5b0ce4
5
5
  SHA512:
6
- metadata.gz: 0696563bcf86da3827f2d8392f2555c56e2f830b0ff6c76bad72d5ac2c1b8ddb37730fee26c51924dbd0f4edc4cf8054949adac7506bf01b45cd955fc200c676
7
- data.tar.gz: 55ebe3341f404a7c57d5265ca6478127e3b3b4f277a0f2d130f87d5724b0d38d6d441fed4488ab13d0194826432ad0491f6a52b754dc19e578f6f33f61be1a83
6
+ metadata.gz: 4cd11454a82290ef985a5341e0dad1eaea6296ca5b6ea1f17522a5f8f43b6c68dd71cfd17426c8204fd352488b6ea876d2e8493b2ec0ce2e575590e13302b456
7
+ data.tar.gz: d17d96491ebc960f4fa47eec58b9dd60610c4a7839e878d8d40c3003cb054e891fc38e958ba42dbcf7ded095385fbb725cdd9e33e368fec51cd89358653c3576
data/.travis.yml CHANGED
@@ -1,18 +1,17 @@
1
1
  language: ruby
2
- script: "rake travis:ci"
2
+ script: "bundle exec rake travis:ci"
3
3
  rvm:
4
- - 1.9.3
5
4
  - 2.0.0
6
- - 2.1.2
7
- - 2.2.1
8
- - jruby-19mode
9
- - jruby-1.7.13
5
+ - 2.1.10
6
+ - 2.2.10
7
+ - 2.3.8
8
+ - 2.4.9
9
+ - 2.5.7
10
+ - 2.6.5
10
11
  gemfile:
11
- - gemfiles/cucumber.1.2.gemfile
12
- - gemfiles/cucumber.1.3.0.gemfile
12
+ - gemfiles/cucumber.1.3.gemfile
13
+ - gemfiles/cucumber.2.4.gemfile
13
14
  - gemfiles/latest.gemfile
14
- - gemfiles/rspec.2.14.gemfile
15
- - gemfiles/rspec.2.99.gemfile
16
15
  - gemfiles/rspec.3.0.gemfile
17
- - gemfiles/spinach.0.7.gemfile
18
- - gemfiles/spinach.0.8.0.gemfile
16
+ - gemfiles/rspec.3.3.gemfile
17
+ - gemfiles/spinach.0.8.gemfile
data/Appraisals CHANGED
@@ -1,31 +1,29 @@
1
- appraise "rspec.2.14" do
2
- gem "rspec", "2.14"
3
- end
4
-
5
- appraise "rspec.2.99" do
6
- gem "rspec", "2.99"
7
- end
8
-
9
1
  appraise "rspec.3.0" do
10
2
  gem "rspec", "3.0"
3
+ gem 'nokogiri', '< 1.7.0', platform: :ruby_20
11
4
  end
12
5
 
13
- appraise "cucumber.1.2" do
14
- gem "cucumber", "1.2"
6
+ appraise "rspec.3.3" do
7
+ gem "rspec", "~> 3.3.0"
8
+ gem 'nokogiri', '< 1.7.0', platform: :ruby_20
15
9
  end
16
10
 
17
- appraise "cucumber.1.3.0" do
18
- gem "cucumber", "1.3.0"
11
+ appraise "cucumber.1.3" do
12
+ gem "cucumber", "~>1.3.0"
13
+ gem 'nokogiri', '< 1.7.0', platform: :ruby_20
19
14
  end
20
15
 
21
- appraise "spinach.0.7" do
22
- gem "spinach", "0.7"
16
+ appraise "cucumber.2.4" do
17
+ gem "cucumber", "~>2.4.0"
18
+ gem 'nokogiri', '< 1.7.0', platform: :ruby_20
23
19
  end
24
20
 
25
- appraise "spinach.0.8.0" do
26
- gem "spinach", "0.8.0"
21
+ appraise "spinach.0.8" do
22
+ gem "spinach", "~>0.8.0"
23
+ gem 'nokogiri', '< 1.7.0', platform: :ruby_20
27
24
  end
28
25
 
29
26
  appraise "latest" do
30
27
  # will get latest versions of all gems
28
+ gem 'nokogiri', '< 1.7.0', platform: :ruby_20
31
29
  end
data/CHANGELOG.md CHANGED
@@ -1,3 +1,72 @@
1
+ 21 Dec 2021 - 1.0.25 -> 1.0.26
2
+
3
+ * [Take screenshots of current window (when using multiple windows)](https://github.com/mattheworiordan/capybara-screenshot/pull/287)
4
+ * [Fix embedding screenshots into cucumber HTML reports](https://github.com/mattheworiordan/capybara-screenshot/pull/288)
5
+
6
+ 4 Oct 2020 - 1.0.24 -> 1.0.25
7
+
8
+ * [Fix Cucumber 5 deprecation warnings](https://github.com/mattheworiordan/capybara-screenshot/pull/274)
9
+ * [Add support for Cuprite driver](https://github.com/mattheworiordan/capybara-screenshot/pull/270)
10
+ * [Rails system spec compatibility](https://github.com/mattheworiordan/capybara-screenshot/pull/264)
11
+
12
+ 24 Nov 2019 - 1.0.23 -> 1.0.24
13
+
14
+ * [Support Apparition driver](https://github.com/mattheworiordan/capybara-screenshot/commit/273317b241d1d1d8600b32fad998742894424f3b)
15
+
16
+ 10 Jun 2019 - 1.0.22 -> 1.0.23
17
+
18
+ * [Support for Capybara sessions implicitly](https://github.com/mattheworiordan/capybara-screenshot/pull/255). Thanks https://github.com/TylerRick
19
+ * [Support for S3 bucket host configuration](https://github.com/mattheworiordan/capybara-screenshot/pull/252). Thanks https://github.com/machty
20
+
21
+ 21 Oct 2018 - 1.0.21 -> 1.0.22
22
+
23
+ * [Support for S3 URL in HTML screenshots](https://github.com/mattheworiordan/capybara-screenshot/pull/239)
24
+ * [Fix for partial Rails environments](https://github.com/mattheworiordan/capybara-screenshot/pull/238)
25
+ * [Capybara 3 support in CI](https://github.com/mattheworiordan/capybara-screenshot/pull/236)
26
+
27
+ 03 May 2018 - 1.0.20 -> 1.0.21
28
+
29
+ * [Bug fix: Fix Ruby version compares in Gemspec](https://github.com/mattheworiordan/capybara-screenshot/pull/231)
30
+
31
+ 03 May 2018 - 1.0.19 -> 1.0.20
32
+
33
+ * [Bug fix: Only take screenshots for feature tests](https://github.com/mattheworiordan/capybara-screenshot/pull/223)
34
+
35
+ 10 April 2018 - 1.0.18 -> 1.0.19
36
+
37
+ * Big thanks for [Geremia Taglialatela](https://github.com/tagliala) for [padding Capybara 3 support and fixing the builds](https://github.com/mattheworiordan/capybara-screenshot/pull/230)
38
+
39
+ 2 November 2017 - 1.0.17 -> 1.0.18
40
+
41
+ * [RSpec 3.3 support](https://github.com/mattheworiordan/capybara-screenshot/pull/213)
42
+ * [Add support for selenium_chrome and selenium_chrome_headless](https://github.com/mattheworiordan/capybara-screenshot/pull/219)
43
+ * [Less dependencies for S3 uploads](https://github.com/mattheworiordan/capybara-screenshot/pull/218)
44
+
45
+ Special thanks to the fine contribution from [Matt Bricston](https://github.com/mattbrictson)
46
+
47
+ 17 July 2017 - 1.0.16 -> 1.0.17
48
+
49
+ * [Better handling of `page.current_path` exceptions for Spinach](https://github.com/mattheworiordan/capybara-screenshot/pull/208)
50
+
51
+ 12 July 2017 - 1.0.15 -> 1.0.16
52
+
53
+ * [Support s3 key name prefixes](https://github.com/mattheworiordan/capybara-screenshot/pull/202)
54
+
55
+ 12 July 2017 - 1.0.14 -> 1.0.15
56
+
57
+ * [SVG badges added](https://github.com/mattheworiordan/capybara-screenshot/pull/207)
58
+ * [Ensure the reporter module is not loaded multiple times](https://github.com/mattheworiordan/capybara-screenshot/pull/205)
59
+ * [S3 object config option](https://github.com/mattheworiordan/capybara-screenshot/pull/204)
60
+ * [Saver can use injected page](https://github.com/mattheworiordan/capybara-screenshot/pull/181)
61
+ * [After* callbacks](https://github.com/mattheworiordan/capybara-screenshot/pull/171)
62
+
63
+ 15 Sep 2016 - 1.0.13 -> 1.0.14
64
+
65
+ * 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.
66
+ * Fixed an inconsistency in the use of `save_and_open_page_path`
67
+ * Improved debugging of Aruba tests so that contributors can easily understand why their builds break
68
+ * Path fixes thanks to [Ryan McGarvey](https://github.com/ryanmcgarvey)
69
+
1
70
  23 May 2016 - 1.0.12 -> 1.0.13
2
71
 
3
72
  * Fixes [mkmf bug 162](https://github.com/mattheworiordan/capybara-screenshot/issues/162) and [mkmf bug 174](https://github.com/mattheworiordan/capybara-screenshot/issues/174)
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source "http://rubygems.org"
3
3
  # Specify your gem's dependencies in capybara-screenshot.gemspec
4
4
  gemspec
5
5
 
6
- gem 'rake'
7
- gem 'appraisal'
8
- gem 'aruba', '~> 0.14.0'
6
+ gem 'rack', '~> 1.0'
7
+ gem 'rake', '~> 13.0'
8
+ gem 'appraisal', '~> 2.0'
9
+ gem 'aruba', '~> 0.14.0'
data/README.md CHANGED
@@ -1,30 +1,31 @@
1
1
  capybara-screenshot gem
2
2
  =======================
3
3
 
4
- [![Build Status](https://travis-ci.org/mattheworiordan/capybara-screenshot.png)](https://travis-ci.org/mattheworiordan/capybara-screenshot)
5
- [![Code Climate](https://d3s6mut3hikguw.cloudfront.net/github/mattheworiordan/capybara-screenshot.png)](https://codeclimate.com/github/mattheworiordan/capybara-screenshot)
4
+ [![Build Status](https://travis-ci.org/mattheworiordan/capybara-screenshot.svg)](https://travis-ci.org/mattheworiordan/capybara-screenshot)
5
+ [![Code Climate](https://d3s6mut3hikguw.cloudfront.net/github/mattheworiordan/capybara-screenshot.svg)](https://codeclimate.com/github/mattheworiordan/capybara-screenshot)
6
6
  [![Gem Version](https://badge.fury.io/rb/capybara-screenshot.svg)](http://badge.fury.io/rb/capybara-screenshot)
7
7
 
8
- #### Capture a screen shot for every test failure automatically!
8
+ #### Capture a screenshot for every test failure automatically!
9
9
 
10
- `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`.
10
+ `capybara-screenshot` used with [Capybara](https://github.com/jnicklas/capybara) alongside [Cucumber](http://cukes.info/), [Rspec](https://www.relishapp.com/rspec) or [Minitest](https://github.com/seattlerb/minitest), will capture a screenshot for each failure in your test suite. Associated screenshot and HTML file
11
+ of the failed page (when using [capybara-webkit](https://github.com/thoughtbot/capybara-webkit), [Selenium](http://seleniumhq.org/), [poltergeist](https://github.com/jonleighton/poltergeist) or [cuprite](https://github.com/machinio/cuprite)) is saved into `$APPLICATION_ROOT/tmp/capybara`.
11
12
 
12
- 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.
13
+ Available screenshots for each test failure is incredibly helpful for diagnosing problems quickly in your failing steps. You have the ability to view screenshots (when applicable) and source code at the time of each failure.
13
14
 
14
- _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)_
15
+ _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)_
15
16
 
16
17
  Installation
17
18
  -----
18
19
 
19
20
  ### Step 1: install the gem
20
21
 
21
- Using Bundler, add the following to your Gemfile
22
+ Using Bundler, add the following to your Gemfile:
22
23
 
23
24
  ```ruby
24
25
  gem 'capybara-screenshot', :group => :test
25
26
  ```
26
27
 
27
- or install manually using Ruby Gems:
28
+ Alternatively, manually install using Ruby Gems:
28
29
 
29
30
  ```
30
31
  gem install capybara-screenshot
@@ -76,7 +77,7 @@ Typically in 'test/test_helper.rb', please add:
76
77
  require 'capybara-screenshot/testunit'
77
78
  ```
78
79
 
79
- By default, screenshots will be captured for `Test::Unit` tests in the path 'test/integration'. You can add additional paths as:
80
+ By default, screenshots will be captured for `Test::Unit` tests in the path 'test/integration'. You can add additional paths:
80
81
 
81
82
  ```ruby
82
83
  Capybara::Screenshot.testunit_paths << 'test/feature'
@@ -86,33 +87,50 @@ Capybara::Screenshot.testunit_paths << 'test/feature'
86
87
  Manual screenshots
87
88
  ----
88
89
 
89
- If you require more control, you can generate the screenshot on demand rather than on failure. This is useful
90
- if the failure occurs at a point where the screen shot is not as useful for debugging a rendering problem. This
91
- can be more useful if you disable the auto-generate on failure feature with the following config
90
+ If you require more control, screenshots can be generated on demand rather than on failure. This is useful
91
+ when screenshots produced at the time of failure are not as useful for debugging a rendering problem.
92
+ Differentiating between manual and failure screenshots can be improved by disabling the auto-generate on
93
+ failure feature:
92
94
 
93
95
  ```ruby
94
96
  Capybara::Screenshot.autosave_on_failure = false
95
97
  ```
96
98
 
97
- Anywhere the Capybara DSL methods (visit, click etc.) are available so too are the screenshot methods.
99
+ Anywhere the Capybara DSL methods (visit, click etc.) are available so too are the screenshot methods:
98
100
 
99
101
  ```ruby
100
102
  screenshot_and_save_page
101
103
  ```
102
104
 
103
- Or for screenshot only, which will automatically open the image.
105
+ Or for screenshot only, which will automatically open the image:
104
106
 
105
107
  ```ruby
106
108
  screenshot_and_open_image
107
109
  ```
108
110
 
109
- These are just calls on the main library methods.
111
+ These are just calls on the main library methods:
110
112
 
111
113
  ```ruby
112
114
  Capybara::Screenshot.screenshot_and_save_page
113
115
  Capybara::Screenshot.screenshot_and_open_image
114
116
  ```
115
117
 
118
+ Better looking HTML screenshots
119
+ -------------------------------
120
+
121
+ By the default, HTML screenshots will not look very good when opened in a browser. This happens because the browser can't correctly resolve relative paths like `<link href="/assets/...." />`, which stops CSS, images, etc... from being loaded. To get a nicer looking page, configure Capybara with:
122
+
123
+ ```ruby
124
+ Capybara.asset_host = 'http://localhost:3000'
125
+ ```
126
+
127
+ This will cause Capybara to add `<base>http://localhost:3000</base>` to the HTML file, which gives the browser enough information to resolve relative paths. Next, start a rails server in development mode, on port 3000, to respond to requests for assets:
128
+
129
+ ```bash
130
+ rails s -p 3000
131
+ ```
132
+
133
+ Now when you open the page, you should have something that looks much better. You can leave this setup in place and use the default HTML pages when you don't care about the presentation, or start the rails server when you need something better looking.
116
134
 
117
135
  Driver configuration
118
136
  --------------------
@@ -149,7 +167,7 @@ Custom screenshot filename
149
167
  --------------------------
150
168
 
151
169
  If you want to control the screenshot filename for a specific test library, to inject the test name into it for example,
152
- you can override how the basename is generated for the file like so
170
+ you can override how the basename is generated for the file:
153
171
 
154
172
  ```ruby
155
173
  Capybara::Screenshot.register_filename_prefix_formatter(:rspec) do |example|
@@ -157,7 +175,7 @@ Capybara::Screenshot.register_filename_prefix_formatter(:rspec) do |example|
157
175
  end
158
176
  ```
159
177
 
160
- By default capybara-screenshot will append a timestamp to the basename. If you want to disable this behavior set the following option:
178
+ By default capybara-screenshot will append a timestamp to the basename. If you want to disable this behavior, set the following option:
161
179
 
162
180
  ```ruby
163
181
  Capybara::Screenshot.append_timestamp = false
@@ -167,25 +185,25 @@ Capybara::Screenshot.append_timestamp = false
167
185
  Custom screenshot directory
168
186
  --------------------------
169
187
  By default, when running under Rails, Sinatra, and Padrino, screenshots are saved into `$APPLICATION_ROOT/tmp/capybara`. Otherwise, they're saved under `Dir.pwd`.
170
- If you want to customize the location, override the file path as:
188
+ If you want to customize the location, override the file path:
171
189
 
172
190
  ```ruby
173
- Capybara.save_and_open_page_path = "/file/path"
191
+ Capybara.save_path = "/file/path"
174
192
  ```
175
193
 
176
194
 
177
195
  Uploading screenshots to S3
178
196
  --------------------------
179
- You can configure capybara-screenshot to automatically save your screenshots to an AWS S3 bucket.
197
+ You can configure capybara-screenshot to automatically save your screenshots to an AWS S3 bucket.
180
198
 
181
- First, install the `aws-sdk` gem or add it to your Gemfile
199
+ First, install the `aws-sdk-s3` gem or add it to your Gemfile:
182
200
 
183
201
  ```ruby
184
- gem 'capybara-screenshot', :group => :test
185
- gem 'aws-sdk', :group => :test
202
+ gem 'aws-sdk-s3', group: :test
203
+ gem 'capybara-screenshot', group: :test
186
204
  ```
187
205
 
188
- Next, configure capybara-screenshot with your S3 credentials, the bucket to save to, and an optional region (default: `us-east-1`).
206
+ Next, configure capybara-screenshot with your S3 credentials, the bucket to save to, and an optional region (default: `us-east-1`):
189
207
 
190
208
  ```ruby
191
209
  Capybara::Screenshot.s3_configuration = {
@@ -194,14 +212,37 @@ Capybara::Screenshot.s3_configuration = {
194
212
  secret_access_key: "my_secret_access_key",
195
213
  region: "eu-central-1"
196
214
  },
197
- bucket_name: "my_screenshots"
215
+ bucket_name: "my_screenshots",
216
+ # Optionally: Specify the host used to access the uploaded screenshots
217
+ bucket_host: "my_screenshots.s3-eu-central-1.amazonaws.com",
218
+ }
219
+ ```
220
+
221
+ The access key used for S3 uploads need to have at least the `s3:PutObject` permission.
222
+
223
+ **Note**: If you do not provide the `bucket_host` configuration option, additionally the `s3:GetBucketLocation` permission is required on the bucket for uploads to succeed.
224
+
225
+ It is also possible to specify the object parameters such as acl.
226
+ Configure the capybara-screenshot with these options in this way:
227
+
228
+ ```ruby
229
+ Capybara::Screenshot.s3_object_configuration = {
230
+ acl: 'public-read'
198
231
  }
199
232
  ```
200
233
 
234
+ You may optionally specify a `:key_prefix` when generating the S3 keys, which can be used to create virtual [folders](http://docs.aws.amazon.com/AmazonS3/latest/UG/FolderOperations.html) in S3, e.g.:
235
+
236
+ ```ruby
237
+ Capybara::Screenshot.s3_configuration = {
238
+ ... # other config here
239
+ key_prefix: "some/folder/"
240
+ }
241
+ ```
201
242
 
202
243
  Pruning old screenshots automatically
203
244
  --------------------------
204
- 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:
245
+ 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:
205
246
 
206
247
  ```ruby
207
248
  # Keep only the screenshots generated from the last failing test suite
@@ -211,6 +252,30 @@ Capybara::Screenshot.prune_strategy = :keep_last_run
211
252
  Capybara::Screenshot.prune_strategy = { keep: 20 }
212
253
  ```
213
254
 
255
+ Callbacks
256
+ ---------
257
+
258
+ You can hook your own logic into callbacks after the html/screenshot has been saved:
259
+
260
+ ```ruby
261
+ # after Saver#save_html
262
+ Capybara::Screenshot.after_save_html do |path|
263
+ mail = Mail.new do
264
+ delivery_method :sendmail
265
+ from 'capybara-screenshot@example.com'
266
+ to 'dev@example.com'
267
+ subject 'Capybara Screenshot'
268
+ add_file File.read path
269
+ end
270
+ mail.delivery_method :sendmail
271
+ mail.deliver
272
+ end
273
+
274
+ # after Saver#save_screenshot
275
+ Capybara::Screenshot.after_save_screenshot do |path|
276
+ # ...
277
+ end
278
+ ```
214
279
 
215
280
  Information about screenshots in RSpec output
216
281
  ---------------------------------------------
@@ -254,7 +319,7 @@ Please raise an issue at [https://github.com/mattheworiordan/capybara-screenshot
254
319
 
255
320
  #### Contributions
256
321
 
257
- 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 "bundle exec rspec && bundle exec cucumber"` locally to test your changes against all versions of testing framework gems supported.
322
+ Contributions are welcome. Please fork this gem and then 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.
258
323
 
259
324
  #### Rubygems
260
325
 
@@ -265,11 +330,12 @@ About
265
330
 
266
331
  This gem was written by **Matthew O'Riordan**, with contributions from [many kind people](https://github.com/mattheworiordan/capybara-screenshot/network/members).
267
332
 
268
- - [http://mattheworiordan.com](http://mattheworiordan.com)
333
+ - [http://mattheworiordan.com](http://mattheworiordan.com), [Technical co-founder & CEO of Ably Realtime](https://ably.com/)
269
334
  - [@mattheworiordan](http://twitter.com/#!/mattheworiordan)
270
- - [Linked In](http://www.linkedin.com/in/lemon)
335
+ - [Linked In](http://www.linkedin.com/in/mattoriordan)
336
+
271
337
 
272
338
  License
273
339
  -------
274
340
 
275
- Copyright © 2014 Matthew O'Riordan, inc. It is free software, and may be redistributed under the terms specified in the LICENSE file.
341
+ Copyright © 2020 Matthew O'Riordan, inc. It is free software, and may be redistributed under the terms specified in the LICENSE file.
@@ -12,14 +12,21 @@ Gem::Specification.new do |s|
12
12
  s.summary = %q{Automatically create snapshots when Cucumber steps fail with Capybara and Rails}
13
13
  s.description = %q{When a Cucumber step fails, it is useful to create a screenshot image and HTML file of the current page}
14
14
  s.license = 'MIT'
15
+ s.metadata = {
16
+ "bug_tracker_uri" => "https://github.com/mattheworiordan/capybara-screenshot/issues",
17
+ "changelog_uri" => "https://github.com/mattheworiordan/capybara-screenshot/blob/master/CHANGELOG.md",
18
+ "documentation_uri" => "https://www.rubydoc.info/gems/capybara-screenshot/#{s.version}",
19
+ "source_code_uri" => "https://github.com/mattheworiordan/capybara-screenshot/tree/v#{s.version}",
20
+ }
15
21
 
16
- s.rubyforge_project = "capybara-screenshot"
17
-
18
- if RUBY_VERSION < "1.9"
22
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("1.9")
19
23
  s.add_dependency 'capybara', ['>= 1.0', '< 2']
20
- else
24
+ elsif Gem::Version.new(RUBY_VERSION) <= Gem::Version.new("2.2.2")
21
25
  s.add_dependency 'capybara', ['>= 1.0', '< 3']
26
+ else
27
+ s.add_dependency 'capybara', ['>= 1.0', '< 4']
22
28
  end
29
+
23
30
  s.add_dependency 'launchy'
24
31
 
25
32
  s.add_development_dependency 'rspec'
@@ -30,7 +37,7 @@ Gem::Specification.new do |s|
30
37
  s.add_development_dependency 'test-unit'
31
38
  s.add_development_dependency 'spinach'
32
39
  s.add_development_dependency 'minitest'
33
- s.add_development_dependency 'aws-sdk'
40
+ s.add_development_dependency 'aws-sdk-s3'
34
41
 
35
42
  s.files = `git ls-files`.split("\n")
36
43
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rack", "~> 1.0"
6
+ gem "rake", "~> 10.0"
7
+ gem "appraisal", "~> 2.0"
8
+ gem "aruba", "~> 0.14.0"
9
+ gem "cucumber", "~>1.3.0"
10
+ gem "nokogiri", "< 1.7.0", platform: :ruby_20
11
+
12
+ gemspec :path => "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rack", "~> 1.0"
6
+ gem "rake", "~> 10.0"
7
+ gem "appraisal", "~> 2.0"
8
+ gem "aruba", "~> 0.14.0"
9
+ gem "cucumber", "~>2.4.0"
10
+ gem "nokogiri", "< 1.7.0", platform: :ruby_20
11
+
12
+ gemspec :path => "../"
@@ -2,7 +2,10 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "rake"
6
- gem "appraisal"
5
+ gem "rack", "~> 1.0"
6
+ gem "rake", "~> 10.0"
7
+ gem "appraisal", "~> 2.0"
8
+ gem "aruba", "~> 0.14.0"
9
+ gem "nokogiri", "< 1.7.0", platform: :ruby_20
7
10
 
8
11
  gemspec :path => "../"
@@ -2,8 +2,11 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "rake"
6
- gem "appraisal"
5
+ gem "rack", "~> 1.0"
6
+ gem "rake", "~> 10.0"
7
+ gem "appraisal", "~> 2.0"
8
+ gem "aruba", "~> 0.14.0"
7
9
  gem "rspec", "3.0"
10
+ gem "nokogiri", "< 1.7.0", platform: :ruby_20
8
11
 
9
12
  gemspec :path => "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rack", "~> 1.0"
6
+ gem "rake", "~> 10.0"
7
+ gem "appraisal", "~> 2.0"
8
+ gem "aruba", "~> 0.14.0"
9
+ gem "rspec", "~> 3.3.0"
10
+ gem "nokogiri", "< 1.7.0", platform: :ruby_20
11
+
12
+ gemspec :path => "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rack", "~> 1.0"
6
+ gem "rake", "~> 10.0"
7
+ gem "appraisal", "~> 2.0"
8
+ gem "aruba", "~> 0.14.0"
9
+ gem "spinach", "~>0.8.0"
10
+ gem "nokogiri", "< 1.7.0", platform: :ruby_20
11
+
12
+ gemspec :path => "../"
@@ -0,0 +1,44 @@
1
+ module Capybara
2
+ module Screenshot
3
+ module Callbacks
4
+ class CallbackSet < Array
5
+ def call *args
6
+ each do |callback|
7
+ callback.call(*args)
8
+ end
9
+ end
10
+ end
11
+
12
+ module ClassMethods
13
+ def callbacks
14
+ @callbacks ||= {}
15
+ end
16
+
17
+ def define_callback name
18
+ callbacks[name] ||= CallbackSet.new
19
+
20
+ define_singleton_method name do |&block|
21
+ callbacks[name] << block
22
+ end
23
+ end
24
+
25
+ def run_callbacks name, *args
26
+ if cb_set = callbacks[name]
27
+ cb_set.call(*args)
28
+ end
29
+ end
30
+ end
31
+
32
+ module InstanceMethods
33
+ def run_callbacks name, *args
34
+ self.class.run_callbacks name, *args
35
+ end
36
+ end
37
+
38
+ def self.included receiver
39
+ receiver.extend ClassMethods
40
+ receiver.send :include, InstanceMethods
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,6 +1,20 @@
1
- require "capybara-screenshot"
2
-
3
1
  module Capybara
2
+ class << self
3
+ module ScreenshotOverrides
4
+ def using_session(name, &block)
5
+ original_session_name = Capybara.session_name
6
+ Capybara::Screenshot.final_session_name = name
7
+ super(name, &block)
8
+ Capybara::Screenshot.final_session_name = original_session_name
9
+ end
10
+
11
+ # No longer needed. Kept for backwards compatibility only.
12
+ alias_method :using_session_with_screenshot, :using_session
13
+ end
14
+
15
+ prepend ScreenshotOverrides
16
+ end
17
+
4
18
  module DSL
5
19
  # Adds class methods to Capybara module and gets mixed into
6
20
  # the current scope during Cucumber and RSpec tests
@@ -12,15 +26,17 @@ module Capybara
12
26
  def screenshot_and_open_image
13
27
  Capybara::Screenshot.screenshot_and_open_image
14
28
  end
29
+ end
15
30
 
16
- def using_session_with_screenshot(name,&blk)
17
- original_session_name = Capybara.session_name
18
- Capybara::Screenshot.final_session_name = name
19
- using_session_without_screenshot(name,&blk)
20
- Capybara::Screenshot.final_session_name = original_session_name
21
- end
31
+ module SessionScreenshotOverrides
32
+ def within_window(window_or_handle)
33
+ super
34
+ rescue Exception
35
+ Thread.current[:capybara_screenshot_offending_window] = window_or_handle
22
36
 
23
- alias_method :using_session_without_screenshot, :using_session
24
- alias_method :using_session, :using_session_with_screenshot
37
+ raise
38
+ end
25
39
  end
40
+
41
+ Session.prepend SessionScreenshotOverrides
26
42
  end