Ahmad Al-kheat Ahmad Al-kheat - 1 year ago 125
Ruby Question

How to test AWS S3 get object method ?

I am using aws sdk for ruby to retrieve an object from a bucket then read it. My code is something like:

def import_from_s3

#initiate the client
s3 = Aws::S3::Client.new({
region: region,
access_key_id: key_id,
secret_access_key: secret

#Get the object
resp = s3.get_object(bucket: bucket, key: key)

My question is how do I test this method without mocking it?

Answer Source

You don't need to (and you shouldn't even try) to test #get_object. That is not implemented by your code and you should assume it has been tested and it works. As for you method #import_from_s3, you have two options. You either don't test it since it is just a thin wrapper around #get_object; or you can make assertions/expectations on its return value.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download