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.
- checksums.yaml +5 -5
- data/.travis.yml +11 -12
- data/Appraisals +14 -16
- data/CHANGELOG.md +69 -0
- data/Gemfile +4 -3
- data/README.md +96 -30
- data/capybara-screenshot.gemspec +12 -5
- data/gemfiles/cucumber.1.3.gemfile +12 -0
- data/gemfiles/cucumber.2.4.gemfile +12 -0
- data/gemfiles/latest.gemfile +5 -2
- data/gemfiles/rspec.3.0.gemfile +5 -2
- data/gemfiles/rspec.3.3.gemfile +12 -0
- data/gemfiles/spinach.0.8.gemfile +12 -0
- data/lib/capybara-screenshot/callbacks.rb +44 -0
- data/lib/capybara-screenshot/capybara.rb +26 -10
- data/lib/capybara-screenshot/cucumber.rb +12 -5
- data/lib/capybara-screenshot/minitest.rb +1 -1
- data/lib/capybara-screenshot/pruner.rb +5 -1
- data/lib/capybara-screenshot/rspec/base_reporter.rb +1 -2
- data/lib/capybara-screenshot/rspec/html_embed_reporter.rb +14 -3
- data/lib/capybara-screenshot/rspec/html_link_reporter.rb +1 -1
- data/lib/capybara-screenshot/rspec/text_reporter.rb +2 -2
- data/lib/capybara-screenshot/rspec.rb +25 -3
- data/lib/capybara-screenshot/s3_saver.rb +39 -11
- data/lib/capybara-screenshot/saver.rb +60 -15
- data/lib/capybara-screenshot/version.rb +1 -1
- data/lib/capybara-screenshot.rb +38 -3
- data/spec/cucumber/cucumber_spec.rb +4 -8
- data/spec/feature/minitest_spec.rb +2 -6
- data/spec/feature/testunit_spec.rb +3 -7
- data/spec/rspec/rspec_spec.rb +36 -8
- data/spec/spinach/spinach_spec.rb +4 -8
- data/spec/support/aruba.rb +0 -1
- data/spec/support/common_setup.rb +13 -5
- data/spec/unit/capybara-screenshot_spec.rb +2 -1
- data/spec/unit/capybara_spec.rb +13 -0
- data/spec/unit/pruner_spec.rb +2 -2
- data/spec/unit/rspec_reporters/html_embed_reporter_spec.rb +13 -0
- data/spec/unit/rspec_reporters/text_reporter_spec.rb +6 -6
- data/spec/unit/s3_saver_spec.rb +196 -14
- data/spec/unit/saver_spec.rb +132 -16
- metadata +19 -17
- data/gemfiles/cucumber.1.2.gemfile +0 -9
- data/gemfiles/cucumber.1.3.0.gemfile +0 -9
- data/gemfiles/rspec.2.14.gemfile +0 -9
- data/gemfiles/rspec.2.99.gemfile +0 -9
- data/gemfiles/spinach.0.7.gemfile +0 -9
- data/gemfiles/spinach.0.8.0.gemfile +0 -9
data/spec/rspec/rspec_spec.rb
CHANGED
@@ -5,8 +5,7 @@ describe Capybara::Screenshot::RSpec, :type => :aruba do
|
|
5
5
|
include CommonSetup
|
6
6
|
|
7
7
|
before do
|
8
|
-
|
9
|
-
Capybara.save_and_open_page_path = expand_path('tmp')
|
8
|
+
Capybara::Screenshot.capybara_tmp_path = expand_path('tmp')
|
10
9
|
end
|
11
10
|
|
12
11
|
def run_failing_case(code, error_message, format=nil)
|
@@ -32,7 +31,7 @@ describe Capybara::Screenshot::RSpec, :type => :aruba do
|
|
32
31
|
RUBY
|
33
32
|
|
34
33
|
cmd = cmd_with_format(options[:format])
|
35
|
-
run_simple_with_retry cmd
|
34
|
+
run_simple_with_retry cmd
|
36
35
|
|
37
36
|
expect(last_command_started.output).to match('0 failures') if options[:assert_all_passed]
|
38
37
|
end
|
@@ -41,8 +40,8 @@ describe Capybara::Screenshot::RSpec, :type => :aruba do
|
|
41
40
|
"rspec #{"--format #{format} " if format}#{expand_path('spec/test_failure.rb')}"
|
42
41
|
end
|
43
42
|
|
44
|
-
it 'saves a screenshot
|
45
|
-
run_failing_case <<-RUBY, %
|
43
|
+
it 'saves a screenshot when browser action fails' do
|
44
|
+
run_failing_case <<-RUBY, %r{Unable to find (visible )?link or button "you'll never find me"}
|
46
45
|
feature 'screenshot with failure' do
|
47
46
|
scenario 'click on a missing link' do
|
48
47
|
visit '/'
|
@@ -51,7 +50,19 @@ describe Capybara::Screenshot::RSpec, :type => :aruba do
|
|
51
50
|
end
|
52
51
|
end
|
53
52
|
RUBY
|
54
|
-
expect(
|
53
|
+
expect('tmp/screenshot.html').to have_file_content('This is the root page')
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'saves a screenshot when expectation fails when using :aggregate_failures' do
|
57
|
+
run_failing_case <<-RUBY, %q{expected "This is the root page" to include "you'll never find me"}
|
58
|
+
feature 'screenshot with failure', :aggregate_failures do
|
59
|
+
scenario 'expect a missing link' do
|
60
|
+
visit '/'
|
61
|
+
expect(page.body).to include("you'll never find me")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
RUBY
|
65
|
+
expect('tmp/screenshot.html').to have_file_content('This is the root page')
|
55
66
|
end
|
56
67
|
|
57
68
|
formatters = {
|
@@ -92,7 +103,7 @@ describe Capybara::Screenshot::RSpec, :type => :aruba do
|
|
92
103
|
end
|
93
104
|
|
94
105
|
it 'saves a screenshot for the correct session for failures using_session' do
|
95
|
-
run_failing_case <<-RUBY, %
|
106
|
+
run_failing_case <<-RUBY, %r{Unable to find (visible )?link or button "you'll never find me"}
|
96
107
|
feature 'screenshot with failure' do
|
97
108
|
scenario 'click on a missing link' do
|
98
109
|
visit '/'
|
@@ -105,7 +116,24 @@ describe Capybara::Screenshot::RSpec, :type => :aruba do
|
|
105
116
|
end
|
106
117
|
end
|
107
118
|
RUBY
|
108
|
-
expect('tmp/screenshot.html').to have_file_content(/is/)
|
119
|
+
expect('tmp/screenshot.html').to have_file_content(/This is a different page/)
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'saves a screenshot for the correct session for failures Capybara.using_session' do
|
123
|
+
run_failing_case <<-RUBY, %r{Unable to find (visible )?link or button "you'll never find me"}
|
124
|
+
feature 'screenshot with failure' do
|
125
|
+
scenario 'click on a missing link' do
|
126
|
+
visit '/'
|
127
|
+
expect(page.body).to include('This is the root page')
|
128
|
+
Capybara.using_session :different_session do
|
129
|
+
visit '/different_page'
|
130
|
+
expect(page.body).to include('This is a different page')
|
131
|
+
click_on "you'll never find me"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
RUBY
|
136
|
+
expect('tmp/screenshot.html').to have_file_content(/This is a different page/)
|
109
137
|
end
|
110
138
|
|
111
139
|
context 'pruning' do
|
@@ -3,10 +3,6 @@ require "spec_helper"
|
|
3
3
|
describe "Using Capybara::Screenshot with Spinach" do
|
4
4
|
include CommonSetup
|
5
5
|
|
6
|
-
before do
|
7
|
-
setup_aruba
|
8
|
-
end
|
9
|
-
|
10
6
|
def run_failing_case(failure_message, code)
|
11
7
|
write_file('steps/failure.rb', <<-RUBY)
|
12
8
|
#{ensure_load_paths_valid}
|
@@ -16,12 +12,12 @@ describe "Using Capybara::Screenshot with Spinach" do
|
|
16
12
|
|
17
13
|
write_file('spinach.feature', code)
|
18
14
|
cmd = 'bundle exec spinach -f .'
|
19
|
-
run_simple_with_retry cmd
|
15
|
+
run_simple_with_retry cmd
|
20
16
|
expect(last_command_started.output).to match(failure_message)
|
21
17
|
end
|
22
18
|
|
23
19
|
it "saves a screenshot on failure" do
|
24
|
-
run_failing_case(%q{Unable to find 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)
|
25
21
|
Feature: Failure
|
26
22
|
Scenario: Failure
|
27
23
|
Given I visit "/"
|
@@ -41,7 +37,7 @@ describe "Using Capybara::Screenshot with Spinach" do
|
|
41
37
|
end
|
42
38
|
|
43
39
|
it "saves a screenshot for the correct session for failures using_session" do
|
44
|
-
run_failing_case(%q{Unable to find 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)
|
45
41
|
Feature: Failure
|
46
42
|
Scenario: Failure in different session
|
47
43
|
Given I visit "/"
|
@@ -53,7 +49,7 @@ describe "Using Capybara::Screenshot with Spinach" do
|
|
53
49
|
it 'on failure it prunes previous screenshots when strategy is set' do
|
54
50
|
create_screenshot_for_pruning
|
55
51
|
configure_prune_strategy :last_run
|
56
|
-
run_failing_case(%q{Unable to find 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)
|
57
53
|
Feature: Failure
|
58
54
|
Scenario: Failure
|
59
55
|
Given I visit "/"
|
data/spec/support/aruba.rb
CHANGED
@@ -20,7 +20,7 @@ module CommonSetup
|
|
20
20
|
target.let(:setup_test_app) do
|
21
21
|
<<-RUBY
|
22
22
|
require 'support/test_app'
|
23
|
-
Capybara.
|
23
|
+
Capybara::Screenshot.capybara_tmp_path = '#{screenshot_path}'
|
24
24
|
Capybara.app = TestApp
|
25
25
|
Capybara::Screenshot.append_timestamp = false
|
26
26
|
#{@additional_setup_steps}
|
@@ -33,11 +33,19 @@ module CommonSetup
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
|
-
|
36
|
+
target.after(:each) do |example|
|
37
|
+
if example.exception
|
38
|
+
puts "Output from failed Aruba test:"
|
39
|
+
puts all_commands.map { |c| c.output }.map { |line| " #{line}"}
|
40
|
+
puts ""
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def run_simple_with_retry(cmd, fail_on_error: false)
|
45
|
+
run_command_and_stop(cmd, fail_on_error: fail_on_error)
|
38
46
|
rescue ChildProcess::TimeoutError => e
|
39
|
-
puts "
|
40
|
-
|
47
|
+
puts "run_command_and_stop(#{cmd}, fail_on_error: #{fail_on_error}) failed. Will retry once. `#{e.message}`"
|
48
|
+
run_command_and_stop(cmd, fail_on_error: fail_on_error)
|
41
49
|
end
|
42
50
|
|
43
51
|
def configure_prune_strategy(strategy)
|
@@ -81,11 +81,12 @@ describe Capybara::Screenshot do
|
|
81
81
|
args = double('args')
|
82
82
|
s3_saver_double = double('s3_saver')
|
83
83
|
s3_configuration = { hello: 'world' }
|
84
|
+
s3_object_configuration = {}
|
84
85
|
|
85
86
|
Capybara::Screenshot.s3_configuration = s3_configuration
|
86
87
|
|
87
88
|
expect(Capybara::Screenshot::Saver).to receive(:new).with(args).and_return(saver_double)
|
88
|
-
expect(Capybara::Screenshot::S3Saver).to receive(:new_with_configuration).with(saver_double, s3_configuration).and_return(s3_saver_double)
|
89
|
+
expect(Capybara::Screenshot::S3Saver).to receive(:new_with_configuration).with(saver_double, s3_configuration, s3_object_configuration).and_return(s3_saver_double)
|
89
90
|
|
90
91
|
expect(Capybara::Screenshot.new_saver(args)).to eq(s3_saver_double)
|
91
92
|
end
|
data/spec/unit/capybara_spec.rb
CHANGED
@@ -26,6 +26,19 @@ describe Capybara do
|
|
26
26
|
}.to raise_exception ::RSpec::Expectations::ExpectationNotMetError
|
27
27
|
end
|
28
28
|
end
|
29
|
+
|
30
|
+
describe 'Capybara.using_session' do
|
31
|
+
include Capybara::DSL
|
32
|
+
|
33
|
+
it 'saves the name of the final session' do
|
34
|
+
expect(Capybara::Screenshot).to receive(:final_session_name=).with(:different_session)
|
35
|
+
expect {
|
36
|
+
Capybara.using_session :different_session do
|
37
|
+
expect(0).to eq 1
|
38
|
+
end
|
39
|
+
}.to raise_exception ::RSpec::Expectations::ExpectationNotMetError
|
40
|
+
end
|
41
|
+
end
|
29
42
|
end
|
30
43
|
|
31
44
|
describe 'final_session_name' do
|
data/spec/unit/pruner_spec.rb
CHANGED
@@ -27,7 +27,7 @@ describe Capybara::Screenshot::Pruner do
|
|
27
27
|
let(:strategy) { :invalid_strategy }
|
28
28
|
|
29
29
|
it 'raises an error' do
|
30
|
-
expect { pruner }.to raise_error
|
30
|
+
expect { pruner }.to raise_error(/Invalid prune strategy/)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -35,7 +35,7 @@ describe Capybara::Screenshot::Pruner do
|
|
35
35
|
let(:strategy) { { keep: :symbol } }
|
36
36
|
|
37
37
|
it 'raises an error' do
|
38
|
-
expect { pruner }.to raise_error
|
38
|
+
expect { pruner }.to raise_error(/must be a Integer/)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -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:
|
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:
|
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:
|
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
|
data/spec/unit/s3_saver_spec.rb
CHANGED
@@ -4,9 +4,19 @@ require 'capybara-screenshot/s3_saver'
|
|
4
4
|
describe Capybara::Screenshot::S3Saver do
|
5
5
|
let(:saver) { double('saver') }
|
6
6
|
let(:bucket_name) { double('bucket_name') }
|
7
|
+
let(:s3_object_configuration) { {} }
|
8
|
+
let(:options) { {} }
|
7
9
|
let(:s3_client) { double('s3_client') }
|
10
|
+
let(:key_prefix){ "some/path/" }
|
8
11
|
|
9
|
-
let(:s3_saver) {
|
12
|
+
let(:s3_saver) { described_class.new(saver, s3_client, bucket_name, s3_object_configuration, options) }
|
13
|
+
let(:s3_saver_with_key_prefix) { described_class.new(saver, s3_client, bucket_name, s3_object_configuration, key_prefix: key_prefix) }
|
14
|
+
|
15
|
+
let(:region) { double('region') }
|
16
|
+
|
17
|
+
before do
|
18
|
+
allow(s3_client).to receive(:get_bucket_location).and_return(double(:bucket_location_response, location_constraint: region))
|
19
|
+
end
|
10
20
|
|
11
21
|
describe '.new_with_configuration' do
|
12
22
|
let(:access_key_id) { double('access_key_id') }
|
@@ -18,40 +28,73 @@ describe Capybara::Screenshot::S3Saver do
|
|
18
28
|
}
|
19
29
|
}
|
20
30
|
|
21
|
-
let(:region) { double('region') }
|
22
31
|
let(:s3_client_credentials) {
|
23
32
|
s3_client_credentials_using_defaults.merge(region: region)
|
24
33
|
}
|
25
34
|
|
26
|
-
|
35
|
+
before do
|
27
36
|
allow(Aws::S3::Client).to receive(:new).and_return(s3_client)
|
28
|
-
allow(
|
37
|
+
allow(described_class).to receive(:new)
|
38
|
+
end
|
29
39
|
|
30
|
-
|
40
|
+
it 'destructures the configuration into its components' do
|
41
|
+
described_class.new_with_configuration(saver, {
|
31
42
|
s3_client_credentials: s3_client_credentials,
|
32
43
|
bucket_name: bucket_name
|
33
|
-
})
|
44
|
+
}, s3_object_configuration)
|
34
45
|
|
35
46
|
expect(Aws::S3::Client).to have_received(:new).with(s3_client_credentials)
|
36
|
-
expect(
|
47
|
+
expect(described_class).to have_received(:new).with(saver, s3_client, bucket_name, s3_object_configuration, hash_including({}))
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'passes key_prefix option if specified' do
|
51
|
+
described_class.new_with_configuration(saver, {
|
52
|
+
s3_client_credentials: s3_client_credentials,
|
53
|
+
bucket_name: bucket_name,
|
54
|
+
key_prefix: key_prefix,
|
55
|
+
}, s3_object_configuration)
|
56
|
+
|
57
|
+
expect(Aws::S3::Client).to have_received(:new).with(s3_client_credentials)
|
58
|
+
expect(described_class).to have_received(:new).with(saver, s3_client, bucket_name, s3_object_configuration, hash_including(key_prefix: key_prefix))
|
37
59
|
end
|
38
60
|
|
39
61
|
it 'defaults the region to us-east-1' do
|
40
62
|
default_region = 'us-east-1'
|
41
63
|
|
42
|
-
|
43
|
-
allow(Capybara::Screenshot::S3Saver).to receive(:new)
|
44
|
-
|
45
|
-
Capybara::Screenshot::S3Saver.new_with_configuration(saver, {
|
64
|
+
described_class.new_with_configuration(saver, {
|
46
65
|
s3_client_credentials: s3_client_credentials_using_defaults,
|
47
66
|
bucket_name: bucket_name
|
48
|
-
})
|
67
|
+
}, s3_object_configuration)
|
49
68
|
|
50
69
|
expect(Aws::S3::Client).to have_received(:new).with(
|
51
70
|
s3_client_credentials.merge(region: default_region)
|
52
71
|
)
|
53
72
|
|
54
|
-
expect(
|
73
|
+
expect(described_class).to have_received(:new).with(saver, s3_client, bucket_name, s3_object_configuration, hash_including({}))
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'stores the object configuration when passed' do
|
77
|
+
s3_object_configuration = { acl: 'public-read' }
|
78
|
+
Capybara::Screenshot.s3_object_configuration = { acl: 'public-read' }
|
79
|
+
|
80
|
+
described_class.new_with_configuration(saver, {
|
81
|
+
s3_client_credentials: s3_client_credentials,
|
82
|
+
bucket_name: bucket_name
|
83
|
+
}, s3_object_configuration)
|
84
|
+
|
85
|
+
expect(Aws::S3::Client).to have_received(:new).with(s3_client_credentials)
|
86
|
+
expect(described_class).to have_received(:new).with(saver, s3_client, bucket_name, s3_object_configuration, hash_including({}))
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'passes key_prefix option if specified' do
|
90
|
+
described_class.new_with_configuration(saver, {
|
91
|
+
s3_client_credentials: s3_client_credentials,
|
92
|
+
bucket_name: bucket_name,
|
93
|
+
key_prefix: key_prefix,
|
94
|
+
}, s3_object_configuration)
|
95
|
+
|
96
|
+
expect(Aws::S3::Client).to have_received(:new).with(s3_client_credentials)
|
97
|
+
expect(described_class).to have_received(:new).with(saver, s3_client, bucket_name, s3_object_configuration, hash_including(key_prefix: key_prefix))
|
55
98
|
end
|
56
99
|
end
|
57
100
|
|
@@ -62,6 +105,20 @@ describe Capybara::Screenshot::S3Saver do
|
|
62
105
|
allow(saver).to receive(:save)
|
63
106
|
end
|
64
107
|
|
108
|
+
context 'providing a bucket_host' do
|
109
|
+
let(:options) { { bucket_host: 'some other location' } }
|
110
|
+
|
111
|
+
it 'does not request the bucket location' do
|
112
|
+
screenshot_path = '/baz/bim.jpg'
|
113
|
+
|
114
|
+
screenshot_file = double('screenshot_file')
|
115
|
+
|
116
|
+
expect(s3_saver).not_to receive(:determine_bucket_host)
|
117
|
+
|
118
|
+
s3_saver.save
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
65
122
|
it 'calls save on the underlying saver' do
|
66
123
|
expect(saver).to receive(:save)
|
67
124
|
|
@@ -83,6 +140,8 @@ describe Capybara::Screenshot::S3Saver do
|
|
83
140
|
body: html_file
|
84
141
|
)
|
85
142
|
|
143
|
+
expect(s3_saver).to receive(:determine_bucket_host).and_call_original
|
144
|
+
|
86
145
|
s3_saver.save
|
87
146
|
end
|
88
147
|
|
@@ -103,6 +162,129 @@ describe Capybara::Screenshot::S3Saver do
|
|
103
162
|
|
104
163
|
s3_saver.save
|
105
164
|
end
|
165
|
+
|
166
|
+
context 'with object configuration' do
|
167
|
+
let(:s3_object_configuration) { { acl: 'public-read' } }
|
168
|
+
let(:s3_saver) { described_class.new(saver, s3_client, bucket_name, s3_object_configuration) }
|
169
|
+
|
170
|
+
it 'uploads the html' do
|
171
|
+
html_path = '/foo/bar.html'
|
172
|
+
expect(saver).to receive(:html_path).and_return(html_path)
|
173
|
+
expect(saver).to receive(:html_saved?).and_return(true)
|
174
|
+
|
175
|
+
html_file = double('html_file')
|
176
|
+
|
177
|
+
expect(File).to receive(:open).with(html_path).and_yield(html_file)
|
178
|
+
|
179
|
+
expect(s3_client).to receive(:put_object).with(
|
180
|
+
bucket: bucket_name,
|
181
|
+
key: 'bar.html',
|
182
|
+
body: html_file,
|
183
|
+
acl: 'public-read'
|
184
|
+
)
|
185
|
+
|
186
|
+
s3_saver.save
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'uploads the screenshot' do
|
190
|
+
screenshot_path = '/baz/bim.jpg'
|
191
|
+
expect(saver).to receive(:screenshot_path).and_return(screenshot_path)
|
192
|
+
expect(saver).to receive(:screenshot_saved?).and_return(true)
|
193
|
+
|
194
|
+
screenshot_file = double('screenshot_file')
|
195
|
+
|
196
|
+
expect(File).to receive(:open).with(screenshot_path).and_yield(screenshot_file)
|
197
|
+
|
198
|
+
expect(s3_client).to receive(:put_object).with(
|
199
|
+
bucket: bucket_name,
|
200
|
+
key: 'bim.jpg',
|
201
|
+
body: screenshot_file,
|
202
|
+
acl: 'public-read'
|
203
|
+
)
|
204
|
+
|
205
|
+
s3_saver.save
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
context 'with key_prefix specified' do
|
210
|
+
it 'uploads the html with key prefix' do
|
211
|
+
html_path = '/foo/bar.html'
|
212
|
+
expect(saver).to receive(:html_path).and_return(html_path)
|
213
|
+
expect(saver).to receive(:html_saved?).and_return(true)
|
214
|
+
|
215
|
+
html_file = double('html_file')
|
216
|
+
|
217
|
+
expect(File).to receive(:open).with(html_path).and_yield(html_file)
|
218
|
+
|
219
|
+
expect(s3_client).to receive(:put_object).with(
|
220
|
+
bucket: bucket_name,
|
221
|
+
key: 'some/path/bar.html',
|
222
|
+
body: html_file
|
223
|
+
)
|
224
|
+
|
225
|
+
s3_saver_with_key_prefix.save
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'uploads the screenshot with key prefix' do
|
229
|
+
screenshot_path = '/baz/bim.jpg'
|
230
|
+
expect(saver).to receive(:screenshot_path).and_return(screenshot_path)
|
231
|
+
expect(saver).to receive(:screenshot_saved?).and_return(true)
|
232
|
+
|
233
|
+
screenshot_file = double('screenshot_file')
|
234
|
+
|
235
|
+
expect(File).to receive(:open).with(screenshot_path).and_yield(screenshot_file)
|
236
|
+
|
237
|
+
expect(s3_client).to receive(:put_object).with(
|
238
|
+
bucket: bucket_name,
|
239
|
+
key: 'some/path/bim.jpg',
|
240
|
+
body: screenshot_file
|
241
|
+
)
|
242
|
+
|
243
|
+
s3_saver_with_key_prefix.save
|
244
|
+
end
|
245
|
+
|
246
|
+
context 'with object configuration' do
|
247
|
+
let(:s3_object_configuration) { { acl: 'public-read' } }
|
248
|
+
|
249
|
+
it 'uploads the html' do
|
250
|
+
html_path = '/foo/bar.html'
|
251
|
+
expect(saver).to receive(:html_path).and_return(html_path)
|
252
|
+
expect(saver).to receive(:html_saved?).and_return(true)
|
253
|
+
|
254
|
+
html_file = double('html_file')
|
255
|
+
|
256
|
+
expect(File).to receive(:open).with(html_path).and_yield(html_file)
|
257
|
+
|
258
|
+
expect(s3_client).to receive(:put_object).with(
|
259
|
+
bucket: bucket_name,
|
260
|
+
key: 'some/path/bar.html',
|
261
|
+
body: html_file,
|
262
|
+
acl: 'public-read'
|
263
|
+
)
|
264
|
+
|
265
|
+
s3_saver_with_key_prefix.save
|
266
|
+
end
|
267
|
+
|
268
|
+
it 'uploads the screenshot' do
|
269
|
+
screenshot_path = '/baz/bim.jpg'
|
270
|
+
expect(saver).to receive(:screenshot_path).and_return(screenshot_path)
|
271
|
+
expect(saver).to receive(:screenshot_saved?).and_return(true)
|
272
|
+
|
273
|
+
screenshot_file = double('screenshot_file')
|
274
|
+
|
275
|
+
expect(File).to receive(:open).with(screenshot_path).and_yield(screenshot_file)
|
276
|
+
|
277
|
+
expect(s3_client).to receive(:put_object).with(
|
278
|
+
bucket: bucket_name,
|
279
|
+
key: 'some/path/bim.jpg',
|
280
|
+
body: screenshot_file,
|
281
|
+
acl: 'public-read'
|
282
|
+
)
|
283
|
+
|
284
|
+
s3_saver_with_key_prefix.save
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
106
288
|
end
|
107
289
|
|
108
290
|
# Needed because we cannot depend on Verifying Doubles
|
@@ -129,4 +311,4 @@ describe Capybara::Screenshot::S3Saver do
|
|
129
311
|
expect(saver).to have_received(:foo_bar).with(*args)
|
130
312
|
end
|
131
313
|
end
|
132
|
-
end
|
314
|
+
end
|