Skip to content

Commit

Permalink
Change syntax in S3Saver
Browse files Browse the repository at this point in the history
  • Loading branch information
ericgriffis committed Apr 3, 2017
1 parent 1238d6e commit f83e27c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions lib/capybara-screenshot/s3_saver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ module Screenshot
class S3Saver
DEFAULT_REGION = 'us-east-1'

def initialize(saver, s3_client, bucket_name, key_prefix: nil)
def initialize(saver, s3_client, bucket_name, options={})
@saver = saver
@s3_client = s3_client
@bucket_name = bucket_name
@key_prefix = key_prefix
@key_prefix = options[:key_prefix]
end

def self.new_with_configuration(saver, configuration)
Expand All @@ -18,13 +18,13 @@ def self.new_with_configuration(saver, configuration)
}

s3_client_credentials = default_s3_client_credentials.merge(
configuration.delete(:s3_client_credentials)
configuration.fetch(:s3_client_credentials)
)

s3_client = Aws::S3::Client.new(s3_client_credentials)
bucket_name = configuration.delete(:bucket_name)
bucket_name = configuration.fetch(:bucket_name)

new(saver, s3_client, bucket_name, **configuration)
new(saver, s3_client, bucket_name, configuration)
rescue KeyError
raise "Invalid S3 Configuration #{configuration}. Please refer to the documentation for the necessary configurations."
end
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/s3_saver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
})

expect(Aws::S3::Client).to have_received(:new).with(s3_client_credentials)
expect(described_class).to have_received(:new).with(saver, s3_client, bucket_name, {})
expect(described_class).to have_received(:new).with(saver, s3_client, bucket_name, hash_including({}))
end

it 'passes key_prefix option if specified' do
Expand All @@ -49,7 +49,7 @@
})

expect(Aws::S3::Client).to have_received(:new).with(s3_client_credentials)
expect(described_class).to have_received(:new).with(saver, s3_client, bucket_name, key_prefix: key_prefix)
expect(described_class).to have_received(:new).with(saver, s3_client, bucket_name, hash_including(key_prefix: key_prefix))
end

it 'defaults the region to us-east-1' do
Expand All @@ -64,7 +64,7 @@
s3_client_credentials.merge(region: default_region)
)

expect(described_class).to have_received(:new).with(saver, s3_client, bucket_name, {})
expect(described_class).to have_received(:new).with(saver, s3_client, bucket_name, hash_including({}))
end
end

Expand Down

0 comments on commit f83e27c

Please sign in to comment.