capybara-screenshot 1.0.21 → 1.0.22

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2839e0fb312bb63dc21c79ccc62cf03e1f0c2108
4
- data.tar.gz: 1b35c96876b2fa3f13e2e582ad15c334225b4e9e
3
+ metadata.gz: b82c5c74da4902799ac9a61f9eb37449a928254e
4
+ data.tar.gz: 8052ba2b86c41f32539463afeddfe07cb275eb0a
5
5
  SHA512:
6
- metadata.gz: 0a381fbb702a47367f84b50a93391e885c8fbb3650dfb8f8efa3f4064dd06ffcdf85251ebc175fb7ffdce6ac2134110da1f993076cf441a8b9bc52c1e0c7d3ef
7
- data.tar.gz: 3a991f0ba8200bb4452b43e5024c6f293eefc81c5cccda07c628da3311d786b61101de4c9c6d489a68bc4489a2da3cee72f5def87885f82b3282a269fd5ce591
6
+ metadata.gz: 7a4fc4c95398c92bec5387f27521623c2ca6c5d7b6dbf07bfa614e63012ccc31625488baf52b6471bdf6d27e8c5254a0af149e7cb3fc220c4b64ce4239fbdbcf
7
+ data.tar.gz: 74fc5fb1271e9d7faaf23271719085ea6302a3b74124d764b1d4f5c6b55109329dfc368e1588466cf99d077a071d4cf77ebe40a8b3f68b140522f2442333f655
@@ -1,3 +1,9 @@
1
+ 21 Oct 2018 - 1.0.21 -> 1.0.22
2
+
3
+ * [Support for S3 URL in HTML screenshots](https://github.com/mattheworiordan/capybara-screenshot/pull/239)
4
+ * [Fix for partial Rails environments](https://github.com/mattheworiordan/capybara-screenshot/pull/238)
5
+ * [Capybara 3 support in CI](https://github.com/mattheworiordan/capybara-screenshot/pull/236)
6
+
1
7
  03 May 2018 - 1.0.20 -> 1.0.21
2
8
 
3
9
  * [Bug fix: Fix Ruby version compares in Gemspec](https://github.com/mattheworiordan/capybara-screenshot/pull/231)
@@ -58,7 +58,7 @@ module Capybara
58
58
  end
59
59
 
60
60
  def self.capybara_root
61
- @capybara_root ||= if defined?(::Rails) && ::Rails.root.present?
61
+ @capybara_root ||= if defined?(::Rails) && ::Rails.respond_to?(:root) && ::Rails.root.present?
62
62
  ::Rails.root.join capybara_tmp_path
63
63
  elsif defined?(Padrino)
64
64
  File.expand_path(capybara_tmp_path, Padrino.root)
@@ -106,11 +106,11 @@ module Capybara
106
106
  end
107
107
 
108
108
  def self.after_save_html &block
109
- Saver.after_save_html &block
109
+ Saver.after_save_html(&block)
110
110
  end
111
111
 
112
112
  def self.after_save_screenshot &block
113
- Saver.after_save_screenshot &block
113
+ Saver.after_save_screenshot(&block)
114
114
  end
115
115
 
116
116
  private
@@ -4,7 +4,7 @@ module Capybara
4
4
  class CallbackSet < Array
5
5
  def call *args
6
6
  each do |callback|
7
- callback.call *args
7
+ callback.call(*args)
8
8
  end
9
9
  end
10
10
  end
@@ -24,7 +24,7 @@ module Capybara
24
24
 
25
25
  def run_callbacks name, *args
26
26
  if cb_set = callbacks[name]
27
- cb_set.call *args
27
+ cb_set.call(*args)
28
28
  end
29
29
  end
30
30
  end
@@ -1,5 +1,3 @@
1
- require "capybara-screenshot"
2
-
3
1
  module Capybara
4
2
  module DSL
5
3
  # Adds class methods to Capybara module and gets mixed into
@@ -27,7 +27,7 @@ begin
27
27
  class Minitest::Test
28
28
  include Capybara::Screenshot::MiniTestPlugin
29
29
  end
30
- rescue NameError => e
30
+ rescue NameError
31
31
  class MiniTest::Unit::TestCase
32
32
  include Capybara::Screenshot::MiniTestPlugin
33
33
  end
@@ -26,7 +26,10 @@ module Capybara
26
26
  end
27
27
 
28
28
  private
29
- attr_reader :strategy_proc
29
+
30
+ def strategy_proc
31
+ @strategy_proc
32
+ end
30
33
 
31
34
  def wildcard_path
32
35
  File.expand_path('*.{html,png}', Screenshot.capybara_root)
@@ -3,7 +3,7 @@ module Capybara
3
3
  module RSpec
4
4
  module BaseReporter
5
5
 
6
- # Automatically set up method aliases (very much like ActiveSupport's `alias_method_chain`)
6
+ # Automatically set up method aliases (very much like ActiveSupport's `alias_method_chain`)
7
7
  # when the module gets included.
8
8
  def enhance_with_screenshot(method)
9
9
  with_method, without_method = "#{method}_with_screenshot", "#{method}_without_screenshot"
@@ -14,7 +14,6 @@ module Capybara
14
14
  end
15
15
  end
16
16
  end
17
-
18
17
  end
19
18
  end
20
19
  end
@@ -1,5 +1,6 @@
1
1
  require 'capybara-screenshot/rspec/base_reporter'
2
2
  require 'base64'
3
+ require 'uri'
3
4
 
4
5
  module Capybara
5
6
  module Screenshot
@@ -13,12 +14,22 @@ module Capybara
13
14
  example = @failed_examples.last
14
15
  # Ignores saved html file, only saved image will be embedded (if present)
15
16
  if (screenshot = example.metadata[:screenshot]) && screenshot[:image]
16
- image = File.binread(screenshot[:image])
17
- encoded_img = Base64.encode64(image)
18
- result += "<img src='data:image/png;base64,#{encoded_img}' style='display: block'>"
17
+ result += "<img src='#{image_tag_source(screenshot[:image])}' style='display: block'>"
19
18
  end
20
19
  result
21
20
  end
21
+
22
+ private
23
+
24
+ def image_tag_source(path)
25
+ if URI.regexp(%w[http https]) =~ path
26
+ path
27
+ else
28
+ image = File.binread(path)
29
+ encoded_img = Base64.encode64(image)
30
+ "data:image/png;base64,#{encoded_img}"
31
+ end
32
+ end
22
33
  end
23
34
  end
24
35
  end
@@ -26,8 +26,8 @@ module Capybara
26
26
  private
27
27
  def output_screenshot_info(example)
28
28
  return unless (screenshot = example.metadata[:screenshot])
29
- output.puts(long_padding + CapybaraScreenshot::Helpers.yellow("HTML screenshot: file://#{screenshot[:html]}")) if screenshot[:html]
30
- output.puts(long_padding + CapybaraScreenshot::Helpers.yellow("Image screenshot: file://#{screenshot[:image]}")) if screenshot[:image]
29
+ output.puts(long_padding + CapybaraScreenshot::Helpers.yellow("HTML screenshot: #{screenshot[:html]}")) if screenshot[:html]
30
+ output.puts(long_padding + CapybaraScreenshot::Helpers.yellow("Image screenshot: #{screenshot[:image]}")) if screenshot[:image]
31
31
  end
32
32
 
33
33
  def long_padding
@@ -5,6 +5,8 @@ module Capybara
5
5
  class S3Saver
6
6
  DEFAULT_REGION = 'us-east-1'
7
7
 
8
+ attr_accessor :html_path, :screenshot_path
9
+
8
10
  def initialize(saver, s3_client, bucket_name, object_configuration, options={})
9
11
  @saver = saver
10
12
  @s3_client = s3_client
@@ -31,11 +33,13 @@ module Capybara
31
33
  end
32
34
 
33
35
  def save_and_upload_screenshot
34
- save_and do |local_file_path|
36
+ save_and do |type, local_file_path|
35
37
  File.open(local_file_path) do |file|
38
+ s3_upload_path = "#{@key_prefix}#{File.basename(local_file_path)}"
39
+
36
40
  object_payload = {
37
41
  bucket: bucket_name,
38
- key: "#{@key_prefix}#{File.basename(local_file_path)}",
42
+ key: s3_upload_path,
39
43
  body: file
40
44
  }
41
45
 
@@ -44,6 +48,10 @@ module Capybara
44
48
  s3_client.put_object(
45
49
  object_payload
46
50
  )
51
+
52
+ s3_region = s3_client.get_bucket_location(bucket: bucket_name).location_constraint
53
+
54
+ send("#{type}_path=", "https://#{bucket_name}.s3-#{s3_region}.amazonaws.com/#{s3_upload_path}")
47
55
  end
48
56
  end
49
57
  end
@@ -66,8 +74,8 @@ module Capybara
66
74
  def save_and
67
75
  saver.save
68
76
 
69
- yield(saver.html_path) if block_given? && saver.html_saved?
70
- yield(saver.screenshot_path) if block_given? && saver.screenshot_saved?
77
+ yield(:html, saver.html_path) if block_given? && saver.html_saved?
78
+ yield(:screenshot, saver.screenshot_path) if block_given? && saver.screenshot_saved?
71
79
  end
72
80
  end
73
81
  end
@@ -1,5 +1,5 @@
1
1
  module Capybara
2
2
  module Screenshot
3
- VERSION = '1.0.21'
3
+ VERSION = '1.0.22'
4
4
  end
5
5
  end
@@ -32,7 +32,7 @@ describe "Using Capybara::Screenshot with Cucumber" do
32
32
  end
33
33
 
34
34
  it 'saves a screenshot on failure' do
35
- run_failing_case %q{Unable to find visible link or button "you'll never find me"}, <<-CUCUMBER
35
+ run_failing_case %q{Unable to find (visible )?link or button "you'll never find me"}, <<-CUCUMBER
36
36
  Feature: Failure
37
37
  Scenario: Failure
38
38
  Given I visit "/"
@@ -52,7 +52,7 @@ describe "Using Capybara::Screenshot with Cucumber" do
52
52
  end
53
53
 
54
54
  it 'saves a screenshot for the correct session for failures using_session' do
55
- run_failing_case(%q{Unable to find visible link or button "you'll never find me"}, <<-CUCUMBER)
55
+ run_failing_case(%q{Unable to find (visible )?link or button "you'll never find me"}, <<-CUCUMBER)
56
56
  Feature: Failure
57
57
  Scenario: Failure in different session
58
58
  Given I visit "/"
@@ -68,7 +68,7 @@ describe "Using Capybara::Screenshot with Cucumber" do
68
68
  end
69
69
 
70
70
  it 'on failure it prunes previous screenshots when strategy is set' do
71
- run_failing_case %q{Unable to find visible link or button "you'll never find me"}, <<-CUCUMBER
71
+ run_failing_case %q{Unable to find (visible )?link or button "you'll never find me"}, <<-CUCUMBER
72
72
  Feature: Prune
73
73
  Scenario: Screenshots are pruned if strategy is set
74
74
  Given I visit "/"
@@ -23,7 +23,7 @@ describe "Using Capybara::Screenshot with MiniTest" do
23
23
 
24
24
  cmd = 'bundle exec ruby test_failure.rb'
25
25
  run_simple_with_retry cmd, false
26
- expect(last_command_started.output).to include %q{Unable to find visible link or button "you'll never find me"}
26
+ expect(last_command_started.output).to match %r{Unable to find (visible )?link or button "you'll never find me"}
27
27
  end
28
28
 
29
29
  it 'saves a screenshot on failure' do
@@ -14,7 +14,7 @@ describe "Using Capybara::Screenshot with Test::Unit" do
14
14
 
15
15
  #{setup_test_app}
16
16
  Capybara::Screenshot.register_filename_prefix_formatter(:testunit) do | fault |
17
- raise "expected fault" unless fault.exception.message.include? %q{Unable to find visible link or button "you'll never find me"}
17
+ raise "expected fault" unless fault.exception.message.match %r{Unable to find (visible )?link or button "you'll never find me"}
18
18
  'my_screenshot'
19
19
  end
20
20
 
@@ -29,7 +29,7 @@ describe "Using Capybara::Screenshot with Test::Unit" do
29
29
 
30
30
  cmd = "bundle exec ruby #{integration_path}/test_failure.rb"
31
31
  run_simple_with_retry cmd, false
32
- expect(last_command_started.output).to include %q{Unable to find visible link or button "you'll never find me"}
32
+ expect(last_command_started.output).to match %r{Unable to find (visible )?link or button "you'll never find me"}
33
33
  end
34
34
 
35
35
  it "saves a screenshot on failure for any test in path 'test/integration'" do
@@ -41,7 +41,7 @@ describe Capybara::Screenshot::RSpec, :type => :aruba do
41
41
  end
42
42
 
43
43
  it 'saves a screenshot when browser action fails' do
44
- run_failing_case <<-RUBY, %q{Unable to find visible link or button "you'll never find me"}
44
+ run_failing_case <<-RUBY, %r{Unable to find (visible )?link or button "you'll never find me"}
45
45
  feature 'screenshot with failure' do
46
46
  scenario 'click on a missing link' do
47
47
  visit '/'
@@ -103,7 +103,7 @@ describe Capybara::Screenshot::RSpec, :type => :aruba do
103
103
  end
104
104
 
105
105
  it 'saves a screenshot for the correct session for failures using_session' do
106
- run_failing_case <<-RUBY, %q{Unable to find visible link or button "you'll never find me"}
106
+ run_failing_case <<-RUBY, %r{Unable to find (visible )?link or button "you'll never find me"}
107
107
  feature 'screenshot with failure' do
108
108
  scenario 'click on a missing link' do
109
109
  visit '/'
@@ -17,7 +17,7 @@ describe "Using Capybara::Screenshot with Spinach" do
17
17
  end
18
18
 
19
19
  it "saves a screenshot on failure" do
20
- run_failing_case(%q{Unable to find visible link or button "you'll never find me"}, <<-GHERKIN)
20
+ run_failing_case(%q{Unable to find (visible )?link or button "you'll never find me"}, <<-GHERKIN)
21
21
  Feature: Failure
22
22
  Scenario: Failure
23
23
  Given I visit "/"
@@ -37,7 +37,7 @@ describe "Using Capybara::Screenshot with Spinach" do
37
37
  end
38
38
 
39
39
  it "saves a screenshot for the correct session for failures using_session" do
40
- run_failing_case(%q{Unable to find visible link or button "you'll never find me"}, <<-GHERKIN)
40
+ run_failing_case(%q{Unable to find (visible )?link or button "you'll never find me"}, <<-GHERKIN)
41
41
  Feature: Failure
42
42
  Scenario: Failure in different session
43
43
  Given I visit "/"
@@ -49,7 +49,7 @@ describe "Using Capybara::Screenshot with Spinach" do
49
49
  it 'on failure it prunes previous screenshots when strategy is set' do
50
50
  create_screenshot_for_pruning
51
51
  configure_prune_strategy :last_run
52
- run_failing_case(%q{Unable to find visible link or button "you'll never find me"}, <<-GHERKIN)
52
+ run_failing_case(%q{Unable to find (visible )?link or button "you'll never find me"}, <<-GHERKIN)
53
53
  Feature: Failure
54
54
  Scenario: Failure
55
55
  Given I visit "/"
@@ -15,4 +15,17 @@ describe Capybara::Screenshot::RSpec::HtmlEmbedReporter do
15
15
  expect(content_without_styles).to eql("original content<img src='data:image/png;base64,#{encoded_image_data}'>")
16
16
  end
17
17
  end
18
+
19
+ context 'when an image was saved to s3' do
20
+ let(:s3_image_url) { "http://s3.amazon.com/path/to/image" }
21
+
22
+ before do
23
+ set_example double("example", metadata: {screenshot: {image: s3_image_url}})
24
+ end
25
+
26
+ it 'embeds the image URL into the content' do
27
+ content_without_styles = @reporter.extra_failure_content(nil).gsub(/ ?style='.*?' ?/, "")
28
+ expect(content_without_styles).to eql("original content<img src='#{s3_image_url}'>")
29
+ end
30
+ end
18
31
  end
@@ -64,20 +64,20 @@ describe Capybara::Screenshot::RSpec::TextReporter do
64
64
  end
65
65
 
66
66
  context 'when a html file was saved' do
67
- let(:example) { example_failed_method_argument_double(screenshot: { html: "path/to/html" }) }
67
+ let(:example) { example_failed_method_argument_double(screenshot: { html: "/path/to/html" }) }
68
68
 
69
69
  it 'appends the html file path to the original output' do
70
70
  @reporter.send(example_failed_method, example)
71
- expect(@reporter.output.string).to eql("original failure info\n #{CapybaraScreenshot::Helpers.yellow("HTML screenshot: file://path/to/html")}\n")
71
+ expect(@reporter.output.string).to eql("original failure info\n #{CapybaraScreenshot::Helpers.yellow("HTML screenshot: /path/to/html")}\n")
72
72
  end
73
73
  end
74
74
 
75
75
  context 'when a html file and an image were saved' do
76
- let(:example) { example_failed_method_argument_double(screenshot: { html: "path/to/html", image: "path/to/image" }) }
76
+ let(:example) { example_failed_method_argument_double(screenshot: { html: "/path/to/html", image: "/path/to/image" }) }
77
77
 
78
78
  it 'appends the image path to the original output' do
79
79
  @reporter.send(example_failed_method, example)
80
- expect(@reporter.output.string).to eql("original failure info\n #{CapybaraScreenshot::Helpers.yellow("HTML screenshot: file://path/to/html")}\n #{CapybaraScreenshot::Helpers.yellow("Image screenshot: file://path/to/image")}\n")
80
+ expect(@reporter.output.string).to eql("original failure info\n #{CapybaraScreenshot::Helpers.yellow("HTML screenshot: /path/to/html")}\n #{CapybaraScreenshot::Helpers.yellow("Image screenshot: /path/to/image")}\n")
81
81
  end
82
82
  end
83
83
 
@@ -91,8 +91,8 @@ describe Capybara::Screenshot::RSpec::TextReporter do
91
91
  end
92
92
  old_reporter = old_reporter_class.new
93
93
  old_reporter.singleton_class.send :include, described_class
94
- example = example_failed_method_argument_double(screenshot: { html: "path/to/html" })
94
+ example = example_failed_method_argument_double(screenshot: { html: "/path/to/html" })
95
95
  old_reporter.send(example_failed_method, example)
96
- expect(old_reporter.output.string).to eql("original failure info\n #{CapybaraScreenshot::Helpers.yellow("HTML screenshot: file://path/to/html")}\n")
96
+ expect(old_reporter.output.string).to eql("original failure info\n #{CapybaraScreenshot::Helpers.yellow("HTML screenshot: /path/to/html")}\n")
97
97
  end
98
98
  end
@@ -11,6 +11,12 @@ describe Capybara::Screenshot::S3Saver do
11
11
  let(:s3_saver) { described_class.new(saver, s3_client, bucket_name, s3_object_configuration) }
12
12
  let(:s3_saver_with_key_prefix) { described_class.new(saver, s3_client, bucket_name, s3_object_configuration, key_prefix: key_prefix) }
13
13
 
14
+ let(:region) { double('region') }
15
+
16
+ before do
17
+ allow(s3_client).to receive(:get_bucket_location).and_return(double(:bucket_location_response, location_constraint: region))
18
+ end
19
+
14
20
  describe '.new_with_configuration' do
15
21
  let(:access_key_id) { double('access_key_id') }
16
22
  let(:secret_access_key) { double('secret_access_key') }
@@ -21,7 +27,6 @@ describe Capybara::Screenshot::S3Saver do
21
27
  }
22
28
  }
23
29
 
24
- let(:region) { double('region') }
25
30
  let(:s3_client_credentials) {
26
31
  s3_client_credentials_using_defaults.merge(region: region)
27
32
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-screenshot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.21
4
+ version: 1.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew O'Riordan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-04 00:00:00.000000000 Z
11
+ date: 2018-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara