capybara-screenshot 1.0.15 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17a6c4cc3fd164bb2b6f74448ef7b9ddf83b771c
4
- data.tar.gz: fc743fe14f52cb0481a3aa545e9b5290420a4cd1
3
+ metadata.gz: 9afdd9d33462cf19d2cd005844e6790171b23073
4
+ data.tar.gz: ac0e7b147e924204f72657cbdfd92b96e2b912cf
5
5
  SHA512:
6
- metadata.gz: 366222eb34fb0bdfa5bf53c5b27a7e00902c1e8300b6767a377ff6fa207eb1a5104d6cc868d7f69c1829f370ff90ebbde1940e8529b8ab694fb544b9ab5fc38d
7
- data.tar.gz: 0c04abede37b6e6fc39a1f1d22a2d7429eada67a0d46bbb8ef59bf1ba53d35763d1d4b4c7361d8c21ffa52dc90e58e7de9421a2864effa8e71dae5c939e9b944
6
+ metadata.gz: 8966719fe9c36701a98e20c72f92d00be96df39374e871ceb18de0aaf91284c40a9c1bedf714186e0c6967da75df8e477f247bfd0201229c1fd32ce4f57489c4
7
+ data.tar.gz: 936a36d7efd3fb8e50a203e3130e0575eb0ce5b99c24ae85e56eede5f19faf5b32cb01a42aa997151ebf00971fe85bed1b78734fed5d27116748e1ca9ab7dc10
@@ -1,10 +1,11 @@
1
1
  language: ruby
2
- script: "rake travis:ci"
2
+ script: "bundle exec rake travis:ci"
3
3
  rvm:
4
4
  - 2.0.0
5
5
  - 2.1.10
6
- - 2.2.1
7
- - 2.3.1
6
+ - 2.2.6
7
+ - 2.3.3
8
+ - 2.4.0
8
9
  gemfile:
9
10
  - gemfiles/cucumber.1.3.gemfile
10
11
  - gemfiles/cucumber.2.4.gemfile
