title: Stubbing S3 presigned_url in AWS SDK v2
body: <p>I'm attempting to use the AWS Ruby SDK <a href="https://docs.aws.amazon.com/sdkforruby/api/Aws/ClientStubs.html#stub_responses-instance_method" rel="nofollow noreferrer">response stubs</a> to test some error handling in my interactions with S3.</p>
  
  <p>I've been able to stub a simplistic <code>put_object</code> case, but for some reason I cannot stub <a href="https://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Object.html#presigned_url-instance_method" rel="nofollow noreferrer"><code>presigned_url</code></a>. It's important to note that I am using an older version of the SDK.</p>
  
  <pre><code># Gemfile
  gem 'aws-sdk', '2.3.22'
  </code></pre>
  
          
  
  <pre><code>describe 'Stubbing AWS' do
    module S3Helper
      def self.presigned_url(object_key:, client:)
        resource = ::Aws::S3::Resource.new(:client =&gt; client)
        bucket = resource.bucket('my-great-bucket')
        bucket
          .object(object_key)
          .presigned_url(:get)
      end
    end
  
    it 'should allow me to stub signed_url' do
      test_client = Aws::S3::Client.new(
        :access_key_id =&gt; ENV['SECRET_ACCESS_KEY_ID'],
        :secret_access_key =&gt; ENV['SECRET_ACCESS_KEY'],
        :region =&gt; ENV['AWS_REGION']
      )
  
      test_client.stub_responses(:get_object 'NotFound')
  
      expect do
        S3Helper.presigned_url(
          object_key: 'my-key',
          client: client
        )
      end.to raise(/NotFound/)
    end
  end
  </code></pre>
  
  <p>The test fails because the response does not trigger the <code>NotFound</code> error, even though I can clearly see that a <code>get_object</code> request was made (and a fake response was returned) in the application logs. </p>
  
  <p>I'm currently solving around this by passing a mock client to my service, and stubbing out the <code>object</code> and <code>presigned_url</code> methods, but I'd prefer to have the SDK do the mocking for me. What am I missing?</p>