0

My project uses Paperclip and Amazon S3, but I need a development/test environment that don't connect directly to S3. I've tried to use FakeS3, but with no luck, since I am using aws-sdk version 2 (and all other websites shows how to proceed using the v1).

There's a way to do that? How?

My Gemfile:

gem 'aws-sdk', '~> 2.5', '>= 2.5.3'
gem 'paperclip', '~> 5.1'

group :development, :test do
  gem 'fakes3', '~> 0.2.4'
end
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
  • I'd recommend using a dev bucket for your dev environment. Anything faking S3 would need to be constantly maintain to support the new features or changes in the S3 protocol. Not worth the efforts IMO. – roychri Dec 14 '16 at 18:49
  • Right... but what about unit tests? Do you keep running this tests using S3 itself? – Rodrigo de Avila Dec 15 '16 at 11:17

1 Answers1

0

The aws-ruby-sdk v2 offers something that allow you to test your code that uses AWS sdk.

stub_data and stub_responses

If offers many options and one of them is:

# stub data in the constructor
client = Aws::S3::Client.new(stub_responses: {
  list_buckets: { buckets: [{name: 'my-bucket' }] },
  get_object: { body: 'data' },
})

client.list_buckets.buckets.map(&:name) #=> ['my-bucket']
client.get_object(bucket:'name', key:'key').body.read #=> 'data'

This way you control what gets returned by the SDK without needing to use the real service.

http://docs.aws.amazon.com/sdkforruby/api/Aws/ClientStubs.html

roychri
  • 2,866
  • 1
  • 21
  • 29