amazon web services - Is it possible to stub a file upload using the Ruby AWS SDK? -
going off found in aws developers guide , looking @ api docs looks should able stub upload_file natively. following not work , upload_file returns true
client = aws::s3::client.new(stub_responses: true) client.stub_responses(:upload_file, false) resource = aws::s3::resource.new(client: client) obj = resource.bucket('foo').object('bar') obj.upload_file(tempfile.new('tmp')) #=> `true` when want `false` the api refers first argument of stub_responses operation_name. examples use operation named list_buckets , head_bucket cannot find list of operations acceptable. reading docs wrong or setting example wrong?
workaround
as work around i'm using rspec stub method. assuming same object in obj, above example needs following test pass
allow(obj).to receive(:upload_file).and_return(false)
after quick @ api docs pointed, best guess stub_response stubbing method calls go directly on client instance of aws::s3::client class.
however, upload_file on instance of aws::s3::object client.stub_reponses wouldn't stub method.
Comments
Post a Comment