capybara-inline-screenshot 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6faf3f9276b69c6cbe55781c9ac60dbc3205a8bb
4
+ data.tar.gz: 83ce00c424fdde1ba80629cb17560f7063ab0af6
5
+ SHA512:
6
+ metadata.gz: cf047e94deee05c01ad29f65b81a88be5434a47323c73fb9574702f2f3a9190d438a352be5d880659fe079cf098ac8a89af87012165b187543bd586879384637
7
+ data.tar.gz: 6ae2b6f2a60480d39f101e7608d1d1ac61ac700ae148162522320d0bfe4551920327ca675a121d87b16e1d2c8f59aee5fe1711df206e3df4a4c147a107c7dfcb
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2015 Buildkite Pty Ltd
2
+
3
+ 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:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ 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.
@@ -0,0 +1,37 @@
1
+ # capybara-inline-screenshot
2
+
3
+ Extends [capybara-screenshot](https://github.com/mattheworiordan/capybara-screenshot) with inline image output.
4
+
5
+ If `CI` environment variable is not present it will output screenshots in base64 encoded [iTerm2 image format](http://iterm2.com/images.html), and if `CI` is present it will output in the [Terminal artifact:// format](http://buildkite.github.io/terminal/inline-images/).
6
+
7
+ In [iTerm2 (nightly)](http://iterm2.com/):
8
+
9
+ ![Screenshot of iTerm2](screenshots/iterm.png)
10
+
11
+ In [Buildkite](https://buildkite.com/):
12
+
13
+ ![Screenshot of Buildkite](screenshots/buildkite.png)
14
+
15
+ ## Usage
16
+
17
+ Add it to your Gemfile (after `capybara-screenshot`):
18
+
19
+ ```ruby
20
+ gem 'capybara-inline-screenshot'
21
+ ```
22
+
23
+ And replace your call to:
24
+
25
+ ```ruby
26
+ require 'capybara/screenshot/rspec'
27
+ ```
28
+
29
+ with:
30
+
31
+ ```ruby
32
+ require 'capybara-inline-screenshot/rspec'
33
+ ```
34
+
35
+ ## License
36
+
37
+ See the [LICENSE](LICENSE.md) file for license rights and limitations (MIT).
@@ -0,0 +1,38 @@
1
+ require 'base64'
2
+ require 'capybara-screenshot'
3
+
4
+ module CapybaraInlineScreenshot
5
+ # Sets the default base directory for artifacts (usually the root dir of the
6
+ # project). Defaults to Rails.root but can be set to another value if you're
7
+ # not using Rails.
8
+ def self.base_artifact_dir=(path)
9
+ @base_artifact_dir = path
10
+ end
11
+
12
+ def self.base_artifact_dir
13
+ @base_artifact_dir || Rails.root
14
+ end
15
+
16
+ def self.escape_code_for_image(path)
17
+ if ENV['CI'] || ENV['CAPYBARA_INLINE_SCREENSHOT'] == 'artifact'
18
+ artifact_escape_code_for_image(path)
19
+ else
20
+ base64_escape_code_for_image(path)
21
+ end
22
+ end
23
+
24
+ def self.artifact_escape_code_for_image(path)
25
+ relative_path = path.sub(/\A#{base_artifact_dir}\/?/, '')
26
+ "\e]1338;url=artifact://#{relative_path}\a"
27
+ end
28
+
29
+ def self.base64_escape_code_for_image(path)
30
+ name = inline_base64(File.basename(path))
31
+ image = inline_base64(File.read(path))
32
+ "\e]1337;File=name=#{name};inline=1:#{image}\a"
33
+ end
34
+
35
+ def self.inline_base64(string)
36
+ Base64.encode64(string).gsub("\n",'')
37
+ end
38
+ end
@@ -0,0 +1,22 @@
1
+ require 'capybara-inline-screenshot'
2
+ require 'capybara-screenshot'
3
+ require 'capybara-screenshot/rspec'
4
+
5
+ module CapybaraInlineScreenshot::Rspec
6
+ extend Capybara::Screenshot::RSpec::BaseReporter
7
+
8
+ enhance_with_screenshot :example_failed
9
+
10
+ def example_failed_with_screenshot(notification)
11
+ example_failed_without_screenshot(notification)
12
+
13
+ if screenshot = notification.example.metadata[:screenshot]
14
+ output.puts CapybaraScreenshot::Helpers.yellow("HTML screenshot: file://#{screenshot[:html]}") if screenshot[:html]
15
+ output.puts CapybaraScreenshot::Helpers.yellow("Image screenshot: file://#{screenshot[:image]}") if screenshot[:image]
16
+ output.puts CapybaraInlineScreenshot.escape_code_for_image(screenshot[:image]) if screenshot[:image]
17
+ end
18
+ end
19
+ end
20
+
21
+ Capybara::Screenshot::RSpec::REPORTERS["RSpec::Core::Formatters::ProgressFormatter"] = CapybaraInlineScreenshot::Rspec
22
+ Capybara::Screenshot::RSpec::REPORTERS["RSpec::Core::Formatters::DocumentationFormatter"] = CapybaraInlineScreenshot::Rspec
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capybara-inline-screenshot
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tim Lucas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capybara-screenshot
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Extends capybara-screenshot with inline image output
28
+ email: t@toolmantim.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - LICENSE.md
34
+ - README.md
35
+ - lib/capybara-inline-screenshot.rb
36
+ - lib/capybara-inline-screenshot/rspec.rb
37
+ homepage: http://github.com/buildkite/capybara-inline-screenshot
38
+ licenses:
39
+ - MIT
40
+ metadata: {}
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 2.4.5
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Extends capybara-screenshot with inline image output
61
+ test_files: []