@@ -1,3 +1,7 @@
1
+ 12 July 2017 - 1.0.15 -> 1.0.16
2
+
3
+ * [Support s3 key name prefixes](https://github.com/mattheworiordan/capybara-screenshot/pull/202)
4
+
1
5
  12 July 2017 - 1.0.14 -> 1.0.15
2
6
 
3
7
  * [SVG badges added](https://github.com/mattheworiordan/capybara-screenshot/pull/207)
data/README.md CHANGED
@@ -223,6 +223,14 @@ Capybara::Screenshot.s3_object_configuration = {
223
223
  }
224
224
  ```
225
225
 
226
+ 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.:
227
+
228
+ ```ruby
229
+ Capybara::Screenshot.s3_configuration = {
230
+ ... # other config here
231
+ key_prefix: "some/folder/"
232
+ }
233
+ ```
226
234
 
227
235
  Pruning old screenshots automatically
228
236
  --------------------------
@@ -5,10 +5,11 @@ module Capybara
5
5
  class S3Saver
6
6
  DEFAULT_REGION = 'us-east-1'
7
7
 
8
- def initialize(saver, s3_client, bucket_name, object_configuration)
8
+ def initialize(saver, s3_client, bucket_name, object_configuration, options={})
9
9
  @saver = saver
10
10
  @s3_client = s3_client
11
11
  @bucket_name = bucket_name
12
+ @key_prefix = options[:key_prefix]
12
13
  @object_configuration = object_configuration
13
14
  end
14
15
 
@@ -24,7 +25,7 @@ module Capybara
24
25
  s3_client = Aws::S3::Client.new(s3_client_credentials)
25
26
  bucket_name = configuration.fetch(:bucket_name)
26
27
 
27
- new(saver, s3_client, bucket_name, object_configuration)
28
+ new(saver, s3_client, bucket_name, object_configuration, configuration)
28
29
  rescue KeyError
29
30
  raise "Invalid S3 Configuration #{configuration}. Please refer to the documentation for the necessary configurations."
30
31
  end
@@ -34,7 +35,7 @@ module Capybara
34
35
  File.open(local_file_path) do |file|
35
36
  object_payload = {
36
37
  bucket: bucket_name,
37
- key: File.basename(local_file_path),
38
+ key: "#{@key_prefix}#{File.basename(local_file_path)}",
38
39
  body: file
39
40
  }
40
41
 
@@ -60,6 +61,7 @@ module Capybara
60
61
  :s3_client,
61
62
  :bucket_name,
62
63
  :object_configuration
64
+ :key_prefix
63
65
 
64
66
  def save_and
65
67
  saver.save
@@ -1,5 +1,5 @@
1
1
  module Capybara
2
2
  module Screenshot
3
- VERSION = '1.0.15'
3
+ VERSION = '1.0.16'
4
4
  end
5
5
  end
@@ -6,8 +6,10 @@ describe Capybara::Screenshot::S3Saver do
6
6
  let(:bucket_name) { double('bucket_name') }
7
7
  let(:s3_object_configuration) { {} }
8
8
  let(:s3_client) { double('s3_client') }
9
+ let(:key_prefix){ "some/path/" }
9
10
 
10
- let(:s3_saver) { Capybara::Screenshot::S3Saver.new(saver, s3_client, bucket_name, s3_object_configuration) }
11
+ let(:s3_saver) { described_class.new(saver, s3_client, bucket_name, s3_object_configuration) }
12
+ let(:s3_saver_with_key_prefix) { described_class.new(saver, s3_client, bucket_name, s3_object_configuration, key_prefix: key_prefix) }
11
13
 
12
14
  describe '.new_with_configuration' do
13
15
  let(:access_key_id) { double('access_key_id') }
@@ -24,26 +26,36 @@ describe Capybara::Screenshot::S3Saver do
24
26
  s3_client_credentials_using_defaults.merge(region: region)
25
27
  }
26
28
 
27
- it 'destructures the configuration into its components' do
29
+ before do
28
30
  allow(Aws::S3::Client).to receive(:new).and_return(s3_client)
29
- allow(Capybara::Screenshot::S3Saver).to receive(:new)
31
+ allow(described_class).to receive(:new)
32
+ end
30
33
 
31
- Capybara::Screenshot::S3Saver.new_with_configuration(saver, {
34
+ it 'destructures the configuration into its components' do
35
+ described_class.new_with_configuration(saver, {
32
36
  s3_client_credentials: s3_client_credentials,
33
37
  bucket_name: bucket_name
34
38
  }, s3_object_configuration)
35
39
 
36
40
  expect(Aws::S3::Client).to have_received(:new).with(s3_client_credentials)
37
- expect(Capybara::Screenshot::S3Saver).to have_received(:new).with(saver, s3_client, bucket_name, s3_object_configuration)
41
+ expect(described_class).to have_received(:new).with(saver, s3_client, bucket_name, s3_object_configuration, hash_including({}))
42
+ end
43
+
44
+ it 'passes key_prefix option if specified' do
45
+ described_class.new_with_configuration(saver, {
46
+ s3_client_credentials: s3_client_credentials,
47
+ bucket_name: bucket_name,
48
+ key_prefix: key_prefix,
49
+ }, s3_object_configuration)
50
+
51
+ expect(Aws::S3::Client).to have_received(:new).with(s3_client_credentials)
52
+ expect(described_class).to have_received(:new).with(saver, s3_client, bucket_name, s3_object_configuration, hash_including(key_prefix: key_prefix))
38
53
  end
39
54
 
40
55
  it 'defaults the region to us-east-1' do
41
56
  default_region = 'us-east-1'
42
57
 
43
- allow(Aws::S3::Client).to receive(:new).and_return(s3_client)
44
- allow(Capybara::Screenshot::S3Saver).to receive(:new)
45
-
46
- Capybara::Screenshot::S3Saver.new_with_configuration(saver, {
58
+ described_class.new_with_configuration(saver, {
47
59
  s3_client_credentials: s3_client_credentials_using_defaults,
48
60
  bucket_name: bucket_name
49
61
  }, s3_object_configuration)
@@ -52,23 +64,31 @@ describe Capybara::Screenshot::S3Saver do
52
64
  s3_client_credentials.merge(region: default_region)
53
65
  )
54
66
 
55
- expect(Capybara::Screenshot::S3Saver).to have_received(:new).with(saver, s3_client, bucket_name, s3_object_configuration)
67
+ expect(described_class).to have_received(:new).with(saver, s3_client, bucket_name, s3_object_configuration, hash_including({}))
56
68
  end
57
69
 
58
70
  it 'stores the object configuration when passed' do
59
71
  s3_object_configuration = { acl: 'public-read' }
60
72
  Capybara::Screenshot.s3_object_configuration = { acl: 'public-read' }
61
73
 
62
- allow(Aws::S3::Client).to receive(:new).and_return(s3_client)
63
- allow(Capybara::Screenshot::S3Saver).to receive(:new)
64
-
65
- Capybara::Screenshot::S3Saver.new_with_configuration(saver, {
74
+ described_class.new_with_configuration(saver, {
66
75
  s3_client_credentials: s3_client_credentials,
67
76
  bucket_name: bucket_name
68
77
  }, s3_object_configuration)
69
78
 
70
79
  expect(Aws::S3::Client).to have_received(:new).with(s3_client_credentials)
71
- expect(Capybara::Screenshot::S3Saver).to have_received(:new).with(saver, s3_client, bucket_name, s3_object_configuration)
80
+ expect(described_class).to have_received(:new).with(saver, s3_client, bucket_name, s3_object_configuration, hash_including({}))
81
+ end
82
+
83
+ it 'passes key_prefix option if specified' do
84
+ described_class.new_with_configuration(saver, {
85
+ s3_client_credentials: s3_client_credentials,
86
+ bucket_name: bucket_name,
87
+ key_prefix: key_prefix,
88
+ }, s3_object_configuration)
89
+
90
+ expect(Aws::S3::Client).to have_received(:new).with(s3_client_credentials)
91
+ expect(described_class).to have_received(:new).with(saver, s3_client, bucket_name, s3_object_configuration, hash_including(key_prefix: key_prefix))
72
92
  end
73
93
  end
74
94
 
@@ -121,9 +141,9 @@ describe Capybara::Screenshot::S3Saver do
121
141
  s3_saver.save
122
142
  end
123
143
 
124
- describe 'save to s3 with object configuration' do
144
+ context 'with object configuration' do
125
145
  let(:s3_object_configuration) { { acl: 'public-read' } }
126
- let(:s3_saver) { Capybara::Screenshot::S3Saver.new(saver, s3_client, bucket_name, s3_object_configuration) }
146
+ let(:s3_saver) { described_class.new(saver, s3_client, bucket_name, s3_object_configuration) }
127
147
 
128
148
  it 'uploads the html' do
129
149
  html_path = '/foo/bar.html'
@@ -163,6 +183,86 @@ describe Capybara::Screenshot::S3Saver do
163
183
  s3_saver.save
164
184
  end
165
185
  end
186
+
187
+ context 'with key_prefix specified' do
188
+ it 'uploads the html with key prefix' do
189
+ html_path = '/foo/bar.html'
190
+ expect(saver).to receive(:html_path).and_return(html_path)
191
+ expect(saver).to receive(:html_saved?).and_return(true)
192
+
193
+ html_file = double('html_file')
194
+
195
+ expect(File).to receive(:open).with(html_path).and_yield(html_file)
196
+
197
+ expect(s3_client).to receive(:put_object).with(
198
+ bucket: bucket_name,
199
+ key: 'some/path/bar.html',
200
+ body: html_file
201
+ )
202
+
203
+ s3_saver_with_key_prefix.save
204
+ end
205
+
206
+ it 'uploads the screenshot with key prefix' do
207
+ screenshot_path = '/baz/bim.jpg'
208
+ expect(saver).to receive(:screenshot_path).and_return(screenshot_path)
209
+ expect(saver).to receive(:screenshot_saved?).and_return(true)
210
+
211
+ screenshot_file = double('screenshot_file')
212
+
213
+ expect(File).to receive(:open).with(screenshot_path).and_yield(screenshot_file)
214
+
215
+ expect(s3_client).to receive(:put_object).with(
216
+ bucket: bucket_name,
217
+ key: 'some/path/bim.jpg',
218
+ body: screenshot_file
219
+ )
220
+
221
+ s3_saver_with_key_prefix.save
222
+ end
223
+
224
+ context 'with object configuration' do
225
+ let(:s3_object_configuration) { { acl: 'public-read' } }
226
+
227
+ it 'uploads the html' do
228
+ html_path = '/foo/bar.html'
229
+ expect(saver).to receive(:html_path).and_return(html_path)
230
+ expect(saver).to receive(:html_saved?).and_return(true)
231
+
232
+ html_file = double('html_file')
233
+
234
+ expect(File).to receive(:open).with(html_path).and_yield(html_file)
235
+
236
+ expect(s3_client).to receive(:put_object).with(
237
+ bucket: bucket_name,
238
+ key: 'some/path/bar.html',
239
+ body: html_file,
240
+ acl: 'public-read'
241
+ )
242
+
243
+ s3_saver_with_key_prefix.save
244
+ end
245
+
246
+ it 'uploads the screenshot' do
247
+ screenshot_path = '/baz/bim.jpg'
248
+ expect(saver).to receive(:screenshot_path).and_return(screenshot_path)
249
+ expect(saver).to receive(:screenshot_saved?).and_return(true)
250
+
251
+ screenshot_file = double('screenshot_file')
252
+
253
+ expect(File).to receive(:open).with(screenshot_path).and_yield(screenshot_file)
254
+
255
+ expect(s3_client).to receive(:put_object).with(
256
+ bucket: bucket_name,
257
+ key: 'some/path/bim.jpg',
258
+ body: screenshot_file,
259
+ acl: 'public-read'
260
+ )
261
+
262
+ s3_saver_with_key_prefix.save
263
+ end
264
+ end
265
+ end
166
266
  end
167
267
 
168
268
  # Needed because we cannot depend on Verifying Doubles
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-screenshot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.15
4
+ version: 1.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew O'Riordan